New menu UI. Props filosofo. see #12713

git-svn-id: http://svn.automattic.com/wordpress/trunk@14248 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2010-04-27 01:05:58 +00:00
parent 418b0b7e69
commit e879a9ab0e
20 changed files with 2279 additions and 1204 deletions

View File

@ -126,11 +126,21 @@ case 'imgedit-preview' :
check_ajax_referer( "image_editor-$post_id" ); check_ajax_referer( "image_editor-$post_id" );
include_once( ABSPATH . 'wp-admin/includes/image-edit.php' ); include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
if ( !stream_preview_image($post_id) ) if ( ! stream_preview_image($post_id) )
die('-1'); die('-1');
die(); die();
break; break;
case 'menu-quick-search':
if ( ! current_user_can( 'switch_themes' ) )
die('-1');
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
_wp_ajax_menu_quick_search( $_REQUEST );
exit;
break;
case 'oembed-cache' : case 'oembed-cache' :
$return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0'; $return = ( $wp_embed->cache_oembed( $_GET['post'] ) ) ? '1' : '0';
die( $return ); die( $return );
@ -386,6 +396,17 @@ case 'delete-link' :
else else
die('0'); die('0');
break; break;
case 'delete-menu-item' :
$menu_item_id = (int) $_POST['menu-item'];
check_admin_referer( 'delete-menu_item_' . $menu_item_id );
if ( ! current_user_can( 'switch_themes' ) )
die('-1');
if ( 'nav_menu_item' == get_post_type( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )
die('1');
else
die('0');
break;
case 'delete-meta' : case 'delete-meta' :
check_ajax_referer( "delete-meta_$id" ); check_ajax_referer( "delete-meta_$id" );
if ( !$meta = get_post_meta_by_id( $id ) ) if ( !$meta = get_post_meta_by_id( $id ) )
@ -795,6 +816,40 @@ case 'edit-comment' :
$x->send(); $x->send();
break; break;
case 'add-menu-item' :
if ( ! current_user_can( 'switch_themes' ) )
die('-1');
check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
$menu_id = (int) $_POST['menu'];
if ( isset( $_POST['menu-item'] ) ) {
$item_ids = wp_save_nav_menu_item( $menu_id, $_POST['menu-item'] );
} else {
$item_ids = array();
}
foreach ( (array) $item_ids as $menu_item_id ) {
$menu_obj = get_post( $menu_item_id );
if ( ! empty( $menu_obj->ID ) ) {
$menu_items[] = wp_setup_nav_menu_item( $menu_obj );
}
}
if ( ! empty( $menu_items ) ) {
$args = array(
'after' => '',
'before' => '',
'context' => 'backend',
'link_after' => '',
'link_before' => '',
'walker' => new Walker_Nav_Menu_Edit,
);
echo walk_nav_menu_tree( $menu_items, 0, (object) $args );
}
break;
case 'add-meta' : case 'add-meta' :
check_ajax_referer( 'add-meta' ); check_ajax_referer( 'add-meta' );
$c = 0; $c = 0;
@ -1033,6 +1088,16 @@ case 'hidden-columns' :
die('1'); die('1');
break; break;
case 'menu-quick-search':
if ( ! current_user_can( 'switch_themes' ) )
die('-1');
require_once ABSPATH . 'wp-admin/includes/nav-menu.php';
_wp_ajax_menu_quick_search( $_REQUEST );
exit;
break;
case 'meta-box-order': case 'meta-box-order':
check_ajax_referer( 'meta-box-order' ); check_ajax_referer( 'meta-box-order' );
$order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false; $order = isset( $_POST['order'] ) ? (array) $_POST['order'] : false;

File diff suppressed because one or more lines are too long

View File

@ -110,11 +110,13 @@ div.dashboard-widget-submit {
} }
div.tabs-panel, div.tabs-panel,
ul.category-tabs li.tabs { ul.category-tabs li.tabs,
ul.add-menu-item-tabs li.tabs {
border-color: #dfdfdf; border-color: #dfdfdf;
} }
ul.category-tabs li.tabs { ul.category-tabs li.tabs,
ul.add-menu-item-tabs li.tabs {
background-color: #f1f1f1; background-color: #f1f1f1;
} }
@ -380,7 +382,8 @@ div.dashboard-widget-submit input:hover,
border-color: #dfdfdf; border-color: #dfdfdf;
} }
#side-sortables .category-tabs .tabs a { #side-sortables .category-tabs .tabs a,
#side-sortables .add-menu-item-tabs .tabs a {
color: #333; color: #333;
} }
@ -1467,7 +1470,8 @@ fieldset.inline-edit-col-right .inline-edit-col {
background-color: #f5f5f5; background-color: #f5f5f5;
} }
#post-body ul.category-tabs li.tabs a { #post-body ul.category-tabs li.tabs a,
#post-body ul.add-menu-item-tabs li.tabs a {
color: #333; color: #333;
} }

File diff suppressed because one or more lines are too long

View File

@ -110,11 +110,13 @@ div.dashboard-widget-submit {
} }
div.tabs-panel, div.tabs-panel,
ul.category-tabs li.tabs { ul.category-tabs li.tabs,
ul.add-menu-item-tabs li.tabs {
border-color: #dfdfdf; border-color: #dfdfdf;
} }
ul.category-tabs li.tabs { ul.category-tabs li.tabs,
ul.add-menu-item-tabs li.tabs {
background-color: #f1f1f1; background-color: #f1f1f1;
} }
@ -379,7 +381,8 @@ div.dashboard-widget-submit input:hover,
border-color: #dfdfdf; border-color: #dfdfdf;
} }
#side-sortables .category-tabs .tabs a { #side-sortables .category-tabs .tabs a,
#side-sortables .add-menu-item-tabs .tabs a {
color: #333; color: #333;
} }
@ -490,7 +493,9 @@ a,
} }
/* Because we don't want visited on these links */ /* Because we don't want visited on these links */
body.press-this .tabs a,
body.press-this .tabs a:hover { body.press-this .tabs a:hover {
background-color: #fff;
border-color: #c6d9e9; border-color: #c6d9e9;
border-bottom-color: #fff; border-bottom-color: #fff;
color: #d54e21; color: #d54e21;
@ -1460,7 +1465,8 @@ fieldset.inline-edit-col-right .inline-edit-col {
background-color: #f5f5f5; background-color: #f5f5f5;
} }
#post-body ul.category-tabs li.tabs a { #post-body ul.category-tabs li.tabs a,
#post-body ul.add-menu-item-tabs li.tabs a {
color: #333; color: #333;
} }

View File

@ -1 +1 @@
#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.list-controls{float:left;}.add-to-menu{float:right;}.button-controls{margin:10px 0;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}#create-menu-name{width:159px;}#manage-menu .inside{padding:0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}.menu-item-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;margin-bottom:10px;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl dt{-webkit-border-radius:6px;border-radius:6px;-moz-border-radius:6px;border:1px solid #E6E6E6;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li dl dt:hover{cursor:move;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .menu-item-delete:hover{color:#f00;}#menu-item-settings{display:none;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.button-controls:after,#menu-item-url-wrap:after,#menu-item-name-wrap:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block;} .nav-edit-wrap{clear:both;}#menu-settings-column{display:block;float:left;width:281px;}#menu-settings-column .inside{padding:0 10px;}#menu-management{float:left;margin-left:15px;}#menu-management .menu-edit{background-color:#fff;border-color:#dfdfdf;border-width:1px;border-style:solid;margin-bottom:20px;padding:0 10px 10px;-moz-border-radius-bottomleft:6px;-webkit-border-bottom-left-radius:6px;-khtml-border-bottom-left-radius:6px;border-bottom-left-radius:6px;-moz-border-radius-bottomright:6px;-webkit-border-bottom-right-radius:6px;-khtml-border-bottom-right-radius:6px;border-bottom-right-radius:6px;-moz-border-radius-topright:6px;-webkit-border-top-right-radius:6px;-khtml-border-top-right-radius:6px;border-top-right-radius:6px;}#menu-management .menu-add-new abbr{font-weight:bold;}#menu-management .menu-tabs{background-color:#fff;border-color:#dfdfdf;border-bottom-color:#fff;}#menu-management .menu-tab-inactive{background-color:#fafafa;border-bottom-color:#fafafa;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{font-size:11px;}#cancel-save{color:#f00;text-decoration:underline;font-size:11px;margin-left:20px;margin-top:5px;}#cancel-save:hover{background-color:#F00;color:#fff;}.list-controls{float:left;}.add-to-menu{float:right;}form.processing .add-to-menu{background:url("../images/wpspin_light.gif") no-repeat top center;display:block;height:20px;overflow:hidden;text-align:left;text-indent:-999em;width:20px;}.button-controls{margin:10px 0;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}#create-menu-name{width:159px;}#manage-menu .inside{padding:0;}#available-links dt{display:block;}#add-custom-link .howto{font-size:11px;}#add-custom-link label span{display:block;float:left;margin-top:5px;padding-right:5px;}.menu-item-textbox{float:right;width:220px;}.howto span{margin-top:4px;display:block;float:left;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;margin-bottom:10px;}.list-container{max-height:200px;overflow-y:auto;padding:10px 10px 5px;border:1px solid #DFDFDF;-moz-border-radius:4px;}.postbox p.submit{margin-bottom:0;}.list li{display:none;margin:0;margin-bottom:5px;}.list li .menu-item-title{cursor:pointer;display:block;}.list li .menu-item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .menu-item-title{margin-left:14px;}.list li ul li ul li .menu-item-title{margin-left:28px;}.list li ul li ul li ul li .menu-item-title{margin-left:42px;}.list li ul li ul li ul li ul li .menu-item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .menu-item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .menu-item-title{margin-left:112px;}#menu-container .inside{padding-bottom:10px;}.menu{padding-top:1em;}.menu ul{width:100%;}.menu li{margin:0;}.menu li dl{clear:both;line-height:1.5em;position:relative;}.menu li dl dt{-webkit-border-radius:6px;border-radius:6px;-moz-border-radius:6px;border:1px solid #E6E6E6;clear:both;cursor:move;position:relative;padding-left:10px;background-color:#f1f1f1;height:35px;line-height:35px;}.menu li.deleting dl dt{background-color:#faa;}.menu li .item-title{display:block;height:1em;margin-right:18em;}.menu li div.sortable-placeholder{background:#f5f5f5;border:1px dashed #bbb;margin:10px 0;padding-top:40px;}.menu li dl.sortable-placeholder{background:#f5f5f5;padding-bottom:40px;}.menu li ul li{margin-left:20px;opacity:.7;}.menu li ul li ul li{opacity:.9;}.menu li ul li ul li ul li{opacity:.9;}.menu li ul li ul li ul li ul li{opacity:.95;}.dropzone{height:7px;margin:3px 0 3px 0;}.ui-draggable-dragging{width:600px;}.item-type{text-transform:uppercase;font-size:11px;color:#999;padding-right:10px;}.item-controls{font-size:11px;position:absolute;right:15px;top:-1px;}.item-controls a{text-decoration:none;}.item-controls a:hover{cursor:pointer;}.item-controls .item-order a{font-weight:bold;}body.js .item-order{display:none;}.item-controls .menu-item-delete:hover{color:#f00;}.menu-item-edit-active{display:block;}.menu-item-edit-inactive{display:none;}.add-menu-item-pagelinks{margin:.5em auto;text-align:center;}#cancel-save{cursor:pointer;}#cancel-save:hover{color:#fff!important;}#update-menu-item{color:#fff!important;}#update-menu-item:hover,#update-menu-item:active,#update-menu-item:focus{color:#eaf2fa!important;border-color:#13455b!important;}.button-controls:after,#menu-item-url-wrap:after,#menu-item-name-wrap:after{content:".";display:block;height:0;clear:both;visibility:hidden;}.button-controls,#menu-item-url-wrap,#menu-item-name-wrap{display:block;}

View File

@ -8,8 +8,61 @@
* @subpackage Administration * @subpackage Administration
*/ */
.nav-edit-wrap {
clear:both;
}
#menu-settings-column {
display:block;
float:left;
width:281px;
}
#menu-settings-column .inside {
padding:0 10px;
}
/* Menu Container */ /* Menu Container */
#menu-management { clear: both; } #menu-management {
float:left;
margin-left:15px;
}
#menu-management .menu-edit {
background-color:#fff;
border-color: #dfdfdf;
border-width: 1px;
border-style: solid;
margin-bottom: 20px;
padding:0 10px 10px;
-moz-border-radius-bottomleft: 6px;
-webkit-border-bottom-left-radius: 6px;
-khtml-border-bottom-left-radius: 6px;
border-bottom-left-radius: 6px;
-moz-border-radius-bottomright: 6px;
-webkit-border-bottom-right-radius: 6px;
-khtml-border-bottom-right-radius: 6px;
border-bottom-right-radius: 6px;
-moz-border-radius-topright: 6px;
-webkit-border-top-right-radius: 6px;
-khtml-border-top-right-radius: 6px;
border-top-right-radius: 6px;
}
#menu-management .menu-add-new abbr {
font-weight:bold;
}
#menu-management .menu-tabs {
background-color:#fff;
border-color:#dfdfdf;
border-bottom-color:#fff;
}
#menu-management .menu-tab-inactive {
background-color:#fafafa;
border-bottom-color:#fafafa;
}
#menu-management .inside { padding: 0 10px; } #menu-management .inside { padding: 0 10px; }
/* Button Primary Actions */ /* Button Primary Actions */
@ -21,7 +74,20 @@
/* Button Secondary Actions */ /* Button Secondary Actions */
.list-controls { float: left; } .list-controls { float: left; }
.add-to-menu { float: right; } .add-to-menu {
float: right;
}
form.processing .add-to-menu {
background: url("../images/wpspin_light.gif") no-repeat top center;
display:block;
height:20px;
overflow:hidden;
text-align:left;
text-indent:-999em;
width:20px;
}
.button-controls { margin: 10px 0; } .button-controls { margin: 10px 0; }
.show-all, .hide-all { cursor: pointer; } .show-all, .hide-all { cursor: pointer; }
.hide-all { display: none; } .hide-all { display: none; }
@ -61,12 +127,58 @@
/* Nav Menu */ /* Nav Menu */
#menu-container .inside { padding-bottom: 10px; } #menu-container .inside { padding-bottom: 10px; }
.menu ul { width: 100%; } .menu {
.menu li { margin: 0; } padding-top:1em;
.menu li dl dt { -webkit-border-radius: 6px; border-radius: 6px; -moz-border-radius: 6px; border: 1px solid #E6E6E6; position: relative; padding-left: 10px; background-color: #f1f1f1; height: 35px; line-height: 35px; } }
.menu li dl dt:hover { cursor: move; }
.menu ul { width: 100%; }
.menu ul.sub-menu {
}
.menu li {
margin: 0;
}
.menu li dl {
clear:both;
line-height:1.5em;
position:relative;
}
.menu li dl dt {
-webkit-border-radius: 6px;
border-radius: 6px;
-moz-border-radius: 6px;
border: 1px solid #E6E6E6;
clear:both;
cursor: move;
position: relative;
padding-left: 10px;
background-color: #f1f1f1;
height: 35px;
line-height: 35px;
}
.menu li dl dt:hover {
}
.menu li.deleting dl dt {
background-color:#faa;
}
.menu li .item-title {
display:block;
height:1em;
margin-right:18em;
}
.menu li div.sortable-placeholder {
background: #f5f5f5;
border: 1px dashed #bbb;
margin: 10px 0px;
padding-top:40px;
}
.menu li dl.sortable-placeholder {
background: #f5f5f5;
padding-bottom:40px;
}
.menu li .item-title { }
.menu li ul li { margin-left: 20px; opacity: .7; } .menu li ul li { margin-left: 20px; opacity: .7; }
.menu li ul li ul li { opacity: .9; } .menu li ul li ul li { opacity: .9; }
.menu li ul li ul li ul li { opacity: .9; } .menu li ul li ul li ul li { opacity: .9; }
@ -81,10 +193,30 @@
.item-controls { font-size: 11px; position: absolute; right: 15px; top: -1px; } .item-controls { font-size: 11px; position: absolute; right: 15px; top: -1px; }
.item-controls a { text-decoration: none; } .item-controls a { text-decoration: none; }
.item-controls a:hover { cursor: pointer; } .item-controls a:hover { cursor: pointer; }
.item-controls .item-order a {
font-weight:bold;
}
body.js .item-order {
display:none;
}
.item-controls .menu-item-delete:hover { color: #ff0000; } .item-controls .menu-item-delete:hover { color: #ff0000; }
/* Thickbox */ /* Menu editing */
#menu-item-settings { display: none; } .menu-item-edit-active {
display:block;
}
.menu-item-edit-inactive {
display:none;
}
.add-menu-item-pagelinks {
margin:.5em auto;
text-align:center;
}
#cancel-save { cursor: pointer; } #cancel-save { cursor: pointer; }
#cancel-save:hover { color: #fff !important; } #cancel-save:hover { color: #fff !important; }
#update-menu-item { color: #fff !important; } #update-menu-item { color: #fff !important; }
@ -94,4 +226,4 @@
/* Clearfix */ /* Clearfix */
.button-controls:after, #menu-item-url-wrap:after, #menu-item-name-wrap:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; } .button-controls:after, #menu-item-url-wrap:after, #menu-item-name-wrap:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
.button-controls, #menu-item-url-wrap, #menu-item-name-wrap { display: block; } .button-controls, #menu-item-url-wrap, #menu-item-name-wrap { display: block; }

File diff suppressed because one or more lines are too long

View File

@ -298,7 +298,8 @@ td.available-theme {
margin-left: 0; margin-left: 0;
margin-right: 120px; margin-right: 120px;
} }
#post-body ul.category-tabs li.tabs { #post-body ul.category-tabs li.tabs,
#post-body ul.add-menu-item-tabs li.tabs {
-moz-border-radius: 0 3px 3px 0; -moz-border-radius: 0 3px 3px 0;
-webkit-border-top-left-radius: 0; -webkit-border-top-left-radius: 0;
-webkit-border-top-right-radius: 3px; -webkit-border-top-right-radius: 3px;
@ -309,21 +310,25 @@ td.available-theme {
border-bottom-left-radius: 0; border-bottom-left-radius: 0;
border-bottom-right-radius: 3px; border-bottom-right-radius: 3px;
} }
#post-body ul.category-tabs { #post-body ul.category-tabs,
#post-body ul.add-menu-item-tabs {
float: right; float: right;
text-align: left; text-align: left;
margin: 0 0 0 -120px; margin: 0 0 0 -120px;
} }
#post-body .categorydiv div.tabs-panel, #post-body .categorydiv div.tabs-panel,
#post-body .taxonomy div.tabs-panel,
#post-body #linkcategorydiv div.tabs-panel { #post-body #linkcategorydiv div.tabs-panel {
margin: 0 120px 0 5px; margin: 0 120px 0 5px;
} }
/* 1800 - 2000 /* 1800 - 2000
=================================== */ =================================== */
#side-sortables .category-tabs li { #side-sortables .category-tabs li,
#side-sortables .add-menu-item-tabs li {
padding-left: 8px; padding-left: 8px;
} }
.categorydiv ul.categorychecklist ul, .categorydiv ul.categorychecklist ul,
.taxonomydiv ul.categorychecklist ul,
#linkcategorydiv ul.categorychecklist ul { #linkcategorydiv ul.categorychecklist ul {
margin-left: 0; margin-left: 0;
margin-right: 18px; margin-right: 18px;

File diff suppressed because one or more lines are too long

View File

@ -1959,7 +1959,8 @@ input#link_url {
width: auto; width: auto;
} }
#post-body ul.category-tabs { #post-body ul.category-tabs,
#post-body ul.add-menu-item-tabs {
float: left; float: left;
width: 120px; width: 120px;
text-align: right; text-align: right;
@ -1968,11 +1969,13 @@ input#link_url {
padding: 0; padding: 0;
} }
#post-body ul.category-tabs li { #post-body ul.category-tabs li,
#post-body ul.add-menu-item-tabs li {
padding: 8px; padding: 8px;
} }
#post-body ul.category-tabs li.tabs { #post-body ul.category-tabs li.tabs,
#post-body ul.add-menu-item-tabs li.tabs {
-moz-border-radius: 3px 0 0 3px; -moz-border-radius: 3px 0 0 3px;
-webkit-border-top-left-radius: 3px; -webkit-border-top-left-radius: 3px;
-webkit-border-bottom-left-radius: 3px; -webkit-border-bottom-left-radius: 3px;
@ -1982,12 +1985,16 @@ input#link_url {
border-bottom-left-radius: 3px; border-bottom-left-radius: 3px;
} }
#post-body ul.category-tabs li.tabs a { #post-body ul.category-tabs li.tabs a,
#post-body ul.add-menu-item-tabs li.tabs a {
font-weight: bold; font-weight: bold;
text-decoration: none; text-decoration: none;
} }
.categorydiv div.tabs-panel, .categorydiv div.tabs-panel,
.customlinkdiv div.tabs-panel,
.posttypediv div.tabs-panel,
.taxonomydiv div.tabs-panel,
#linkcategorydiv div.tabs-panel { #linkcategorydiv div.tabs-panel {
height: 200px; height: 200px;
overflow: auto; overflow: auto;
@ -1996,25 +2003,40 @@ input#link_url {
border-width: 1px; border-width: 1px;
} }
div.tabs-panel-active {
display:block;
}
div.tabs-panel-inactive {
display:none;
}
#post-body .categorydiv div.tabs-panel, #post-body .categorydiv div.tabs-panel,
.taxonomy div.tabs-panel,
#post-body #linkcategorydiv div.tabs-panel { #post-body #linkcategorydiv div.tabs-panel {
margin: 0 5px 0 125px; margin: 0 5px 0 125px;
} }
#side-sortables .category-tabs li { #side-sortables .category-tabs li,
#side-sortables .add-menu-item-tabs li {
display: inline; display: inline;
padding-right: 8px; padding-right: 8px;
} }
#side-sortables .category-tabs a { #side-sortables .category-tabs a,
#side-sortables .add-menu-item-tabs a {
text-decoration: none; text-decoration: none;
} }
#side-sortables .category-tabs { #side-sortables .category-tabs,
#side-sortables .add-menu-item-tabs {
margin-bottom: 3px; margin-bottom: 3px;
} }
.categorydiv ul, .categorydiv ul,
.customlinkdiv ul,
.posttypediv ul,
.taxonomydiv ul,
#linkcategorydiv ul { #linkcategorydiv ul {
list-style: none; list-style: none;
padding: 0; padding: 0;
@ -2025,6 +2047,9 @@ input#link_url {
#front-static-pages ul, #front-static-pages ul,
.inline-editor ul.cat-checklist ul, .inline-editor ul.cat-checklist ul,
.categorydiv ul.categorychecklist ul, .categorydiv ul.categorychecklist ul,
.customlinkdiv ul.categorychecklist ul,
.posttypediv ul.categorychecklist ul,
.taxonomydiv ul.categorychecklist ul,
#linkcategorydiv ul.categorychecklist ul { #linkcategorydiv ul.categorychecklist ul {
margin-left: 18px; margin-left: 18px;
} }
@ -2040,27 +2065,34 @@ ul.categorychecklist li {
margin-bottom: 0px; margin-bottom: 0px;
} }
.categorydiv .tabs-panel { .categorydiv .tabs-panel,
.customlinkdiv .tabs-panel,
.posttypediv .tabs-panel,
.taxonomydiv .tabs-panel {
border-width: 3px; border-width: 3px;
border-style: solid; border-style: solid;
} }
ul.category-tabs { ul.category-tabs,
ul.add-menu-item-tabs {
margin-top: 12px; margin-top: 12px;
} }
ul.category-tabs li.tabs { ul.category-tabs li.tabs,
ul.add-menu-item-tabs li.tabs {
border-style: solid solid none; border-style: solid solid none;
border-width: 1px 1px 0; border-width: 1px 1px 0;
} }
#post-body .category-tabs li.tabs { #post-body .category-tabs li.tabs,
#post-body .add-menu-item-tabs li.tabs {
border-style: solid none solid solid; border-style: solid none solid solid;
border-width: 1px 0 1px 1px; border-width: 1px 0 1px 1px;
margin-right: -1px; margin-right: -1px;
} }
ul.category-tabs li { ul.category-tabs li,
ul.add-menu-item-tabs li {
padding: 5px 8px; padding: 5px 8px;
-moz-border-radius: 3px 3px 0 0; -moz-border-radius: 3px 3px 0 0;
-webkit-border-top-left-radius: 3px; -webkit-border-top-left-radius: 3px;
@ -3705,4 +3737,4 @@ table#available-headers label img {
border-width: 1px 1px 0; border-width: 1px 1px 0;
background-color: #fafafa; background-color: #fafafa;
color: #c1c1c1; color: #c1c1c1;
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -10,7 +10,7 @@
*/ */
/** Load WordPress Administration Bootstrap */ /** Load WordPress Administration Bootstrap */
require_once( './admin.php' ); require_once( 'admin.php' );
// Load all the nav menu interface functions // Load all the nav menu interface functions
require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' ); require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
@ -37,9 +37,6 @@ wp_enqueue_script( 'common' );
wp_enqueue_script( 'wp-lists' ); wp_enqueue_script( 'wp-lists' );
wp_enqueue_script( 'postbox' ); wp_enqueue_script( 'postbox' );
// Thickbox
add_thickbox();
// Container for any messages displayed to the user // Container for any messages displayed to the user
$messages_div = ''; $messages_div = '';
@ -53,10 +50,133 @@ $nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit'; $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
switch ( $action ) { switch ( $action ) {
case 'add-menu-item':
if ( current_user_can( 'switch_themes' ) ) {
check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
if ( isset( $_REQUEST['menu-item'] ) ) {
wp_save_nav_menu_item( $nav_menu_selected_id, $_REQUEST['menu-item'] );
}
}
break;
case 'move-down-menu-item' :
// moving down a menu item is the same as moving up the next in order
check_admin_referer( 'move-menu_item' );
$menu_item_id = (int) $_REQUEST['menu-item'];
$next_item_id = 0;
if ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) {
$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
if ( ! is_wp_error( $menus ) ) {
foreach( (array) $menus as $menu_id ) {
$move_down_ordered_menu_items = (array) wp_get_nav_menu_items( $menu_id );
while ( $next = array_shift( $move_down_ordered_menu_items ) ) {
if ( isset( $next->ID ) && $next->ID == $menu_item_id ) {
break;
}
}
if ( $following = array_shift( $move_down_ordered_menu_items ) ) {
$next_item_id = (int) $following->ID;
}
}
}
}
// fall through to next case
case 'move-up-menu-item' :
check_admin_referer( 'move-menu_item' );
$menu_item_id = empty( $next_item_id ) ? (int) $_REQUEST['menu-item'] : $next_item_id;
if ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) {
$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
if ( ! is_wp_error( $menus ) ) {
foreach( (array) $menus as $menu_id ) {
$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
$menu_item_data = get_post( $menu_item_id , ARRAY_A );
// setup the data we need in one pass through the array of menu items
$dbids_to_orders = array();
$orders_to_dbids = array();
$objectids_to_dbids = array();
$dbids_to_objectids = array();
foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
if ( isset( $ordered_menu_item_object->ID ) ) {
if ( isset( $ordered_menu_item_object->menu_order ) ) {
$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
}
$possible_object_id = (int) get_post_meta( $ordered_menu_item_object->ID, '_menu_item_object_id', true );
if ( ! empty( $possible_object_id ) ) {
$dbids_to_objectids[$ordered_menu_item_object->ID] = $possible_object_id;
$objectids_to_dbids[$possible_object_id] = $ordered_menu_item_object->ID;
}
}
}
// if this menu item is not first
if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
// if this menu item is a child of the previous
if (
! empty( $menu_item_data['post_parent'] ) &&
isset( $objectids_to_dbids[$menu_item_data['post_parent']] ) &&
isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &&
( $objectids_to_dbids[$menu_item_data['post_parent']] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
) {
$parent_db_id = $objectids_to_dbids[$menu_item_data['post_parent']];
$parent_data = get_post( $parent_db_id, ARRAY_A );
if ( ! is_wp_error( $parent_data ) ) {
// if there is something before the parent, make menu item a child of the parent's parent
if ( ! empty( $dbids_to_orders[$parent_db_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) ) {
$menu_item_data['post_parent'] = $parent_data['post_parent'];
// else there isn't something before the parent
} else {
$menu_item_data['post_parent'] = 0;
}
// set former parent's [menu_order] to that of menu-item's
$parent_data['menu_order'] = $parent_data['menu_order'] + 1;
// set menu-item's [menu_order] to that of former parent
$menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
// save changes
wp_update_post($menu_item_data);
wp_update_post($parent_data);
}
// else this menu item is not a child of the previous
} elseif ( isset($dbids_to_objectids[$orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]] ) ) {
// just make it a child of the previous; keep the order
$menu_item_data['post_parent'] = (int) $dbids_to_objectids[$orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]];
wp_update_post($menu_item_data);
}
}
}
}
}
break;
case 'delete-menu-item':
$menu_item_id = (int) $_REQUEST['menu-item'];
check_admin_referer( 'delete-menu_item_' . $menu_item_id );
if ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) {
if ( wp_delete_post( $menu_item_id, true ) ) {
$messages_div = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';
}
}
break;
case 'delete': case 'delete':
check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id ); check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
if ( is_nav_menu($nav_menu_selected_id) ) { if ( is_nav_menu( $nav_menu_selected_id ) ) {
$delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id ); $delete_nav_menu = wp_delete_nav_menu( $nav_menu_selected_id );
if ( is_wp_error($delete_nav_menu) ) { if ( is_wp_error($delete_nav_menu) ) {
@ -70,98 +190,73 @@ switch ( $action ) {
break; break;
case 'update': case 'update':
check_admin_referer( 'update-nav_menu' ); check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
// Add Menu // Add Menu
if ( isset($_POST['create-menu-button']) ) { if ( 0 == $nav_menu_selected_id ) {
if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) { if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) {
$add_nav_menu = esc_html( $_POST['create-menu-name'] ); $new_menu_title = esc_html( $_POST['menu-name'] );
if ( $add_nav_menu ) { if ( $new_menu_title ) {
$add_nav_menu = wp_create_nav_menu( $add_nav_menu ); $_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
if ( is_wp_error( $add_nav_menu ) ) { if ( is_wp_error( $_nav_menu_selected_id ) ) {
$messages_div = '<div id="message" class="error"><p>' . $add_nav_menu->get_error_message() . '</p></div>'; $messages_div = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
} else { } else {
$nav_menu_selected_id = $add_nav_menu->term_id; $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
$nav_menu_selected_title = $add_nav_menu->name; $nav_menu_selected_id = $_nav_menu_selected_id;
$messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $add_nav_menu->name ) . '</p></div>'; $nav_menu_selected_title = $_menu_object->name;
$messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been successfully created.'), $nav_menu_selected_title ) . '</p></div>';
} }
} else { } else {
$messages_div = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>'; $messages_div = '<div id="message" class="error"><p>' . __('Please enter a valid menu name.') . '</p></div>';
} }
unset( $add_nav_menu );
} }
// update existing menu
} else { } else {
// @todo wrap this into wp_update_nav_menu_object(); $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
if ( isset($_POST['menu-name']) ) {
$old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A ); if ( ! is_wp_error( $_menu_object ) ) {
$args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], ); wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $_POST['menu-name'] ) );
$new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args ); $nav_menu_selected_title = $_menu_object->name;
} }
// Update menu items // Update menu items
// @todo: wrap update logic into wp_update_nav_menu(); if ( ! is_wp_error( $_menu_object ) ) {
$update_count = isset( $_POST['li-count'] ) ? (int) $_POST['li-count'] : 0;
$update_nav_menu = is_nav_menu( $nav_menu_selected_id );
if ( !is_wp_error($update_nav_menu) ) {
$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); $menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
// Loop through all POST variables // Loop through all the menu items' POST variables
for ( $k = 0; $k < $update_count; $k++ ) { foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) {
// Menu item title can't be blank // Menu item title can't be blank
if ( '' == $_POST['menu-item-title'][$k] ) if ( '' == $_POST['menu-item-title'][$_key] )
continue; continue;
$menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0; $args = array(
$menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0; 'menu-item-db-id' => $_POST['menu-item-db-id'][$_key],
$menu_item_object = isset( $_POST['menu-item-object'][$k] ) ? $_POST['menu-item-object'][$k] : ''; 'menu-item-object-id' => $_POST['menu-item-object-id'][$_key],
$menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0; 'menu-item-object' => $_POST['menu-item-object'][$_key],
$menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0; 'menu-item-parent-id' => $_POST['menu-item-parent-id'][$_key],
$menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom'; 'menu-item-position' => $_POST['menu-item-position'][$_key],
$menu_item_append = isset( $_POST['menu-item-append'][$k] ) ? $_POST['menu-item-append'][$k] : 'custom'; 'menu-item-type' => $_POST['menu-item-type'][$_key],
$menu_item_title = isset( $_POST['menu-item-title'][$k] ) ? $_POST['menu-item-title'][$k] : ''; 'menu-item-append' => $_POST['menu-item-append'][$_key],
$menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : ''; 'menu-item-title' => $_POST['menu-item-title'][$_key],
$menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k] : ''; 'menu-item-url' => $_POST['menu-item-url'][$_key],
$menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : ''; 'menu-item-description' => $_POST['menu-item-description'][$_key],
$menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : ''; 'menu-item-attr-title' => $_POST['menu-item-attr-title'][$_key],
$menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : ''; 'menu-item-target' => $_POST['menu-item-target'][$_key],
$menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : ''; 'menu-item-classes' => $_POST['menu-item-classes'][$_key],
'menu-item-xfn' => $_POST['menu-item-xfn'][$_key],
// Populate the menu item object
$post = array(
'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'ping_status' => 0,
'post_author' => $user_ID, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
'post_title' => $menu_item_title, 'post_excerpt' => $menu_item_attr_title,
'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
'post_content' => $menu_item_description,
); );
// New menu item $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args );
if ( $menu_item_db_id == 0 ) {
$menu_item_db_id = wp_insert_post( $post );
// Update existing menu item if ( ! is_wp_error( $menu_item_db_id ) && isset( $menu_items[$menu_item_db_id] ) ) {
} elseif ( isset($menu_items[$menu_item_db_id]) || ( 'custom' == $menu_item_type && 0 != $menu_item_db_id ) ) {
$post['ID'] = $menu_item_db_id;
wp_update_post( $post );
unset( $menu_items[$menu_item_db_id] ); unset( $menu_items[$menu_item_db_id] );
} }
update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($menu_item_type) );
update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $menu_item_object_id );
update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($menu_item_object) );
update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($menu_item_target) );
// @todo handle sanitizing multiple classes separated by whitespace.
update_post_meta( $menu_item_db_id, '_menu_item_classes', sanitize_html_class($menu_item_classes) );
update_post_meta( $menu_item_db_id, '_menu_item_xfn', sanitize_html_class($menu_item_xfn) );
// @todo: only save custom link urls.
update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($menu_item_url) );
} }
// Remove menu items from the menu that weren't in $_POST // Remove menu items from the menu that weren't in $_POST
@ -173,8 +268,8 @@ switch ( $action ) {
do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); do_action( 'wp_update_nav_menu', $nav_menu_selected_id );
$messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $update_nav_menu->name ) . '</p></div>'; $messages_div = '<div id="message" class="updated"><p>' . sprintf( __('The <strong>%s</strong> menu has been updated.'), $nav_menu_selected_title ) . '</p></div>';
unset( $update_nav_menu, $update_count, $menu_items ); unset( $menu_items );
} }
} }
break; break;
@ -184,48 +279,40 @@ switch ( $action ) {
$nav_menus = wp_get_nav_menus(); $nav_menus = wp_get_nav_menus();
// Get recently edited nav menu // Get recently edited nav menu
$recently_edited = get_user_option( 'nav_menu_recently_edited' ); $recently_edited = (int) get_user_option( 'nav_menu_recently_edited' );
// If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu. // If there was no recently edited menu, and $nav_menu_selected_id is a nav menu, update recently edited menu.
if ( !$recently_edited && is_nav_menu($nav_menu_selected_id) ) { if ( !$recently_edited && is_nav_menu( $nav_menu_selected_id ) ) {
$recently_edited = $nav_menu_selected_id; $recently_edited = $nav_menu_selected_id;
// Else if $nav_menu_selected_id is not a menu, but $recently_edited is, grab that one. // Else if $nav_menu_selected_id is not a menu and not requesting that we create a new menu, but $recently_edited is a menu, grab that one.
} elseif ( 0 == $nav_menu_selected_id && is_nav_menu($recently_edited) ) { } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && is_nav_menu( $recently_edited ) ) {
$nav_menu_selected_id = $recently_edited; $nav_menu_selected_id = $recently_edited;
// Else try to grab the first menu from the menus list // Else try to grab the first menu from the menus list
} elseif ( 0 == $nav_menu_selected_id && ! empty($nav_menus) ) { } elseif ( 0 == $nav_menu_selected_id && ! isset( $_REQUEST['menu'] ) && ! empty($nav_menus) ) {
$nav_menu_selected_id = $nav_menus[0]->term_id; $nav_menu_selected_id = $nav_menus[0]->term_id;
} }
// Update the user's setting // Update the user's setting
if ( $nav_menu_selected_id != $recently_edited && is_nav_menu($nav_menu_selected_id) ) if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) )
update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id ); update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
// If there's a menu, get it's name. // If there's a menu, get its name.
if ( !$nav_menu_selected_title && $nav_menu_selected_title = is_nav_menu( $nav_menu_selected_id ) ) { if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
$nav_menu_selected_title = $nav_menu_selected_title->name; $_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
$nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
} }
// Create Menu Metabox
add_meta_box( 'create-menu', __('Create Menu'), 'wp_nav_menu_create_metabox', 'nav-menus', 'side', 'core' );
// The user has no menus.
if ( !is_nav_menu( $nav_menu_selected_id ) ) {
$messages_div = '<div id="message" class="updated"><p>' . __('You do not have any menus. Create a new menu.') . '</p></div>';
// The theme supports menus // The theme supports menus
} elseif ( current_theme_supports('nav-menus') ) { if ( current_theme_supports('nav-menus') ) {
// Register nav menu metaboxes // Register nav menu metaboxes
add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'nav-menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) ); wp_nav_menu_meta_boxes_setup();
wp_nav_menu_metaboxes_setup();
// The theme does not support menus but supports widgets // The theme does not support menus but supports widgets
} elseif ( current_theme_supports('widgets') ) { } elseif ( current_theme_supports('widgets') ) {
// Register nav menu metaboxes // Register nav menu metaboxes
add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'nav-menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) ); wp_nav_menu_meta_boxes_setup();
wp_nav_menu_metaboxes_setup();
$messages_div = '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the &#8220;Navigation Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>'; $messages_div = '<div id="message" class="error"><p>' . __('The current theme does not natively support menus, but you can use the &#8220;Navigation Menu&#8221; widget to add any menus you create here to the theme&#8217;s sidebar.') . '</p></div>';
// The theme supports neither menus nor widgets. // The theme supports neither menus nor widgets.
@ -235,114 +322,113 @@ if ( !is_nav_menu( $nav_menu_selected_id ) ) {
} }
// Get the admin header // Get the admin header
require_once( './admin-header.php' ); require_once( 'admin-header.php' );
?> ?>
<div class="wrap"> <div class="wrap nav-edit-wrap">
<?php screen_icon(); ?> <?php screen_icon(); ?>
<h2><?php esc_html_e('Menus'); ?></h2> <h2><?php esc_html_e('Menus'); ?></h2>
<?php /* OMGWTFBBQ */ ?><div class="error"><p><strong><?php _e('Beta Testers:') ?></strong> <?php _e('This feature is still under construction. You can try it out, but expect it to change in layout and functionality in the second beta release.'); ?></p></div>
<?php echo $messages_div; ?> <?php echo $messages_div; ?>
<div class="hide-if-js error"><p><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></p></div>
<?php if ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) : ?>
<div id="menu-settings-column" class="metabox-holder">
<?php if ( !empty($nav_menus) && count($nav_menus) > 1 && ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) ) : ?> <form id="nav-menu-meta" action="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-menu-meta" method="post" enctype="multipart/form-data">
<ul class="subsubsub"> <input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
<?php <input type="hidden" name="action" value="add-menu-item" />
foreach ( $nav_menus as $_nav_menu ) { <?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
$sep = end( $nav_menus ) == $_nav_menu ? '' : ' | '; <?php do_meta_boxes( 'nav-menus', 'side', null ); ?>
</form>
if ( $nav_menu_selected_id == $_nav_menu->term_id ) </div><!-- /#menu-settings-column -->
echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&amp;menu=' . esc_attr($_nav_menu->term_id) ) .'" class="current">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>';
else <div id="menu-management" class="">
echo '<li><a href="'. admin_url( 'nav-menus.php?action=edit&amp;menu=' . esc_attr($_nav_menu->term_id) ) .'">'. esc_html( $_nav_menu->name ) .'</a>'. $sep .'</li>'; <h2>
} <?php
?> foreach( (array) $nav_menus as $_nav_menu ) :
</ul>
<?php endif; ?> ?>
<a href="<?php
echo add_query_arg(
array(
'action' => 'edit',
'menu' => $_nav_menu->term_id,
),
admin_url( 'nav-menus.php' )
);
?>" class="menu-tabs<?php
if ( $nav_menu_selected_id != $_nav_menu->term_id )
echo ' menu-tab-inactive';
?>"><?php echo esc_html( $_nav_menu->name ); ?></a>
<div id="menu-management" class="metabox-holder has-right-sidebar"> <?php
<form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data"> endforeach;
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> ?>
<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> <a href="<?php
<?php wp_nonce_field( 'update-nav_menu' ); ?> echo add_query_arg(
<input type="hidden" name="action" value="update" /> array(
<input type="hidden" name="li-count" id="li-count" value="-1" /> 'action' => 'edit',
<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> 'menu' => 0,
<input type="hidden" id="hidden-metaboxes" value="<?php echo wp_initial_nav_menu_meta_boxes(); ?>" /> ),
<div id="post-body"> admin_url( 'nav-menus.php' )
<div id="post-body-content"> );
<?php if ( is_nav_menu($nav_menu_selected_id) && ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) ) : ?> ?>" class="menu-tabs menu-add-new<?php
<div id="menu-container" class="postbox"> if ( 0 != $nav_menu_selected_id )
<h3 class="hndle"><?php echo esc_html( $nav_menu_selected_title ); ?></h3> echo ' menu-tab-inactive';
<div class="inside"> ?>"><?php printf( '<abbr title="%s">+</abbr>', esc_html__( 'Add menu' ) ); ?></a>
<?php wp_nav_menu( array( 'menu' => $nav_menu_selected_id, 'context' => 'backend' ) ); ?> </h2>
</div><!-- /.inside --> <div class="menu-edit">
<!-- /#nav-menu-canvas .postbox--> <form id="update-nav-menu" action="<?php echo admin_url( 'nav-menus.php' ); ?>" method="post" enctype="multipart/form-data">
</div> <div id="submitpost" class="submitbox">
<?php endif; ?> <div id="minor-publishing">
</div><!-- /#post-body-content--> <div class="misc-pub-section misc-pub-section-last">
</div><!--- /#post-body --> <label class="howto" for="menu-name">
<div id="menu-settings-column" class="inner-sidebar"> <span><?php _e('Name'); ?></span>
<input id="menu-name" name="menu-name" type="text" class="regular-text menu-item-textbox" value="<?php echo esc_attr( $nav_menu_selected_title ); ?>" />
<br class="clear" />
</label>
</div><!--END .misc-pub-section misc-pub-section-last-->
<br class="clear" />
</div><!--END #misc-publishing-actions-->
<div id="major-publishing-actions">
<?php do_meta_boxes( 'nav-menus', 'side', null ); ?> <?php if ( ! empty( $nav_menu_selected_id ) ) : ?>
<div id="delete-action">
<a class="submitdelete deletion menu-delete" href="<?php echo wp_nonce_url( admin_url('nav-menus.php?action=delete&amp;menu=' . $nav_menu_selected_id), 'delete-nav_menu-' . $nav_menu_selected_id ); ?>"><?php _e('Delete Menu'); ?></a>
</div><!--END #delete-action-->
<?php endif; ?>
</div><!-- /#menu-settings-column --> <div id="publishing-action">
</form><!--/#update-nav-menu--> <input class="button-primary" name="save_menu" type="submit" value="<?php esc_attr_e('Save Menu'); ?>" />
<br class="clear" /> </div><!--END #publishing-action-->
</div><!-- /.metabox-holder has-right-sidebar--> <br class="clear" />
</div><!--END #major-publishing-actions-->
</div><!--END #submitpost .submitbox-->
<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
<?php wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' ); ?>
<input type="hidden" name="action" value="update" />
<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
<input type="hidden" id="hidden-metaboxes" value="<?php echo wp_initial_nav_menu_meta_boxes(); ?>" />
<div id="post-body">
<div id="post-body-content">
<?php if ( is_nav_menu( $nav_menu_selected_id ) && ( current_theme_supports('nav-menus') || current_theme_supports('widgets') ) ) : ?>
<ul class="menu" id="menu-to-edit">
<?php
$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
if ( ! is_wp_error( $edit_markup ) ) {
echo $edit_markup;
}
?>
</ul>
<?php endif; ?>
<br class="clear" />
</div><!-- /#post-body-content-->
</div><!--- /#post-body -->
</form><!--/#update-nav-menu-->
</div><!-- /.menu-edit -->
</div><!-- /#menu-management -->
<?php endif; // if menus supported in current theme ?>
</div><!-- /.wrap--> </div><!-- /.wrap-->
<div id="menu-item-settings">
<p class="description">
<label for="edit-menu-item-title">
<?php _e( 'Menu Title' ); ?><br />
<input type="text" id="edit-menu-item-title" class="widefat" name="edit-menu-item-title" value="" tabindex="1" />
</label>
</p>
<p class="description">
<label for="edit-menu-item-url">
<?php _e( 'URL' ); ?><br />
<input type="text" id="edit-menu-item-url" class="widefat code" name="edit-menu-item-url" value="" tabindex="2" />
</label>
</p>
<p class="description">
<label for="edit-menu-item-attr-title">
<?php _e( 'Title Attribute' ); ?><br />
<input type="text" id="edit-menu-item-attr-title" class="widefat" name="edit-menu-item-attr-title" value="" tabindex="3" />
</label>
</p>
<p class="description">
<label for="edit-menu-item-target">
<?php _e( 'Link Target' ); ?><br />
<select id="edit-menu-item-target" class="widefat" name="edit-menu-item-target" tabindex="4">
<option value=""><?php _e('Same window or tab'); ?></option>
<option value="_blank"><?php _e('New window or tab'); ?></option>
</select>
</label>
</p>
<p class="description">
<label for="edit-menu-item-classes">
<?php _e( 'CSS Classes (optional)' ); ?><br />
<input type="text" id="edit-menu-item-classes" class="widefat code" name="edit-menu-item-classes" value="" tabindex="5" />
</label>
</p>
<p class="description">
<label for="edit-menu-item-xfn">
<?php _e( 'Link Relationship (XFN) (optional)' ); ?><br />
<input type="text" id="edit-menu-item-xfn" class="widefat code" name="edit-menu-item-xfn" value="" tabindex="6" />
</label>
</p>
<p class="description">
<label for="edit-menu-item-description">
<?php _e( 'Description (optional)' ); ?><br />
<textarea id="edit-menu-item-description" class="widefat" rows="3" name="edit-menu-item-description" tabindex="7" /></textarea>
<span class="description"><?php _e('The description will be displayed in the menu if the current theme supports it.'); ?></span>
</label>
</p>
<p>
<a id="update-menu-item" class="save button-primary" tabindex="8"><?php _e('Save Changes'); ?></a>
<a id="cancel-save" class="submitdelete deletion" tabindex="9"><?php _e('Cancel'); ?></a>
</p>
<input type="hidden" id="edit-menu-item-id" name="edit-item-id" value="" />
</div><!-- /#menu-item-settings-->
<?php include( './admin-footer.php' ); ?> <?php include( 'admin-footer.php' ); ?>

View File

@ -1123,102 +1123,6 @@ class Walker {
} }
} }
/**
* Create HTML list of nav menu items.
*
* @package WordPress
* @since 3.0.0
* @uses Walker
*/
class Walker_Nav_Menu extends Walker {
/**
* @see Walker::$tree_type
* @since 3.0.0
* @var string
*/
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
/**
* @see Walker::$db_fields
* @since 3.0.0
* @todo Decouple this.
* @var array
*/
var $db_fields = array( 'parent' => 'post_parent', 'id' => 'object_id' );
/**
* @see Walker::start_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"sub-menu\">\n";
}
/**
* @see Walker::end_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
/**
* @see Walker::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param int $current_page Menu item ID.
* @param object $args
*/
function start_el(&$output, $item, $depth, $args) {
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$classes = $value = '';
if ( 'frontend' == $args->context ) {
global $wp_query;
$classes = array( 'menu-item', 'menu-item-type-'. $item->type, $item->classes );
if ( 'custom' != $item->object )
$classes[] = 'menu-item-object-'. $item->object;
if ( $item->object_id == $wp_query->get_queried_object_id() )
$classes[] = 'current-menu-item';
// @todo add classes for parent/child relationships
$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$classes = ' class="' . esc_attr( $classes ) . '"';
} else {
$value = ' value="' . $item->ID . '"';
}
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $classes .'>' . wp_get_nav_menu_item( $item, $args->context, $args );
}
/**
* @see Walker::end_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
*/
function end_el(&$output, $item, $depth) {
$output .= "</li>\n";
}
}
/** /**
* Create HTML list of pages. * Create HTML list of pages.
* *

View File

@ -7,6 +7,160 @@
* @since 3.0.0 * @since 3.0.0
*/ */
/**
* Create HTML list of nav menu items.
*
* @package WordPress
* @since 3.0.0
* @uses Walker
*/
class Walker_Nav_Menu extends Walker {
/**
* @see Walker::$tree_type
* @since 3.0.0
* @var string
*/
var $tree_type = array( 'post_type', 'taxonomy', 'custom' );
/**
* @see Walker::$db_fields
* @since 3.0.0
* @todo Decouple this.
* @var array
*/
var $db_fields = array( 'parent' => 'post_parent', 'id' => 'object_id' );
/**
* @see Walker::start_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
function start_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"sub-menu\">\n";
}
/**
* @see Walker::end_lvl()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param int $depth Depth of page. Used for padding.
*/
function end_lvl(&$output, $depth) {
$indent = str_repeat("\t", $depth);
$output .= "$indent</ul>\n";
}
/**
* @see Walker::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param int $current_page Menu item ID.
* @param object $args
*/
function start_el(&$output, $item, $depth, $args) {
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$classes = $value = '';
$classes = array( 'menu-item', 'menu-item-type-'. $item->type, $item->classes );
if ( 'custom' != $item->object )
$classes[] = 'menu-item-object-'. $item->object;
if ( $item->object_id == $wp_query->get_queried_object_id() )
$classes[] = 'current-menu-item';
// @todo add classes for parent/child relationships
$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$classes = ' class="' . esc_attr( $classes ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $classes .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title ) . $args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'wp_get_nav_menu_item', $item_output, $args );
}
/**
* @see Walker::end_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Page data object. Not used.
* @param int $depth Depth of page. Not Used.
*/
function end_el(&$output, $item, $depth) {
$output .= "</li>\n";
}
}
/**
* Create HTML list of nav menu input items.
*
* @package WordPress
* @since 3.0.0
* @uses Walker_Nav_Menu
*/
class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
/**
* @see Walker::start_el()
* @since 3.0.0
*
* @param string $output Passed by reference. Used to append additional content.
* @param object $item Menu item data object.
* @param int $depth Depth of menu item. Used for padding.
* @param int $current_page Menu item ID.
* @param object $args
*/
function start_el(&$output, $item, $depth, $args) {
static $_placeholder;
$_placeholder = 0 > $_placeholder ? $_placeholder - 1 : -1;
$possible_object_id = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_placeholder;
$possible_db_id = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$output .= $indent . '<li>';
$output .= '<label class="menu-item-title">';
$output .= '<input type="checkbox" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="'. esc_attr( $item->object_id ) .'" />';
$output .= $item->title .'</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="'. esc_attr( $item->object ) .'" />';
$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="'. esc_attr( $item->post_parent ) .'" />';
$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="'. esc_attr( $item->type ) .'" />';
$output .= '<input type="hidden" class="menu-item-append" name="menu-item[' . $possible_object_id . '][menu-item-append]" value="'. esc_attr( $item->append ) .'" />';
$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="'. esc_attr( $item->title ) .'" />';
$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="'. esc_attr( $item->url ) .'" />';
$output .= '<input type="hidden" class="menu-item-append" name="menu-item[' . $possible_object_id . '][menu-item-append]" value="'. esc_attr( $item->append ) .'" />';
$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="'. esc_attr( $item->target ) .'" />';
$output .= '<input type="hidden" class="menu-item-attr_title" name="menu-item[' . $possible_object_id . '][menu-item-attr_title]" value="'. esc_attr( $item->attr_title ) .'" />';
$output .= '<input type="hidden" class="menu-item-description" name="menu-item[' . $possible_object_id . '][menu-item-description]" value="'. esc_attr( $item->description ) .'" />';
$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="'. esc_attr( $item->classes ) .'" />';
$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="'. esc_attr( $item->xfn ) .'" />';
}
}
/** /**
* Displays a navigation menu. * Displays a navigation menu.
* *
@ -17,9 +171,6 @@
* menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'. * menu_class - CSS class to use for the div container of the menu list. Defaults to 'menu'.
* format - Whether to format the ul. Defaults to 'div'. * format - Whether to format the ul. Defaults to 'div'.
* fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'. * fallback_cb - If the menu doesn't exists, a callback function will fire. Defaults to 'wp_page_menu'.
* container - Type of container tag. Avalible options div, p, or nav. Defaults to 'div'.
* container_class - Chooses a class for the container.
* container_id - Chooses an id for the container.
* before - Text before the link text. * before - Text before the link text.
* after - Text after the link text. * after - Text after the link text.
* link_before - Text before the link. * link_before - Text before the link.
@ -33,7 +184,7 @@
* @param array $args Arguments * @param array $args Arguments
*/ */
function wp_nav_menu( $args = array() ) { function wp_nav_menu( $args = array() ) {
$defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'container_id' => '', 'menu_class' => 'menu', 'echo' => true, $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '', 'fallback_cb' => 'wp_page_menu', 'before' => '', 'after' => '', 'link_before' => '', 'link_after' => '',
'depth' => 0, 'walker' => '', 'context' => 'frontend' ); 'depth' => 0, 'walker' => '', 'context' => 'frontend' );
@ -46,7 +197,7 @@ function wp_nav_menu( $args = array() ) {
// If we couldn't find a menu based off the name, id or slug, // If we couldn't find a menu based off the name, id or slug,
// get the first menu that has items. // get the first menu that has items.
if ( !$menu ) { if ( ! $menu ) {
$menus = wp_get_nav_menus(); $menus = wp_get_nav_menus();
foreach ( $menus as $menu_maybe ) { foreach ( $menus as $menu_maybe ) {
if ( wp_get_nav_menu_items($menu_maybe->term_id) ) { if ( wp_get_nav_menu_items($menu_maybe->term_id) ) {
@ -56,9 +207,9 @@ function wp_nav_menu( $args = array() ) {
} }
} }
// If the menu exists, get it's items. // If the menu exists, get its items.
if ( $menu && !is_wp_error($menu) ) if ( $menu && ! is_wp_error($menu) )
$menu_items = wp_get_nav_menu_items( $menu->term_id, $args->context ); $menu_items = wp_get_nav_menu_items( $menu->term_id );
// If no menu was found or if the menu has no items, call the fallback_cb // If no menu was found or if the menu has no items, call the fallback_cb
if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) { if ( !$menu || is_wp_error($menu) || ( isset($menu_items) && empty($menu_items) ) ) {
@ -73,15 +224,15 @@ function wp_nav_menu( $args = array() ) {
if ( in_array( $args->container, $container_allowedtags ) ) { if ( in_array( $args->container, $container_allowedtags ) ) {
$class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-'. $menu->slug .'-container"'; $class = $args->container_class ? ' class="' . esc_attr($args->container_class) . '"' : ' class="menu-'. $menu->slug .'-container"';
$container_id = $args->container_id ? ' id="' . esc_attr($args->container_id) . '"' : '' ; $nav_menu .= '<'. $args->container . $class .'>';
$nav_menu .= '<'. $args->container . $class . $container_id .'>';
} }
// Set up the $menu_item variables // Set up the $menu_item variables
$sorted_menu_items = array();
foreach ( (array) $menu_items as $key => $menu_item ) foreach ( (array) $menu_items as $key => $menu_item )
$menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item( $menu_item, 'frontend' ); $sorted_menu_items[$menu_item->menu_order] = wp_setup_nav_menu_item( $menu_item );
$items .= walk_nav_menu_tree( $menu_items, $args->depth, $args ); $items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
// Attributes // Attributes
$attributes = ' id="menu-' . $menu->slug . '"'; $attributes = ' id="menu-' . $menu->slug . '"';
@ -112,83 +263,17 @@ function wp_nav_menu( $args = array() ) {
} }
/** /**
* Returns the menu item formatted based on it's context. * Retrieve the HTML list content for nav menu items.
* *
* @since 3.0.0 * @uses Walker_Nav_Menu to create HTML list content.
* * @since 2.1.0
* @param string $menu_item The menu item to format. * @see Walker::walk() for parameters and return description.
* @param string $context The context to which the menu item will be formatted to.
* @param string $args Optional. Args used for the 'template' context.
* @return string $output The menu formatted menu item.
*/ */
function wp_get_nav_menu_item( $menu_item, $context = 'frontend', $args = array() ) { function walk_nav_menu_tree( $items, $depth, $r ) {
$output = ''; $walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker;
switch ( $context ) { $args = array( $items, $depth, $r );
case 'frontend':
$attributes = ! empty( $menu_item->attr_title ) ? ' title="' . esc_attr( $menu_item->attr_title ) .'"' : '';
$attributes .= ! empty( $menu_item->target ) ? ' target="' . esc_attr( $menu_item->target ) .'"' : '';
$attributes .= ! empty( $menu_item->xfn ) ? ' rel="' . esc_attr( $menu_item->xfn ) .'"' : '';
$attributes .= ! empty( $menu_item->url ) ? ' href="' . esc_attr( $menu_item->url ) .'"' : '';
$output .= $args->before; return call_user_func_array( array(&$walker, 'walk'), $args );
$output .= '<a'. $attributes .'>';
$output .= $args->link_before . apply_filters( 'the_title', $menu_item->title ) . $args->link_after;
$output .= '</a>';
$output .= $args->after;
break;
case 'backend':
$output .= '<dl><dt>';
$output .= '<span class="item-title">'. esc_html( $menu_item->title ) .'</span>';
$output .= '<span class="item-controls">';
$output .= '<span class="item-type">'. esc_html( $menu_item->append ) .'</span>';
// Actions
$output .= '<a class="item-edit thickbox" id="edit-'. esc_attr( $menu_item->ID ) .'" value="'. esc_attr( $menu_item->ID ) .'" title="'. __('Edit Menu Item') .'" href="#TB_inline?height=540&width=300&inlineId=menu-item-settings">'. __('Edit') .'</a> | ';
$output .= '<a class="item-delete" id="delete-'. esc_attr( $menu_item->ID ) .'" value="'. esc_attr( $menu_item->ID ) .'">'. __('Delete') .'</a>';
$output .= '</span></dt></dl>';
// Menu Item Settings
$output .= '<input type="hidden" name="menu-item-db-id[]" value="'. esc_attr( $menu_item->ID ) .'" />';
$output .= '<input type="hidden" name="menu-item-object-id[]" value="'. esc_attr( $menu_item->object_id ) .'" />';
$output .= '<input type="hidden" name="menu-item-object[]" value="'. esc_attr( $menu_item->object ) .'" />';
$output .= '<input type="hidden" name="menu-item-parent-id[]" value="'. esc_attr( $menu_item->post_parent ) .'" />';
$output .= '<input type="hidden" name="menu-item-position[]" value="'. esc_attr( $menu_item->menu_order ) .'" />';
$output .= '<input type="hidden" name="menu-item-type[]" value="'. esc_attr( $menu_item->type ) .'" />';
$output .= '<input type="hidden" name="menu-item-title[]" value="'. esc_attr( $menu_item->title ) .'" />';
$output .= '<input type="hidden" name="menu-item-url[]" value="'. esc_attr( $menu_item->url ) .'" />';
$output .= '<input type="hidden" name="menu-item-description[]" value="'. esc_attr( $menu_item->description ) .'" />';
$output .= '<input type="hidden" name="menu-item-classes[]" value="'. esc_attr( $menu_item->classes ) .'" />';
$output .= '<input type="hidden" name="menu-item-xfn[]" value="'. esc_attr( $menu_item->xfn ) .'" />';
$output .= '<input type="hidden" name="menu-item-attr-title[]" value="'.esc_attr( $menu_item->post_excerpt ) .'" />';
$output .= '<input type="hidden" name="menu-item-target[]" value="'. esc_attr( $menu_item->target ) .'" />';
break;
case 'custom':
case 'taxonomy':
case 'post_type':
$output .= '<label class="menu-item-title"><input type="checkbox" id="'. esc_attr( 'menu-item-' . $menu_item->object_id ) .'" value="'. esc_attr( $menu_item->url ) .'" />'. $menu_item->title .'</label>';
// Menu item hidden fields
$output .= '<input type="hidden" class="menu-item-db-id" value="0" />';
$output .= '<input type="hidden" class="menu-item-object-id" value="'. esc_attr( $menu_item->object_id ) .'" />';
$output .= '<input type="hidden" class="menu-item-object" value="'. esc_attr( $menu_item->object ) .'" />';
$output .= '<input type="hidden" class="menu-item-parent-id" value="'. esc_attr( $menu_item->post_parent ) .'" />';
$output .= '<input type="hidden" class="menu-item-type" value="'. esc_attr( $menu_item->type ) .'" />';
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
$output .= '<input type="hidden" class="menu-item-title" value="'. esc_attr( $menu_item->title ) .'" />';
$output .= '<input type="hidden" class="menu-item-url" value="'. esc_attr( $menu_item->url ) .'" />';
$output .= '<input type="hidden" class="menu-item-append" value="'. esc_attr( $menu_item->append ) .'" />';
$output .= '<input type="hidden" class="menu-item-target" value="'. esc_attr( $menu_item->target ) .'" />';
$output .= '<input type="hidden" class="menu-item-attr_title" value="'. esc_attr( $menu_item->attr_title ) .'" />';
$output .= '<input type="hidden" class="menu-item-description" value="'. esc_attr( $menu_item->description ) .'" />';
$output .= '<input type="hidden" class="menu-item-classes" value="'. esc_attr( $menu_item->classes ) .'" />';
$output .= '<input type="hidden" class="menu-item-xfn" value="'. esc_attr( $menu_item->xfn ) .'" />';
break;
}
return apply_filters( 'wp_get_nav_menu_item', $output, $context, $args );
} }
?>
?>

View File

@ -16,7 +16,22 @@
* @return mixed $menu|false Or WP_Error * @return mixed $menu|false Or WP_Error
*/ */
function wp_get_nav_menu_object( $menu ) { function wp_get_nav_menu_object( $menu ) {
return is_nav_menu( $menu ); if ( ! $menu )
return false;
$menu_obj = get_term( $menu, 'nav_menu' );
if ( ! $menu_obj )
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );
if ( ! $menu_obj )
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
if ( ! $menu_obj ) {
$menu_obj = false;
}
return $menu_obj;
} }
/** /**
@ -27,25 +42,18 @@ function wp_get_nav_menu_object( $menu ) {
* @since 3.0.0 * @since 3.0.0
* *
* @param int|string $menu The menu to check * @param int|string $menu The menu to check
* @return mixed Menu Object, if it exists. Else, false or WP_Error * @return bool Whether the menu exists.
*/ */
function is_nav_menu( $menu ) { function is_nav_menu( $menu ) {
if ( !$menu ) if ( ! $menu )
return false; return false;
$menu_obj = wp_get_nav_menu_object( $menu );
$menu_obj = get_term( $menu, 'nav_menu' ); if ( $menu_obj && ! is_wp_error( $menu_obj ) && ! empty( $menu_obj->term_id ) )
return true;
if ( !$menu_obj )
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' ); return false;
if ( !$menu_obj )
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );
if ( !$menu_obj ) {
$menu_obj = false;
}
return $menu_obj;
} }
/** /**
@ -96,7 +104,7 @@ function wp_create_nav_menu( $menu_name, $args = array() ) {
*/ */
function wp_delete_nav_menu( $menu ) { function wp_delete_nav_menu( $menu ) {
$menu = wp_get_nav_menu_object( $menu ); $menu = wp_get_nav_menu_object( $menu );
if ( !$menu ) if ( ! $menu )
return false; return false;
$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' ); $menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
@ -116,6 +124,151 @@ function wp_delete_nav_menu( $menu ) {
} }
} }
/**
* Save the properties of a menu or create a new menu with those properties.
*
* @since 3.0.0
*
* @param int $menu_id The ID of the menu
* @param array $menu_data The array of menu data.
* @return int The menu's ID.
*/
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
$menu_id = (int) $menu_id;
$_menu = wp_get_nav_menu_object( $menu_id );
// menu doesn't already exist
if ( ! $_menu || is_wp_error( $_menu ) ) {
$_menu = wp_create_nav_menu( $menu_data['menu-name'] );
}
if ( $_menu && isset( $_menu->term_id ) && ! is_wp_error( $_menu ) ) {
$args = array(
'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ),
'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ),
'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ),
'slug' => null,
);
$menu_id = (int) $_menu->term_id;
$update_response = wp_update_term( $menu_id, 'nav_menu', $args );
if ( ! is_wp_error( $update_response ) ) {
return $menu_id;
}
} else {
return 0;
}
}
/**
* Save the properties of a menu item or create a new one.
*
* @since 3.0.0
*
* @param int $menu_id The ID of the menu. Required.
* @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
* @param array $menu_item_data The menu item's data.
* @return int The menu item's database ID or WP_Error object on failure.
*/
function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
$menu_id = (int) $menu_id;
$menu_item_db_id = (int) $menu_item_db_id;
$menu = wp_get_nav_menu_object( $menu_id );
if ( ! $menu || is_wp_error( $menu ) ) {
return $menu;
}
$menu_items = (array) wp_get_nav_menu_items( $menu_id );
$count = count( $menu_items );
$defaults = array(
'menu-item-db-id' => $menu_item_db_id,
'menu-item-object-id' => 0,
'menu-item-object' => '',
'menu-item-parent-id' => 0,
'menu-item-position' => 0,
'menu-item-type' => 'custom',
'menu-item-append' => 'custom',
'menu-item-title' => '',
'menu-item-url' => '',
'menu-item-description' => '',
'menu-item-attr-title' => '',
'menu-item-target' => '',
'menu-item-classes' => '',
'menu-item-xfn' => '',
);
$args = wp_parse_args( $menu_item_data, $defaults );
if ( 0 == (int) $args['menu-item-position'] ) {
$last_item = array_pop( $menu_items );
if ( $last_item && isset( $last_item->ID ) ) {
$last_data = get_post( $last_item->ID );
if ( ! is_wp_error( $last_data ) && isset( $last_data->menu_order ) ) {
$args['menu-item-position'] = 1 + (int) $last_data->menu_order;
}
} else {
$args['menu-item-position'] = $count;
}
}
// Populate the menu item object
$post = array(
'menu_order' => $args['menu-item-position'],
'ping_status' => 0,
'post_content' => $args['menu-item-description'],
'post_excerpt' => $args['menu-item-attr-title'],
'post_parent' => $args['menu-item-parent-id'],
'post_status' => 'publish',
'post_title' => $args['menu-item-title'],
'post_type' => 'nav_menu_item',
'tax_input' => array( 'nav_menu' => $menu->name ),
);
// New menu item
if ( 0 == $menu_item_db_id ) {
$menu_item_db_id = wp_insert_post( $post );
// Update existing menu item
} else {
$post['ID'] = $menu_item_db_id;
wp_update_post( $post );
}
if ( 'custom' == $args['menu-item-type'] ) {
$args['menu-item-object-id'] = $menu_item_db_id;
$args['menu-item-object'] = 'custom';
}
if ( $menu_item_db_id && ! is_wp_error( $menu_item_db_id ) ) {
$menu_item_db_id = (int) $menu_item_db_id;
update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) );
update_post_meta( $menu_item_db_id, '_menu_item_object_id', (int) $args['menu-item-object-id'] );
update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );
// @todo handle sanitizing multiple classes separated by whitespace.
update_post_meta( $menu_item_db_id, '_menu_item_classes', sanitize_html_class($args['menu-item-classes']) );
update_post_meta( $menu_item_db_id, '_menu_item_xfn', sanitize_html_class($args['menu-item-xfn']) );
// @todo: only save custom link urls.
update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) );
do_action('wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );
}
return $menu_item_db_id;
}
/** /**
* Returns all navigation menu objects. * Returns all navigation menu objects.
* *
@ -127,6 +280,43 @@ function wp_get_nav_menus() {
return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) ); return get_terms( 'nav_menu', array( 'hide_empty' => false, 'orderby' => 'id' ) );
} }
/**
* Sort menu items by the desired key.
*
* @since 3.0.0
* @access private
*
* @param object $a The first object to compare
* @param object $b The second object to compare
* @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.
*/
function _sort_nav_menu_items($a, $b) {
global $_menu_item_sort_prop;
if ( empty( $_menu_item_sort_prop ) ) {
return 0;
}
if ( isset( $a->$_menu_item_sort_prop ) && isset( $b->$_menu_item_sort_prop ) ) {
$_a = (int) $a->$_menu_item_sort_prop;
$_b = (int) $b->$_menu_item_sort_prop;
if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop ) {
return 0;
} elseif (
( $_a == $a->$_menu_item_sort_prop ) &&
( $_b == $b->$_menu_item_sort_prop )
) {
return $_a < $_b ? -1 : 1;
} else {
return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
}
} else {
return 0;
}
}
/** /**
* Returns all menu items of a navigation menu. * Returns all menu items of a navigation menu.
* *
@ -139,13 +329,13 @@ function wp_get_nav_menus() {
function wp_get_nav_menu_items( $menu, $args = array() ) { function wp_get_nav_menu_items( $menu, $args = array() ) {
$menu = wp_get_nav_menu_object( $menu ); $menu = wp_get_nav_menu_object( $menu );
if ( !$menu ) if ( ! $menu )
return false; return false;
$items = get_objects_in_term( $menu->term_id, 'nav_menu' ); $items = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( ! empty( $items ) ) { if ( ! empty( $items ) ) {
$defaults = array( 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order' ); $defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order' );
$args = wp_parse_args( $args, $defaults ); $args = wp_parse_args( $args, $defaults );
if ( count( $items ) > 1 ) if ( count( $items ) > 1 )
$args['include'] = implode( ',', $items ); $args['include'] = implode( ',', $items );
@ -155,50 +345,48 @@ function wp_get_nav_menu_items( $menu, $args = array() ) {
$items = get_posts( $args ); $items = get_posts( $args );
if ( ARRAY_A == $args['output'] ) { if ( ARRAY_A == $args['output'] ) {
$output = array(); $GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
foreach ( $items as $item ) { usort($items, '_sort_nav_menu_items');
$output[$item->$args['output_key']] = $item; $i = 1;
foreach( $items as $k => $item ) {
$items[$k]->$args['output_key'] = $i++;
} }
unset( $items );
ksort( $output );
return $output;
} }
} }
return $items; return $items;
} }
/** /**
* Retrieve the HTML list content for nav menu items. * Decorates a menu item object with the shared navigation menu item properties.
* *
* @uses Walker_Nav_Menu to create HTML list content. * Properties:
* @since 2.1.0 * - db_id: The DB ID of the this item as a nav_menu_item object, if it exists (0 if it doesn't exist).
* @see Walker::walk() for parameters and return description. * - object_id: The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.
*/ * - type: The family of objects originally represented, such as "post_type" or "taxonomy."
function walk_nav_menu_tree( $items, $depth, $r ) { * - object: The type of object originally represented, such as "category," "post", or "attachment."
$walker = ( empty($r->walker) ) ? new Walker_Nav_Menu : $r->walker; * - append: The singular label used to describe this type of menu item.
$args = array( $items, $depth, $r ); * - parent: The DB ID of the original object's parent object, if any (0 otherwise).
* - url: The URL to which this menu item points.
return call_user_func_array( array(&$walker, 'walk'), $args ); * - title: The title of this menu item.
} * - target: The target attribute of the link element for this menu item.
* - attr_title: The title attribute of the link element for this menu item.
/** * - classes: The class attribute value for the link element of this menu item.
* Adds all the navigation menu properties to the menu item. * - xfn: The XFN relationship expressed in the link of this menu item.
* - description: The description of this menu item.
* *
* @since 3.0.0 * @since 3.0.0
* *
* @param string $menu_item The menu item to modify * @param object $menu_item The menu item to modify.
* @param string $menu_item_type The menu item type (frontend, custom, post_type, taxonomy). * @return object $menu_item The menu item with standard menu item properties.
* @param string $menu_item_object Optional. The menu item object type (post type or taxonomy).
* @return object $menu_item The modified menu item.
*/ */
function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_object = '' ) { function wp_setup_nav_menu_item( $menu_item ) {
switch ( $menu_item_type ) { if ( isset( $menu_item->post_type ) ) {
case 'frontend': if ( 'nav_menu_item' == $menu_item->post_type ) {
$menu_item->db_id = (int) $menu_item->ID; $menu_item->db_id = (int) $menu_item->ID;
$menu_item->object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true ); $menu_item->object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true );
$menu_item->object = get_post_meta( $menu_item->ID, '_menu_item_object', true ); $menu_item->object = get_post_meta( $menu_item->ID, '_menu_item_object', true );
$menu_item->type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); $menu_item->type = get_post_meta( $menu_item->ID, '_menu_item_type', true );
if ( 'post_type' == $menu_item->type ) { if ( 'post_type' == $menu_item->type ) {
$object = get_post_type_object( $menu_item->object ); $object = get_post_type_object( $menu_item->object );
$menu_item->append = $object->singular_label; $menu_item->append = $object->singular_label;
@ -213,7 +401,7 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
$menu_item->append = __('Custom'); $menu_item->append = __('Custom');
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true ); $menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
} }
$menu_item->title = $menu_item->post_title; $menu_item->title = $menu_item->post_title;
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true ); $menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
@ -222,31 +410,12 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true ); $menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_classes', true );
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true ); $menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
break; } else {
case 'custom':
$menu_item->db_id = 0; $menu_item->db_id = 0;
$menu_item->object_id = (int) $menu_item->ID; $menu_item->object_id = (int) $menu_item->ID;
$menu_item->object = 'custom'; $menu_item->type = 'post_type';
$menu_item->type = 'custom';
$menu_item->append = __('custom');
$menu_item->attr_title = strip_tags( $menu_item->post_excerpt ); $object = get_post_type_object( $menu_item->post_type );
$menu_item->description = strip_tags( $menu_item->post_content );
$menu_item->title = $menu_item->post_title;
$menu_item->url = get_post_meta( $menu_item->ID, '_menu_item_url', true );
$menu_item->target = get_post_meta( $menu_item->ID, '_menu_item_target', true );
$menu_item->classes = get_post_meta( $menu_item->ID, '_menu_item_target', true );
$menu_item->xfn = get_post_meta( $menu_item->ID, '_menu_item_xfn', true );
break;
case 'post_type':
$menu_item->db_id = 0;
$menu_item->object_id = (int) $menu_item->ID;
$menu_item->type = $menu_item_type;
$object = get_post_type_object( $menu_item_object );
$menu_item->object = $object->name; $menu_item->object = $object->name;
$menu_item->append = strtolower( $object->singular_label ); $menu_item->append = strtolower( $object->singular_label );
@ -254,33 +423,32 @@ function wp_setup_nav_menu_item( $menu_item, $menu_item_type = null, $menu_item_
$menu_item->url = get_permalink( $menu_item->ID ); $menu_item->url = get_permalink( $menu_item->ID );
$menu_item->target = ''; $menu_item->target = '';
$menu_item->attr_title = ''; $menu_item->attr_title = strip_tags( $menu_item->post_excerpt );
$menu_item->description = strip_tags( $menu_item->post_content ); $menu_item->description = strip_tags( $menu_item->post_content );
$menu_item->classes = ''; $menu_item->classes = '';
$menu_item->xfn = ''; $menu_item->xfn = '';
break; }
} elseif ( isset( $menu_item->taxonomy ) ) {
$menu_item->ID = $menu_item->term_id;
$menu_item->db_id = 0;
$menu_item->object_id = (int) $menu_item->term_id;
$menu_item->post_parent = (int) $menu_item->parent;
$menu_item->type = 'taxonomy';
case 'taxonomy': $object = get_taxonomy( $menu_item->taxonomy );
$menu_item->ID = $menu_item->term_id; $menu_item->object = $object->name;
$menu_item->db_id = 0; $menu_item->append = strtolower( $object->singular_label );
$menu_item->object_id = (int) $menu_item->term_id;
$menu_item->post_parent = (int) $menu_item->parent;
$menu_item->type = $menu_item_type;
$object = get_taxonomy( $menu_item_object ); $menu_item->title = $menu_item->name;
$menu_item->object = $object->name; $menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy );
$menu_item->append = strtolower( $object->singular_label ); $menu_item->target = '';
$menu_item->attr_title = '';
$menu_item->description = strip_tags( get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy ) );
$menu_item->classes = '';
$menu_item->xfn = '';
$menu_item->title = $menu_item->name;
$menu_item->url = get_term_link( $menu_item, $menu_item_object );
$menu_item->target = '';
$menu_item->attr_title = '';
$menu_item->description = '';
$menu_item->classes = '';
$menu_item->xfn = '';
break;
} }
return apply_filters( 'wp_setup_nav_menu_item', $menu_item, $menu_item_type, $menu_item_object ); return apply_filters( 'wp_setup_nav_menu_item', $menu_item );
} }
?> ?>

View File

@ -2190,7 +2190,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
$data = stripslashes_deep( $data ); $data = stripslashes_deep( $data );
$where = array( 'ID' => $post_ID ); $where = array( 'ID' => $post_ID );
if ($update) { if ( $update ) {
do_action( 'pre_post_update', $post_ID ); do_action( 'pre_post_update', $post_ID );
if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) { if ( false === $wpdb->update( $wpdb->posts, $data, $where ) ) {
if ( $wp_error ) if ( $wp_error )
@ -2265,7 +2265,7 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
wp_transition_post_status($data['post_status'], $previous_status, $post); wp_transition_post_status($data['post_status'], $previous_status, $post);
if ( $update) if ( $update )
do_action('edit_post', $post_ID, $post); do_action('edit_post', $post_ID, $post);
do_action('save_post', $post_ID, $post); do_action('save_post', $post_ID, $post);

View File

@ -393,12 +393,13 @@ function wp_default_scripts( &$scripts ) {
) ); ) );
// Custom Navigation // Custom Navigation
$scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100403' ); $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", false, '20100426' );
$scripts->localize( 'nav-menu', 'navMenuL10n', array( $scripts->localize( 'nav-menu', 'navMenuL10n', array(
'custom' => _x('Custom', 'menu nav item type'), 'custom' => _x('Custom', 'menu nav item type'),
'thickbox' => _x('Edit Menu Item', 'Thickbox Title'), 'thickbox' => _x('Edit Menu Item', 'Thickbox Title'),
'edit' => _x('Edit', 'menu item edit text'), 'edit' => _x('Edit', 'menu item edit text'),
'warnDelete' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ), 'warnDeleteMenu' => __( "You are about to permanently delete this menu. \n 'Cancel' to stop, 'OK' to delete." ),
'warnDeleteMenuItem' => __( "You are about to permanently delete this menu item. \n 'Cancel' to stop, 'OK' to delete." ),
) ); ) );
$scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' ); $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array('farbtastic'), '20100321' );
@ -440,13 +441,13 @@ function wp_default_styles( &$styles ) {
// Any rtl stylesheets that don't have a .dev version for ltr // Any rtl stylesheets that don't have a .dev version for ltr
$no_suffix = array( 'farbtastic' ); $no_suffix = array( 'farbtastic' );
$styles->add( 'wp-admin', "/wp-admin/css/wp-admin$suffix.css", array(), '20100424' ); $styles->add( 'wp-admin', "/wp-admin/css/wp-admin$suffix.css", array(), '20100426' );
$styles->add( 'ie', "/wp-admin/css/ie$suffix.css", array(), '20100219' ); $styles->add( 'ie', "/wp-admin/css/ie$suffix.css", array(), '20100219' );
$styles->add_data( 'ie', 'conditional', 'lte IE 7' ); $styles->add_data( 'ie', 'conditional', 'lte IE 7' );
// all colors stylesheets need to have the same query strings (cache manifest compat) // all colors stylesheets need to have the same query strings (cache manifest compat)
$colors_version = '20100418'; $colors_version = '20100426';
// Register "meta" stylesheet for admin colors. All colors-* style sheets should have the same version string. // Register "meta" stylesheet for admin colors. All colors-* style sheets should have the same version string.
$styles->add( 'colors', true, array(), $colors_version ); $styles->add( 'colors', true, array(), $colors_version );
@ -472,7 +473,7 @@ function wp_default_styles( &$styles ) {
$styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' ); $styles->add( 'farbtastic', '/wp-admin/css/farbtastic.css', array(), '1.2' );
$styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' ); $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.css', array(), '0.9.8' );
$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' ); $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.1' );
$styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100322' ); $styles->add( 'nav-menu', "/wp-admin/css/nav-menu$suffix.css", array(), '20100426' );
foreach ( $rtl_styles as $rtl_style ) { foreach ( $rtl_styles as $rtl_style ) {
$styles->add_data( $rtl_style, 'rtl', true ); $styles->add_data( $rtl_style, 'rtl', true );