diff --git a/wp-admin/css/nav-menu.css b/wp-admin/css/nav-menu.css
index aad36daf4a..07c8034ac4 100644
--- a/wp-admin/css/nav-menu.css
+++ b/wp-admin/css/nav-menu.css
@@ -1 +1 @@
-#menu-management{clear:both;}#menu-management .inside{padding:0 10px;}#menu-container .submit{margin:0 0 10px;padding:0;}.submitdelete{color:#f00;text-decoration:underline;font-size:11px;float:left;margin-top:5px;}.submitdelete:hover{background-color:#F00;color:#fff;}.save{float:right;}.button-controls{float:left;}.add-to-menu{float:right;}#create-menu-name{width:159px;}#available-links{margin:15px 0 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-url,#menu-item-name{float:right;width:220px;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.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 .item-title{cursor:pointer;display:block;}.list li .item-title input{margin-right:3px;margin-top:-3px;}.list li ul li .item-title{margin-left:14px;}.list li ul li ul li .item-title{margin-left:28px;}.list li ul li ul li ul li .item-title{margin-left:42px;}.list li ul li ul li ul li ul li .item-title{margin-left:56px;}.list li ul li ul li ul li ul li ul li .item-title{margin-left:70px;}.list li ul li ul li ul li ul li ul li ul li .item-title{margin-left:84px;}.list li ul li ul li ul li ul li ul li ul li ul li .item-title{margin-left:98px;}.list li ul li ul li ul li ul li ul li ul li ul li ul li .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-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright: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 .item-title{background:url(../images/ico-arrow.png) no-repeat 4px 5px;background-position:center left;padding-left:15px;}.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-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;}.hide{display:none;}
\ No newline at end of file
+#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;}.button-controls{float:left;}.add-to-menu{float:right;}#manage-menu .inside{padding:0;}#create-menu-name{width:159px;}#available-links{margin:15px 0 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;}.show-all,.hide-all{cursor:pointer;}.hide-all{display:none;}.quick-search{width:190px;}.list-wrap{display:none;clear:both;}.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-bottom-left-radius:6px;-webkit-border-bottom-right-radius:6px;-webkit-border-top-left-radius:6px;-webkit-border-top-right-radius:6px;border-bottom-left-radius:6px;border-bottom-right-radius:6px;border-top-left-radius:6px;border-top-right-radius:6px;-moz-border-radius-bottomleft:6px;-moz-border-radius-bottomright:6px;-moz-border-radius-topleft:6px;-moz-border-radius-topright: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;}
\ No newline at end of file
diff --git a/wp-admin/css/nav-menu.dev.css b/wp-admin/css/nav-menu.dev.css
index bbe65082f2..923857d9f3 100644
--- a/wp-admin/css/nav-menu.dev.css
+++ b/wp-admin/css/nav-menu.dev.css
@@ -14,19 +14,16 @@
/* Button Primary Actions */
#menu-container .submit { margin: 0px 0px 10px; padding: 0px; }
-.submitdelete { color: #ff0000; text-decoration: underline; font-size: 11px; float: left; margin-top: 5px; }
-.submitdelete:hover { background-color: #FF0000; color: #fff; }
-.save { float: right; }
+
+.submitdelete { font-size: 11px; }
+#cancel-save { color: #ff0000; text-decoration: underline; font-size: 11px; margin-left: 20px; margin-top: 5px; }
+#cancel-save:hover { background-color: #FF0000; color: #fff; }
/* Button Secondary Actions */
.button-controls { float: left; }
.add-to-menu { float: right; }
-/* CSS for switching the main columns *//*
-#menu-settings-column { clear: none; float: left; }
-#menu-management #post-body { float: right; margin-left: -340px; margin-right: 0px; }
-#menu-management #post-body-content { margin-left: 300px; margin-right: 0px; }
-*/
+#manage-menu .inside { padding: 0px 0px; }
/* Create Menu */
#create-menu-name { width: 159px; }
@@ -36,7 +33,8 @@
#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-url, #menu-item-name { float: right; width: 220px; }
+.menu-item-textbox { float: right; width: 220px; }
+.howto span { margin-top: 4px; display: block; float: left; }
/* Pages/Categories */
.show-all, .hide-all { cursor: pointer; }
@@ -50,17 +48,17 @@
/* Listings */
.list li { display: none; margin: 0; margin-bottom: 5px; }
-.list li .item-title { cursor: pointer; display: block; }
-.list li .item-title input { margin-right: 3px; margin-top: -3px; }
+.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 .item-title { margin-left: 14px; }
-.list li ul li ul li .item-title { margin-left: 28px; }
-.list li ul li ul li ul li .item-title { margin-left: 42px; }
-.list li ul li ul li ul li ul li .item-title { margin-left: 56px; }
-.list li ul li ul li ul li ul li ul li .item-title { margin-left: 70px; }
-.list li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 84px; }
-.list li ul li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 98px; }
-.list li ul li ul li ul li ul li ul li ul li ul li ul li .item-title { margin-left: 112px; }
+.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 */
#menu-container .inside { padding-bottom: 10px; }
@@ -71,9 +69,9 @@
.menu li dl dt:hover { cursor: move; }
.menu li .item-title { }
-.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 { 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; }
/* Drag and Drop */
@@ -85,7 +83,7 @@
.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-delete:hover { color: #ff0000; }
+.item-controls .menu-item-delete:hover { color: #ff0000; }
/* Thickbox */
#menu-item-settings { display: none; }
@@ -94,7 +92,4 @@
#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; }
-
-/* Misc */
-.hide { display: none; }
\ No newline at end of file
+#update-menu-item:focus { color: #eaf2fa !important; border-color: #13455b !important; }
\ No newline at end of file
diff --git a/wp-admin/includes/nav-menu.php b/wp-admin/includes/nav-menu.php
index bacb534318..da5cf18e18 100644
--- a/wp-admin/includes/nav-menu.php
+++ b/wp-admin/includes/nav-menu.php
@@ -1,273 +1,383 @@
true ), 'object' );
- $args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
- $link_objects = new WP_Query( $args );
+ if ( !$post_types )
+ return false;
- $items_counter = $counter;
-
- if ( !$link_objects->posts ) {
- _e('Not Found');
- return $items_counter;
+ foreach ( $post_types as $post_type ) {
+ $id = sanitize_title_with_dashes( $post_type->label );
+
+ // delete_transient( "nav_menu_items_{$post_type->name}" );
+ // delete_transient( "nav_menu_sub_items_{$post_type->name}" );
+
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $post_type->singular_label ), 'wp_nav_menu_item_post_type_metabox', 'menus', 'side', 'default', $post_type );
}
-
- // Display Loop
- foreach ( $link_objects->posts as $item ) {
- if ( 0 == $item->parent ) {
- $item = wp_setup_nav_menu_item( $item, 'item', $items_counter );
-
- switch ( $context ) {
- case 'menu':
- ?>
-
-
-
- ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' );
- ?>
-
- 0,
- 'sort_order' => 'ASC',
- 'sort_column' => 'post_title',
- 'hierarchical' => 1,
- 'exclude' => '',
- 'include' => '',
- 'meta_key' => '',
- 'meta_value' => '',
- 'authors' => '',
- 'parent' => -1,
- 'exclude_tree' => '',
- 'number' => '',
- 'offset' => 0 );
-
- // Get all pages
- $pages_array = get_pages( $pages_args );
-
- $items_counter = $counter;
- $parentli = $items_counter;
-
- if ( !$pages_array ) {
- echo __('Not Found');
- return $items_counter;
+function wp_nav_menu_taxonomy_metaboxes() {
+ $taxonomies = get_taxonomies( array( 'show_ui' => true ), 'object' );
+
+ if ( !$taxonomies )
+ return false;
+
+ foreach ( $taxonomies as $tax ) {
+ $id = sanitize_title_with_dashes( $tax->label );
+
+ // delete_transient( "nav_menu_items_{$tax->name}" );
+ // delete_transient( "nav_menu_sub_items_{$tax->name}" );
+
+ add_meta_box( "add-{$id}", sprintf( __('Add an Existing %s'), $tax->singular_label ), 'wp_nav_menu_item_taxonomy_metabox', 'menus', 'side', 'default', $tax );
}
-
- // Display Loop
- foreach ( $pages_array as $post ) {
- if ( $post->post_parent == 0 ) {
- $post = wp_setup_nav_menu_item( $post, 'page', $items_counter );
- if ( $context == 'menu' ) {
- ?>
-
-
-
- ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' );
- ?>
-
- 'post',
- 'child_of' => 0,
- 'orderby' => 'name',
- 'order' => 'ASC',
- 'hide_empty' => false,
- 'include_last_update_time' => false,
- 'hierarchical' => 1,
- 'exclude' => '',
- 'include' => '',
- 'number' => '',
- 'pad_counts' => false );
+function wp_nav_menu_manage_menu_metabox( $object, $menu ) { ?>
+
+
+
+
- $items_counter = $counter;
-
- // Get all categories
- $categories_array = get_categories( $category_args );
-
- if ( !$categories_array ) {
- _e('Not Found');
- return $items_counter;
- }
-
- // Display Loop
- foreach ( $categories_array as $cat_item ) {
- if ( $cat_item->parent == 0 ) {
- $cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter );
- // Custom Menu
- if ( $context == 'menu' ) {
- ?>
-
-
-
- cat_ID;
- $items_counter++;
- $items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' );
- ?>
-
- $childof,
- 'hide_empty' => false,
- 'parent' => $childof);
- } elseif ( $output_type == 'default' ) {
- // Sidebar Menu
- $sub_args = array(
- 'child_of' => $childof,
- 'hide_empty' => false,
- 'parent' => $childof);
- }
-
- if ( $context == 'categories' ) {
- // Get Sub Category Items
- $item_type = 'category';
- $sub_array = get_categories($sub_args);
- } elseif ($context == 'pages') {
- // Get Sub Page Items
- $item_type = 'page';
- $sub_array = get_pages($sub_args);
- } else {
- $item_type = 'custom';
- $sub_array = array();
- }
-
- if ( $sub_array ) {
- ?>
-
+
+
+
+
+
+
+
+
+
+
+ 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
+
+ // Cache the query for a day. @todo: Make sure to flush transient when links are updated.
+ $query = get_transient( 'menu_item_query_custom_links' );
+ if ( false == $query ) {
+ $query = new WP_Query( $args );
+ set_transient( 'menu_item_query_custom_links', $query, 86400 );
}
- return $counter;
+
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+ posts, 'custom' ); ?>
+
+
+
+
+
+ $post_type['args']->name, );
+
+ if ( 'attachment' == $post_type['args']->name )
+ $args['post_status'] = 'any';
+
+ // Cache the query for a day. @todo: Make sure to flush transient when objects are updated.
+ $query = get_transient( "nav_menu_items_{$post_type['args']->name}" );
+ if ( false == $query ) {
+ $query = new WP_Query( $args );
+ set_transient( "nav_menu_items_{$post_type['args']->name}", $query, 86400 );
+ }
+
+ if ( !$query->posts )
+ $error = ''. sprintf( __( 'No %s exists' ), $post_type['args']->label ) .' ';
+
+ $pt_names = '';
+ if ( is_array($query->posts) ) {
+ foreach ( $query->posts as $post ) {
+ if ( $post->post_title ) {
+ $pt_names .= htmlentities( $post->post_title ) .'|';
+ } else {
+ $pt_names = sprintf( __('No %s exists'), $post_type['args']->label );
+ }
+ }
+ }
+
+ $id = sanitize_title_with_dashes( $post_type['args']->label );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ posts, 'post_type', $post_type['args']->name ); ?>
+
+
+
+
+
+
+
+ 0, 'orderby' => 'name', 'order' => 'ASC',
+ 'hide_empty' => false, 'include_last_update_time' => false, 'hierarchical' => 1, 'exclude' => '',
+ 'include' => '', 'number' => '', 'pad_counts' => false
+ );
+
+ // Cache the query for a day. @todo: Make sure to flush transient when terms are updated.
+ $terms = get_transient( "nav_menu_items_{$taxonomy['args']->name}" );
+ if ( false == $terms ) {
+ $terms = get_terms( $taxonomy['args']->name, $args );
+ set_transient( "nav_menu_items_{$taxonomy['args']->name}", $terms, 86400 );
+ }
+
+ if ( !$terms )
+ $error = ''. sprintf( __( 'No %s exists' ), $taxonomy['args']->label ) .' ';
+
+ $term_names = '';
+ if ( is_array($terms) ) {
+ foreach ( $terms as $term ) {
+ if ( $term->name ) {
+ $term_names .= htmlentities( $term->name ) .'|';
+ } else {
+ $term_names = sprintf( __('No %s exists'), $taxonomy['args']->label );
+ }
+ }
+ }
+
+ $id = sanitize_title_with_dashes( $taxonomy['args']->label );
+ ?>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ post_parent) )
+ $menu_item->post_parent = $menu_item->parent;
+
+ // Cleanest way to get all attachements
+ if ( 'attachment' == $object )
+ $menu_item->post_parent = 0;
+
+ if ( 0 == $menu_item->post_parent ) {
+ // Setup the menu item
+ $menu_item = wp_setup_nav_menu_item( $menu_item, $object_type, $object );
+ $attributes = ( 'backend' == $context ) ? ' id="menu-item-'. $i .'" value="'. $i .'"' : '';
+
+ $output .= '';
+ $output .= wp_get_nav_menu_item( $menu_item, $object_type, $object );
+ $output .= wp_get_nav_menu_sub_items( $menu_item->ID, $object_type, $object, $context );
+ $output .= ' ';
+
+ ++$i;
+ }
+ }
+
+ return $output;
+}
+
+/**
+ * Recursive function to retrieve sub menu items.
+ *
+ * @since 3.0.0
+ *
+ * @param string $childof The Parent ID.
+ * @param string $object_type The object type.
+ * @param string $object The object name.
+ * @return string $output sub menu items.
+ */
+function wp_get_nav_menu_sub_items( $childof, $object_type, $object = null, $context = 'frontend' ) {
+ $args = array( 'child_of' => $childof, 'parent' => $childof, 'hide_empty' => false, );
+
+ switch ( $object_type ) {
+ case 'post_type':
+ $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
+ if ( in_array( $object, $hierarchical_post_types ) ) {
+ $args['post_type'] = $object;
+ $sub_menu_items = get_pages( $args );
+ } else {
+ $sub_menu_items = array();
+ }
+ break;
+
+ case 'taxonomy':
+ if ( is_taxonomy_hierarchical( $object ) ) {
+ $sub_menu_items = get_terms( $object, $args );
+ } else {
+ $sub_menu_items = array();
+ }
+ break;
+
+ default:
+ $sub_menu_items = array();
+ break;
+ }
+
+ $output = '';
+ $i = 1;
+ if ( !empty($sub_menu_items) && !is_wp_error($sub_menu_items) ) {
+ $output .= '';
+ }
+ return $output;
}
?>
\ No newline at end of file
diff --git a/wp-admin/js/nav-menu-default-items.dev.js b/wp-admin/js/nav-menu-default-items.dev.js
index 0eb6b8a5c0..4112aa54d6 100644
--- a/wp-admin/js/nav-menu-default-items.dev.js
+++ b/wp-admin/js/nav-menu-default-items.dev.js
@@ -15,13 +15,26 @@ jQuery(document).ready(function($){
wp_drag_and_drop();
- wp_update_post_data();
+ // Delete AYS
+ $('#update-nav-menu .deletion').click(function(){
+ if ( confirm( navMenuL10n.warnDelete ) ) {
+ return true;
+ } else {
+ return false;
+ };
+ });
// Handle Save Button Clicks
$('#save_menu').click(function(){
return wp_update_post_data();
});
-
+
+ // close postboxes that should be closed
+ $('.if-js-closed').removeClass('if-js-closed').addClass('closed');
+
+ // postboxes setup
+ postboxes.add_postbox_toggles('menus');
+
// Clear the quick search textbox
$('.quick-search').click(function(){
$(this).attr( 'value', '' );
@@ -38,18 +51,14 @@ jQuery(document).ready(function($){
});
// Delete menu item
- $('#menu-container .item-delete').live( 'click', function(){
+ $('#menu-container .item-delete').live( 'click', function(e){
return wp_remove_menu_item( $(this).attr('value') );
});
// Update menu item settings (thickbox)
$('#update-menu-item').click(function(){
wp_update_menu_item();
- tb_remove();
-
- // Give feedback to the user
- var id = $('#edit-item-id').val();
- $('#menu-' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
+ return tb_remove();
});
// Close thickbox
@@ -58,55 +67,32 @@ jQuery(document).ready(function($){
});
// Show All Button
- $('.show-all').click(function(){
- $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 10px;' );
- $(this).offsetParent().find('.list-wrap').css( 'display','block' );
- $(this).siblings('.quick-search').attr( 'value', '' );
- $(this).offsetParent().find('.list-wrap li').css( 'display', 'block' );
- $(this).hide();
- $(this).siblings('.hide-all').show();
+ $('.show-all').click(function(e){
+ jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'block' );
+ jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'block' );
+ jQuery(e.currentTarget).hide();
+ jQuery(e.currentTarget).siblings('.hide-all').show();
});
// Hide All Button
- $('.hide-all').click(function(){
- $(this).offsetParent().find('#add-buttons-actions').attr( 'style','margin-bottom: 0px;' );
- $(this).offsetParent().find('.list-wrap').css( 'display','none' );
- $(this).siblings('.quick-search').attr( 'value', 'Search' );
- $(this).offsetParent().find('.list-wrap li').css( 'display', 'none' );
- $(this).hide();
- $(this).siblings('.show-all').show();
+ $('.hide-all').click(function(e){
+ jQuery(e.currentTarget).parent().siblings('.list-wrap').css( 'display', 'none' );
+ jQuery(e.currentTarget).parent().siblings('.list-wrap').find('li').css( 'display', 'none' );
+ jQuery(e.currentTarget).hide();
+ jQuery(e.currentTarget).siblings('.show-all').show();
});
- // Add menu item to queue
- $('.list input').click(function(){
+ // Add menu items into the menu
+ $('.add-to-menu').click(function(e){
+ return wp_add_checked_items_to_menu(e.currentTarget);
+ });
- var item_type = jQuery(this).parent().siblings('.item-type').val();
- var item_title = jQuery(this).parent().siblings('.item-title').val();
- var item_url = jQuery(this).parent().siblings('.item-url').val();
- var item_id = jQuery(this).parent().siblings('.item-dbid').val();
- var item_parent_id = jQuery(this).parent().siblings('.item-parent').val();
- var item_description = jQuery(this).parent().siblings('.item-description').val();
+ // Create a new link then add it to the menu
+ $('#add-custom-links .add-to-menu a').click(function(e){
+ var link_url = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-url').val();
+ var link_name = jQuery(e.currentTarget).parent().parent().find('#custom-menu-item-name').val();
- return wp_update_queue( $(this), item_type, item_title, item_url, item_id, item_parent_id, item_description );
- });
-
- // Add queued menu items into the menu
- $('.enqueue a').click(function(){
- return wp_add_queued_items_to_menu(this);
- });
-
- // Create the link, add it to the menu + available links section
- $('#add-custom-link .add-to-menu a').click(function(){
- var link_url = $(this).offsetParent().find('#menu-item-url').val();
- var link_name = $(this).offsetParent().find('#menu-item-name').val();
-
- wp_add_queued_items_to_menu( this );
-
- // Don't save the link if it was left with it's default settings
- if ( 'http://' == link_url || 'Menu Item' == link_name )
- return;
-
- // and update the Menu with the new link
- wp_add_item_to_menu( 'custom', link_name, link_url, 0, 0, '' );
+ // Add link to menu
+ wp_add_item_to_menu( 0, '', 'custom', navMenuL10n.custom, 0, link_name, link_url, '', '', '_none', '', '' );
});
});
\ No newline at end of file
diff --git a/wp-admin/js/nav-menu-default-items.js b/wp-admin/js/nav-menu-default-items.js
index 32a2324fe6..329e6b8c88 100644
--- a/wp-admin/js/nav-menu-default-items.js
+++ b/wp-admin/js/nav-menu-default-items.js
@@ -1 +1 @@
-jQuery(document).ready(function(a){wp_drag_and_drop();wp_update_post_data();a("#save_menu").click(function(){return wp_update_post_data()});a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();tb_remove();var b=a("#edit-item-id").val();a("#menu-"+b+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 10px;");a(this).offsetParent().find(".list-wrap").css("display","block");a(this).siblings(".quick-search").attr("value","");a(this).offsetParent().find(".list-wrap li").css("display","block");a(this).hide();a(this).siblings(".hide-all").show()});a(".hide-all").click(function(){a(this).offsetParent().find("#add-buttons-actions").attr("style","margin-bottom: 0px;");a(this).offsetParent().find(".list-wrap").css("display","none");a(this).siblings(".quick-search").attr("value","Search");a(this).offsetParent().find(".list-wrap li").css("display","none");a(this).hide();a(this).siblings(".show-all").show()});a(".list input").click(function(){var d=jQuery(this).parent().siblings(".item-type").val();var g=jQuery(this).parent().siblings(".item-title").val();var c=jQuery(this).parent().siblings(".item-url").val();var e=jQuery(this).parent().siblings(".item-dbid").val();var b=jQuery(this).parent().siblings(".item-parent").val();var f=jQuery(this).parent().siblings(".item-description").val();return wp_update_queue(a(this),d,g,c,e,b,f)});a(".enqueue a").click(function(){return wp_add_queued_items_to_menu(this)});a("#add-custom-link .add-to-menu a").click(function(){var b=a(this).offsetParent().find("#menu-item-url").val();var c=a(this).offsetParent().find("#menu-item-name").val();wp_add_queued_items_to_menu(this);if("http://"==b||"Menu Item"==c){return}wp_add_item_to_menu("custom",c,b,0,0,"")})});
\ No newline at end of file
+jQuery(document).ready(function(a){wp_drag_and_drop();a("#update-nav-menu .deletion").click(function(){if(confirm(navMenuL10n.warnDelete)){return true}else{return false}});a("#save_menu").click(function(){return wp_update_post_data()});a(".if-js-closed").removeClass("if-js-closed").addClass("closed");postboxes.add_postbox_toggles("menus");a(".quick-search").click(function(){a(this).attr("value","")});a(".quick-search-submit").click(function(){a(this).siblings(".quick-search").search()});a("#menu-container .item-edit").click(function(){return wp_edit_menu_item(a(this).attr("value"))});a("#menu-container .item-delete").live("click",function(b){return wp_remove_menu_item(a(this).attr("value"))});a("#update-menu-item").click(function(){wp_update_menu_item();return tb_remove()});a("#cancel-save").click(function(){return tb_remove()});a(".show-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","block");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","block");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".hide-all").show()});a(".hide-all").click(function(b){jQuery(b.currentTarget).parent().siblings(".list-wrap").css("display","none");jQuery(b.currentTarget).parent().siblings(".list-wrap").find("li").css("display","none");jQuery(b.currentTarget).hide();jQuery(b.currentTarget).siblings(".show-all").show()});a(".add-to-menu").click(function(b){return wp_add_checked_items_to_menu(b.currentTarget)});a("#add-custom-links .add-to-menu a").click(function(d){var b=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-url").val();var c=jQuery(d.currentTarget).parent().parent().find("#custom-menu-item-name").val();wp_add_item_to_menu(0,"","custom",navMenuL10n.custom,0,c,b,"","","_none","","")})});
\ No newline at end of file
diff --git a/wp-admin/js/nav-menu-dynamic-functions.dev.js b/wp-admin/js/nav-menu-dynamic-functions.dev.js
index 7098ada94b..34a8c466aa 100644
--- a/wp-admin/js/nav-menu-dynamic-functions.dev.js
+++ b/wp-admin/js/nav-menu-dynamic-functions.dev.js
@@ -8,66 +8,75 @@
* @subpackage Administration
*/
-/**
- * Adds a link to the available links section
- *
- * @param object e - An object recieved via ajax
- */
-function wp_update_links_list(e) {
- var link = ' '+ e.link_name +' ';
-
- // Prepend the link to the available links section
- jQuery('#available-links .list').prepend( link );
-
- // Give feedback to the user
- jQuery('#available-links .list #link-' + e.link_id).parent().animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
+function wp_nav_menu_autocomplete( id ) {
+ jQuery('#add-'+ id +' .quick-search').autocomplete(jQuery( '#add-'+ id +' .autocomplete' ).val().split('|'));
+
+ jQuery('#add-'+ id +' .quick-search').result(function(event, data, formatted) {
+ jQuery('#add-'+ id +' .list-wrap').css( 'display', 'block' );
+ jQuery("#add-"+ id +" .list-wrap li:contains('" + data + "')").css( 'display', 'block' );
+ jQuery('#add-'+ id +' .show-all').hide();
+ jQuery('#add-'+ id +' .hide-all').show();
+ });
}
/**
* Populate the thickbox window with the selected menu items
*
- * @param int o - the id of the menu li to edit.
+ * @param int id - the id of the menu li to edit.
*/
function wp_edit_menu_item( id ) {
- var itemType = jQuery('#item-type' + id).val();
- var itemTitle = jQuery('#item-title' + id).val();
- var itemURL = jQuery('#item-url' + id).val();
- var itemAttrTitle = jQuery('#item-attr-title' + id).val();
- var itemTarget = jQuery('#item-target' + id).val();
- var itemDesc = jQuery('#item-description' + id).val();
+ var item_type = jQuery('#menu-item-type' + id).val();
+ var item_title = jQuery('#menu-item-title' + id).val();
+ var item_link = jQuery('#menu-item-url' + id).val();
+ var item_attr_title = jQuery('#menu-item-attr-title' + id).val();
+ var item_target = jQuery('#menu-item-target' + id).val();
+ var item_description = jQuery('#menu-item-description' + id).val();
+ var item_classes = jQuery('#menu-item-classes' + id).val();
+ var item_xfn = jQuery('#menu-item-xfn' + id).val();
- // Disable the ability to edit the url for page and category items
- if ( 'page' == itemType || 'category' == itemType )
- jQuery( '#edit-item-url' ).attr('disabled', 'disabled' );
+ // Only allow custom links to be editable.
+ if ( 'custom' != item_type )
+ jQuery( '#edit-menu-item-url' ).attr('disabled', 'disabled' );
// Populate the fields for thickbox
- jQuery( '#edit-item-id' ).val(id);
- jQuery( '#edit-item-title' ).val(itemTitle);
- jQuery( '#edit-item-url' ).val(itemURL);
- jQuery( '#edit-item-attr-title' ).val(itemAttrTitle);
- jQuery( '#edit-item-target' ).val(itemTarget);
- jQuery( "#edit-item-target option[value='" + itemTarget + "']" ).attr('selected', 'selected');
- jQuery( '#edit-item-description' ).val(itemDesc);
+ jQuery( '#edit-menu-item-id' ).val(id);
+ jQuery( '#edit-menu-item-title' ).val(item_title);
+ jQuery( '#edit-menu-item-url' ).val(item_link);
+ jQuery( '#edit-menu-item-attr-title' ).val(item_attr_title);
+ jQuery( '#edit-menu-item-target' ).val(item_target);
+ jQuery( "#edit-menu-item-target option[value='" + item_target + "']" ).attr('selected', 'selected');
+ jQuery( '#edit-menu-item-description' ).val(item_description);
+ jQuery( '#edit-menu-item-classes' ).val(item_classes);
+ jQuery( '#edit-menu-item-xfn' ).val(item_xfn);
+
+ // focus
+ jQuery( '#edit-menu-item-title' ).focus();
};
/**
* Update the values for the menu item being editing
*/
function wp_update_menu_item() {
- var id = jQuery('#edit-item-id').val();
- var itemTitle = jQuery('#edit-item-title').val();
- var itemURL = jQuery('#edit-item-url').val();
- var itemAttrTitle = jQuery('#edit-item-attr-title').val();
- var itemTarget = jQuery('#edit-item-target').val();
- var itemDesc = jQuery('#edit-item-description').val();
+ var id = jQuery('#edit-menu-item-id').val();
+ var item_title = jQuery('#edit-menu-item-title').val();
+ var item_link = jQuery('#edit-menu-item-url').val();
+ var item_attr_title = jQuery('#edit-menu-item-attr-title').val();
+ var item_target = jQuery('#edit-menu-item-target').val();
+ var item_description = jQuery('#edit-menu-item-description').val();
+ var item_classes = jQuery('#edit-menu-item-classes').val();
+ var item_xfn = jQuery('#edit-menu-item-xfn').val();
- // update menu item settings
- jQuery('#menu-' + id).find('.item-title:first').html(itemTitle);
- jQuery('#item-title' + id).val(itemTitle);
- jQuery('#item-url' + id).val(itemURL);
- jQuery('#item-attr-title' + id).val(itemAttrTitle);
- jQuery('#item-target' + id).val(itemTarget);
- jQuery('#item-description' + id).val(itemDesc);
+ // update menu item settings
+ jQuery('.menu #menu-item' + id).find('span.item-title').html(item_title);
+ jQuery('.menu #menu-item-title' + id).val(item_title);
+ jQuery('.menu #menu-item-url' + id).val(item_link);
+ jQuery('.menu #menu-item-attr-title' + id).val(item_attr_title);
+ jQuery('.menu #menu-item-target' + id).val(item_target);
+ jQuery('.menu #menu-item-description' + id).val(item_description);
+ jQuery('.menu #menu-item-classes' + id).val(item_classes);
+ jQuery('.menu #menu-item-xfn' + id).val(item_xfn);
+
+ jQuery('.menu #menu-item' + id + ' dt:first').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
}
/**
@@ -76,166 +85,100 @@ function wp_update_menu_item() {
* @param int o - the id of the menu li to remove.
*/
function wp_remove_menu_item( o ) {
- var todelete = document.getElementById('menu-' + o);
+ var todelete = document.getElementById('menu-item' + o);
if ( todelete ) {
// Give some feedback to the user
jQuery( todelete ).find('dt').each(function(){
jQuery(this).animate( { backgroundColor: '#FF3333' }, { duration: 'normal', complete: function() { jQuery(this).parent().parent().remove() } } );
});
-
- wp_update_post_data();
}
};
-/**
- * Prepares menu items for POST
- */
-function wp_update_post_data() {
- var i = 0;
-
- jQuery('.menu li').each(function(i) {
- i = i + 1;
- var j = jQuery(this).attr('value');
-
- jQuery(this).find('#item-position' + j).attr('value', i);
- jQuery(this).attr('id','menu-' + i);
- jQuery(this).attr('value', i);
-
- jQuery(this).find('#item-dbid' + j).attr('name','item-dbid' + i);
- jQuery(this).find('#item-dbid' + j).attr('id','item-dbid' + i);
-
- jQuery(this).find('#item-postmenu' + j).attr('name','item-postmenu' + i);
- jQuery(this).find('#item-postmenu' + j).attr('id','item-postmenu' + i);
-
- var p = jQuery(this).find('#item-parent' + j).parent().parent().parent().attr('value');
-
- jQuery(this).find('#item-parent' + j).attr('name','item-parent' + i);
- jQuery(this).find('#item-parent' + j).attr('id','item-parent' + i);
-
- if (p) {
- // Do nothing
- } else {
- // reset p to be top level
- p = 0;
- }
-
- jQuery(this).find('#item-parent' + j).attr('value', p);
-
- jQuery(this).find('#item-title' + j).attr('name','item-title' + i);
- jQuery(this).find('#item-title' + j).attr('id','item-title' + i);
-
- jQuery(this).find('#item-url' + j).attr('name','item-url' + i);
- jQuery(this).find('#item-url' + j).attr('id','item-url' + i);
-
- jQuery(this).find('#item-description' + j).attr('name','item-description' + i);
- jQuery(this).find('#item-description' + j).attr('id','item-description' + i);
-
- jQuery(this).find('#item-attr-title' + j).attr('name','item-attr-title' + i);
- jQuery(this).find('#item-attr-title' + j).attr('id','item-attr-title' + i);
-
- jQuery(this).find('#item-target' + j).attr('name','item-target' + i);
- jQuery(this).find('#item-target' + j).attr('id','item-target' + i);
-
- jQuery(this).find('#item-position' + j).attr('name', 'item-position' + i);
- jQuery(this).find('#item-position' + j).attr('id', 'item-position' + i);
-
- jQuery(this).find('#item-type' + j).attr('name', 'item-type' + i);
- jQuery(this).find('#item-type' + j).attr('id', 'item-type' + i);
-
- jQuery('#li-count').attr( 'value', i );
- });
-};
-
/**
* Adds the item to the menu
*
- * @param string id - The menu item's id
- * @param string additemtype - Page, Category, or Custom.
- * @param string itemtext - menu text.
- * @param string itemurl - url of the menu.
- * @param int itemid - menu id.
- * @param int itemparentid - default 0.
- * @param string itemdescription - the description of the menu item.
+ * @param string item_db_id - The menu item's db id.
+ * @param string item_object_id - The menu item's object id.
+ * @param string item_type - The menu item's object type.
+ * @param string item_append - The menu item's nice name.
+ * @param string item_parent_id - The menu item's parent id.
+ * @param string item_title - The menu item title.
+ * @param string item_url - The menu item url
+ * @param string item_description - The menu item description.
+ * @param string item_attr_title - The title attribute.
+ * @param string item_target - The target attribute.
+ * @param string item_classes - Optional. Additional CSS classes for the menu item
+ * @param string item_xfn - Optional. The rel attribute.
*/
-function wp_add_item_to_menu( item_type, item_title, item_url, item_id, item_parent_id, item_description ) {
+function wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
var randomnumber = wp_get_unique_menu_id();
+ var hidden = wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
// Adds the item in the queue
- jQuery('.menu').append('
' + item_title + ' ' + item_type + ' ' + navMenuL10n.edit + ' | Delete ');
+ jQuery('.menu').append('
' + item_title + ' ' + item_append + ' ' + navMenuL10n.edit + ' | Delete ' + hidden + ' ');
// Give some feedback to the user
- jQuery( '.menu #menu-' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
+ jQuery( '.menu #menu-item' + randomnumber + ' dt:first' ).animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
// Enable drag-n-drop
wp_drag_and_drop();
- wp_update_post_data();
-
// Reload thickbox
tb_init('a.thickbox, area.thickbox, input.thickbox');
};
-/*
- * Queues items in perperation for appendToList
- *
- * @param string type - Page, Category, or Custom.
- * @param string link - menu text.
- * @param string url - url of the menu.
- * @param int id - menu id.
- * @param int parent_id - default 0.
- * @param string description - the description of the menu item.
-*/
-function wp_update_queue( e, item_type, item_title, item_url, item_id, item_parent_id, item_description ) {
- var randomnumber = wp_get_unique_menu_id();
- var menu_item_id = jQuery(e).attr('id');
-
- if ( jQuery(e).attr('checked') ) {
- // Add menu item to the queue
- jQuery('#queue').append('
' + item_title + ' ' + item_type + ' ' + navMenuL10n.edit + ' | Delete ');
-
- } else {
- // Remove the item from the queue
- if ( menu_item_id == jQuery('#queue li input[name^="item-id"]' ).val() ) {
- jQuery('#queue li input[name^="item-id"]' ).parent().remove()
- };
- };
-};
-
/**
* Grabs items from the queue and adds them to the menu.
*
- * @param string button - a reference of the button that was clicked
+ * @param string button - a reference to the button that was clicked
*/
-function wp_add_queued_items_to_menu( button ) {
- // Grab items in queue
- var items = jQuery('#queue').children();
+function wp_add_checked_items_to_menu( button ) {
+ // Grab checked items
+ var items = jQuery(button).siblings('.list-wrap').find(':checked');
- // Empty Queue
- jQuery('#queue').empty();
-
- // Appends HTML to the menu
- jQuery('.menu').append( items );
-
- // Give some feedback to the user
+ // If nothing was checked, cancel
+ if ( 0 == items.length )
+ return false;
+
+ // Loop through each item, grab it's hidden data and add it to the menu.
jQuery(items).each(function(){
- jQuery(this).find('dt').animate( { backgroundColor: '#FFFF33' }, { duration: 'normal', complete: function() { jQuery(this).css( 'backgroundColor', '' ); }});
+ var item_type = jQuery(this).parent().siblings('.menu-item-type').val();
+
+ if ( 'custom' == item_type ) {
+ var item_attr_title = jQuery(this).parent().siblings('.menu-item-attr-title').val();
+ var item_target = jQuery(this).parent().siblings('.menu-item-target').val();
+ var item_classes = jQuery(this).parent().siblings('.menu-item-classes').val();
+ var item_xfn = jQuery(this).parent().siblings('.menu-item-xfn').val();
+ } else {
+ var item_attr_title = '';
+ var item_target = '_none';
+ var item_classes = '';
+ var item_xfn = '';
+ };
+
+ var item_db_id = jQuery(this).parent().siblings('.menu-item-db-id').val();
+ var item_object_id = jQuery(this).parent().siblings('.menu-item-object-id').val();
+ var item_append = jQuery(this).parent().siblings('.menu-item-append').val();
+ var item_parent_id = jQuery(this).parent().siblings('.menu-item-parent-id').val();
+ var item_title = jQuery(this).parent().siblings('.menu-item-title').val();
+ var item_url = jQuery(this).parent().siblings('.menu-item-url').val();
+ var item_description = jQuery(this).parent().siblings('.menu-item-description').val();
+
+ if ( undefined == item_description ) {
+ item_description = '';
+ };
+
+ // Add the menu item to the menu
+ wp_add_item_to_menu( item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn );
+
+ // uncheck the menu item in the list
+ jQuery(this).attr( 'checked', false );
});
-
- // Uncheck the checkboxes in the list
- jQuery(button).offsetParent().find('.list-container input').attr('checked', false);
-
- wp_update_post_data();
-
- // Enable drag-n-drop
- wp_drag_and_drop();
-
- // Reload thickbox
- tb_init('a.thickbox, area.thickbox, input.thickbox');
};
/**
- * Allow the items in the Menu to be dragged and dropped.
+ * Makes the menu items drag and droppable.
*/
function wp_drag_and_drop() {
// Make sure all li's have dropzones
@@ -251,7 +194,7 @@ function wp_drag_and_drop() {
opacity: .8,
addClasses: false,
helper: 'clone',
- zIndex: 100,
+ zIndex: 100
});
// make menu item droppable
@@ -306,6 +249,49 @@ function wp_drag_and_drop() {
);
}
+/**
+ * Prepares menu items for POST.
+ */
+function wp_update_post_data() {
+ var i = 0;
+
+ jQuery('.menu li').each(function(i) {
+ i = i + 1;
+ var j = jQuery(this).attr('value');
+
+ jQuery(this).find('#menu-item-position' + j).attr('value', i);
+ jQuery(this).attr('id','menu-item' + i);
+ jQuery(this).attr('value', i);
+
+ jQuery(this).find('#menu-item-db-id' + j).attr('id','menu-item-db-id' + i);
+ jQuery(this).find('#menu-item-object-id' + j).attr('id','menu-item-object-id' + i);
+ jQuery(this).find('#menu-item-append' + j).attr('id', 'menu-item-append' + i);
+ jQuery(this).find('#menu-item-type' + j).attr('id', 'menu-item-type' + i);
+ jQuery(this).find('#menu-item-position' + j).attr('id', 'menu-item-position' + i);
+
+ var p = jQuery(this).find('#menu-item-parent-id' + j).parent().parent().parent().attr('value');
+ jQuery(this).find('#menu-item-parent-id' + j).attr('id','menu-item-parent-id' + i);
+ if (p) {
+ // Do nothing
+ } else {
+ // reset p to be top level
+ p = 0;
+ }
+ jQuery(this).find('#menu-item-parent-id' + j).attr('value', p);
+
+ jQuery(this).find('#menu-item-title' + j).attr('id','menu-item-title' + i);
+ jQuery(this).find('#menu-item-url' + j).attr('id','menu-item-url' + i);
+ jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
+ jQuery(this).find('#menu-item-classes' + j).attr('id','menu-item-classes' + i);
+ jQuery(this).find('#menu-item-xfn' + j).attr('id','menu-item-xfn' + i);
+ jQuery(this).find('#menu-item-description' + j).attr('id','menu-item-description' + i);
+ jQuery(this).find('#menu-item-attr-title' + j).attr('id','menu-item-attr-title' + i);
+ jQuery(this).find('#menu-item-target' + j).attr('id','menu-item-target' + i);
+
+ jQuery('#li-count').attr( 'value', i );
+ });
+};
+
/**
* Gets a unique number based on how many items are in the menu
*/
@@ -331,4 +317,40 @@ function wp_get_unique_menu_id() {
}
}
return randomnumber;
+}
+
+/**
+ * Returns all the nessecary hidden inputs for each menu item.
+ *
+ * @param string item_db_id - The menu item's db id.
+ * @param string item_object_id - The menu item's object id.
+ * @param string item_type - The menu item's object type.
+ * @param string item_append - The menu item's nice name.
+ * @param string item_parent_id - The menu item's parent id.
+ * @param string item_title - The menu item title.
+ * @param string item_url - The menu item url
+ * @param string item_description - The menu item description.
+ * @param string item_attr_title - The title attribute.
+ * @param string item_target - The target attribute.
+ * @param string item_classes - Optional. Additional CSS classes for the menu item
+ * @param string item_xfn - Optional. The rel attribute.
+ */
+function wp_get_hidden_inputs( randomnumber, item_db_id, item_object_id, item_type, item_append, item_parent_id, item_title, item_url, item_description, item_attr_title, item_target, item_classes, item_xfn ) {
+ var hidden = '';
+
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+ hidden += ' ';
+
+ return hidden;
}
\ No newline at end of file
diff --git a/wp-admin/js/nav-menu-dynamic-functions.js b/wp-admin/js/nav-menu-dynamic-functions.js
index 45a420a8c1..fd6a4168b4 100644
--- a/wp-admin/js/nav-menu-dynamic-functions.js
+++ b/wp-admin/js/nav-menu-dynamic-functions.js
@@ -1 +1 @@
-function wp_update_links_list(e){var link=' '+e.link_name+" ";jQuery("#available-links .list").prepend(link);jQuery("#available-links .list #link-"+e.link_id).parent().animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_edit_menu_item(id){var itemType=jQuery("#item-type"+id).val();var itemTitle=jQuery("#item-title"+id).val();var itemURL=jQuery("#item-url"+id).val();var itemAttrTitle=jQuery("#item-attr-title"+id).val();var itemTarget=jQuery("#item-target"+id).val();var itemDesc=jQuery("#item-description"+id).val();if("page"==itemType||"category"==itemType){jQuery("#edit-item-url").attr("disabled","disabled")}jQuery("#edit-item-id").val(id);jQuery("#edit-item-title").val(itemTitle);jQuery("#edit-item-url").val(itemURL);jQuery("#edit-item-attr-title").val(itemAttrTitle);jQuery("#edit-item-target").val(itemTarget);jQuery("#edit-item-target option[value='"+itemTarget+"']").attr("selected","selected");jQuery("#edit-item-description").val(itemDesc)}function wp_update_menu_item(){var id=jQuery("#edit-item-id").val();var itemTitle=jQuery("#edit-item-title").val();var itemURL=jQuery("#edit-item-url").val();var itemAttrTitle=jQuery("#edit-item-attr-title").val();var itemTarget=jQuery("#edit-item-target").val();var itemDesc=jQuery("#edit-item-description").val();jQuery("#menu-"+id).find(".item-title:first").html(itemTitle);jQuery("#item-title"+id).val(itemTitle);jQuery("#item-url"+id).val(itemURL);jQuery("#item-attr-title"+id).val(itemAttrTitle);jQuery("#item-target"+id).val(itemTarget);jQuery("#item-description"+id).val(itemDesc)}function wp_remove_menu_item(o){var todelete=document.getElementById("menu-"+o);if(todelete){jQuery(todelete).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})});wp_update_post_data()}}function wp_update_post_data(){var i=0;jQuery(".menu li").each(function(i){i=i+1;var j=jQuery(this).attr("value");jQuery(this).find("#item-position"+j).attr("value",i);jQuery(this).attr("id","menu-"+i);jQuery(this).attr("value",i);jQuery(this).find("#item-dbid"+j).attr("name","item-dbid"+i);jQuery(this).find("#item-dbid"+j).attr("id","item-dbid"+i);jQuery(this).find("#item-postmenu"+j).attr("name","item-postmenu"+i);jQuery(this).find("#item-postmenu"+j).attr("id","item-postmenu"+i);var p=jQuery(this).find("#item-parent"+j).parent().parent().parent().attr("value");jQuery(this).find("#item-parent"+j).attr("name","item-parent"+i);jQuery(this).find("#item-parent"+j).attr("id","item-parent"+i);if(p){}else{p=0}jQuery(this).find("#item-parent"+j).attr("value",p);jQuery(this).find("#item-title"+j).attr("name","item-title"+i);jQuery(this).find("#item-title"+j).attr("id","item-title"+i);jQuery(this).find("#item-url"+j).attr("name","item-url"+i);jQuery(this).find("#item-url"+j).attr("id","item-url"+i);jQuery(this).find("#item-description"+j).attr("name","item-description"+i);jQuery(this).find("#item-description"+j).attr("id","item-description"+i);jQuery(this).find("#item-attr-title"+j).attr("name","item-attr-title"+i);jQuery(this).find("#item-attr-title"+j).attr("id","item-attr-title"+i);jQuery(this).find("#item-target"+j).attr("name","item-target"+i);jQuery(this).find("#item-target"+j).attr("id","item-target"+i);jQuery(this).find("#item-position"+j).attr("name","item-position"+i);jQuery(this).find("#item-position"+j).attr("id","item-position"+i);jQuery(this).find("#item-type"+j).attr("name","item-type"+i);jQuery(this).find("#item-type"+j).attr("id","item-type"+i);jQuery("#li-count").attr("value",i)})}function wp_add_item_to_menu(item_type,item_title,item_url,item_id,item_parent_id,item_description){var randomnumber=wp_get_unique_menu_id();jQuery(".menu").append('
'+item_title+' '+item_type+' '+navMenuL10n.edit+' | Delete ');jQuery(".menu #menu-"+randomnumber+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();wp_update_post_data();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_update_queue(e,item_type,item_title,item_url,item_id,item_parent_id,item_description){var randomnumber=wp_get_unique_menu_id();var menu_item_id=jQuery(e).attr("id");if(jQuery(e).attr("checked")){jQuery("#queue").append('
'+item_title+' '+item_type+' '+navMenuL10n.edit+' | Delete ')}else{if(menu_item_id==jQuery('#queue li input[name^="item-id"]').val()){jQuery('#queue li input[name^="item-id"]').parent().remove()}}}function wp_add_queued_items_to_menu(button){var items=jQuery("#queue").children();jQuery("#queue").empty();jQuery(".menu").append(items);jQuery(items).each(function(){jQuery(this).find("dt").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})});jQuery(button).offsetParent().find(".list-container input").attr("checked",false);wp_update_post_data();wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('
')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100,});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(e,ui){var li=jQuery(this).parent();var child=!jQuery(this).hasClass("dropzone");if(child&&li.children("ul").length==0){li.append('')}if(child){li.children("ul").append(ui.draggable)}else{li.before(ui.draggable)}li.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var draggablevalue=ui.draggable.attr("value");var droppablevalue=li.attr("value");li.find("#menu-"+draggablevalue).find("#parent"+draggablevalue).val(droppablevalue);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var parentid=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_get_unique_menu_id(){var count=jQuery(".menu li").length+1;var randomnumber=count;var validatetest=0;try{var test=document.getElementById("menu-"+randomnumber.toString()).value}catch(err){validatetest=1}while(validatetest==0){randomnumber=randomnumber+1;try{var test2=document.getElementById("menu-"+randomnumber.toString()).value}catch(err){validatetest=1}}return randomnumber};
\ No newline at end of file
+function wp_nav_menu_autocomplete(a){jQuery("#add-"+a+" .quick-search").autocomplete(jQuery("#add-"+a+" .autocomplete").val().split("|"));jQuery("#add-"+a+" .quick-search").result(function(b,d,c){jQuery("#add-"+a+" .list-wrap").css("display","block");jQuery("#add-"+a+" .list-wrap li:contains('"+d+"')").css("display","block");jQuery("#add-"+a+" .show-all").hide();jQuery("#add-"+a+" .hide-all").show()})}function wp_edit_menu_item(a){var f=jQuery("#menu-item-type"+a).val();var b=jQuery("#menu-item-title"+a).val();var g=jQuery("#menu-item-url"+a).val();var c=jQuery("#menu-item-attr-title"+a).val();var d=jQuery("#menu-item-target"+a).val();var h=jQuery("#menu-item-description"+a).val();var e=jQuery("#menu-item-classes"+a).val();var i=jQuery("#menu-item-xfn"+a).val();if("custom"!=f){jQuery("#edit-menu-item-url").attr("disabled","disabled")}jQuery("#edit-menu-item-id").val(a);jQuery("#edit-menu-item-title").val(b);jQuery("#edit-menu-item-url").val(g);jQuery("#edit-menu-item-attr-title").val(c);jQuery("#edit-menu-item-target").val(d);jQuery("#edit-menu-item-target option[value='"+d+"']").attr("selected","selected");jQuery("#edit-menu-item-description").val(h);jQuery("#edit-menu-item-classes").val(e);jQuery("#edit-menu-item-xfn").val(i);jQuery("#edit-menu-item-title").focus()}function wp_update_menu_item(){var h=jQuery("#edit-menu-item-id").val();var f=jQuery("#edit-menu-item-title").val();var b=jQuery("#edit-menu-item-url").val();var g=jQuery("#edit-menu-item-attr-title").val();var d=jQuery("#edit-menu-item-target").val();var c=jQuery("#edit-menu-item-description").val();var a=jQuery("#edit-menu-item-classes").val();var e=jQuery("#edit-menu-item-xfn").val();jQuery(".menu #menu-item"+h).find("span.item-title").html(f);jQuery(".menu #menu-item-title"+h).val(f);jQuery(".menu #menu-item-url"+h).val(b);jQuery(".menu #menu-item-attr-title"+h).val(g);jQuery(".menu #menu-item-target"+h).val(d);jQuery(".menu #menu-item-description"+h).val(c);jQuery(".menu #menu-item-classes"+h).val(a);jQuery(".menu #menu-item-xfn"+h).val(e);jQuery(".menu #menu-item"+h+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}})}function wp_remove_menu_item(b){var a=document.getElementById("menu-item"+b);if(a){jQuery(a).find("dt").each(function(){jQuery(this).animate({backgroundColor:"#FF3333"},{duration:"normal",complete:function(){jQuery(this).parent().parent().remove()}})})}}function wp_add_item_to_menu(a,k,f,n,l,b,m,h,e,d,c,i){var j=wp_get_unique_menu_id();var g=wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i);jQuery(".menu").append('");jQuery(".menu #menu-item"+j+" dt:first").animate({backgroundColor:"#FFFF33"},{duration:"normal",complete:function(){jQuery(this).css("backgroundColor","")}});wp_drag_and_drop();tb_init("a.thickbox, area.thickbox, input.thickbox")}function wp_add_checked_items_to_menu(b){var a=jQuery(b).siblings(".list-wrap").find(":checked");if(0==a.length){return false}jQuery(a).each(function(){var h=jQuery(this).parent().siblings(".menu-item-type").val();if("custom"==h){var e=jQuery(this).parent().siblings(".menu-item-attr-title").val();var f=jQuery(this).parent().siblings(".menu-item-target").val();var g=jQuery(this).parent().siblings(".menu-item-classes").val();var j=jQuery(this).parent().siblings(".menu-item-xfn").val()}else{var e="";var f="_none";var g="";var j=""}var c=jQuery(this).parent().siblings(".menu-item-db-id").val();var k=jQuery(this).parent().siblings(".menu-item-object-id").val();var n=jQuery(this).parent().siblings(".menu-item-append").val();var l=jQuery(this).parent().siblings(".menu-item-parent-id").val();var d=jQuery(this).parent().siblings(".menu-item-title").val();var m=jQuery(this).parent().siblings(".menu-item-url").val();var i=jQuery(this).parent().siblings(".menu-item-description").val();if(undefined==i){i=""}wp_add_item_to_menu(c,k,h,n,l,d,m,i,e,f,g,j);jQuery(this).attr("checked",false)})}function wp_drag_and_drop(){jQuery(".menu li").each(function(){if(!jQuery(this).children(".dropzone").attr("class")){jQuery(this).prepend('
')}});jQuery(".menu li").draggable({handle:" > dl",opacity:0.8,addClasses:false,helper:"clone",zIndex:100});jQuery(".menu li dl, .menu li .dropzone").droppable({accept:".menu li",tolerance:"pointer",drop:function(f,d){var a=jQuery(this).parent();var g=!jQuery(this).hasClass("dropzone");if(g&&a.children("ul").length==0){a.append('')}if(g){a.children("ul").append(d.draggable)}else{a.before(d.draggable)}a.find("dl,.dropzone").css({backgroundColor:"",borderColor:""});var c=d.draggable.attr("value");var b=a.attr("value");a.find("#menu-"+c).find("#parent"+c).val(b);jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style")},over:function(){if(jQuery(this).attr("class")=="dropzone ui-droppable"){jQuery(this).parent().find("div:first").css("background","none").css("height","50px")}else{if(jQuery(this).attr("class")=="ui-droppable"){jQuery(this).parent().find("dt:first").css("background","#d8d8d8")}else{}}var a=jQuery(this).parent().attr("id")},out:function(){jQuery(this).parent().find("dt").removeAttr("style");jQuery(this).parent().find("div:first").removeAttr("style");jQuery(this).filter(".dropzone").css({borderColor:""})}})}function wp_update_post_data(){var a=0;jQuery(".menu li").each(function(c){c=c+1;var b=jQuery(this).attr("value");jQuery(this).find("#menu-item-position"+b).attr("value",c);jQuery(this).attr("id","menu-item"+c);jQuery(this).attr("value",c);jQuery(this).find("#menu-item-db-id"+b).attr("id","menu-item-db-id"+c);jQuery(this).find("#menu-item-object-id"+b).attr("id","menu-item-object-id"+c);jQuery(this).find("#menu-item-append"+b).attr("id","menu-item-append"+c);jQuery(this).find("#menu-item-type"+b).attr("id","menu-item-type"+c);jQuery(this).find("#menu-item-position"+b).attr("id","menu-item-position"+c);var d=jQuery(this).find("#menu-item-parent-id"+b).parent().parent().parent().attr("value");jQuery(this).find("#menu-item-parent-id"+b).attr("id","menu-item-parent-id"+c);if(d){}else{d=0}jQuery(this).find("#menu-item-parent-id"+b).attr("value",d);jQuery(this).find("#menu-item-title"+b).attr("id","menu-item-title"+c);jQuery(this).find("#menu-item-url"+b).attr("id","menu-item-url"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-classes"+b).attr("id","menu-item-classes"+c);jQuery(this).find("#menu-item-xfn"+b).attr("id","menu-item-xfn"+c);jQuery(this).find("#menu-item-description"+b).attr("id","menu-item-description"+c);jQuery(this).find("#menu-item-attr-title"+b).attr("id","menu-item-attr-title"+c);jQuery(this).find("#menu-item-target"+b).attr("id","menu-item-target"+c);jQuery("#li-count").attr("value",c)})}function wp_get_unique_menu_id(){var d=jQuery(".menu li").length+1;var e=d;var a=0;try{var f=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}while(a==0){e=e+1;try{var b=document.getElementById("menu-"+e.toString()).value}catch(c){a=1}}return e}function wp_get_hidden_inputs(j,a,k,f,n,l,b,m,h,e,d,c,i){var g="";g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';g+='';return g};
\ No newline at end of file
diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php
index 685241b632..68841f72f4 100644
--- a/wp-admin/nav-menus.php
+++ b/wp-admin/nav-menus.php
@@ -9,170 +9,203 @@
* @subpackage Administration
*/
-require_once('admin.php');
+/** Load WordPress Administration Bootstrap */
+require_once( 'admin.php' );
-/*
-TODO
- Add caps: edit_menus, delete_menus
-*/
+// Permissions Check
if ( ! current_user_can('switch_themes') )
wp_die( __( 'Cheatin’ uh?' ));
+// Nav Menu CSS
wp_admin_css( 'nav-menu' );
+
+// jQuery
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'jquery-ui-draggable' );
wp_enqueue_script( 'jquery-ui-droppable' );
wp_enqueue_script( 'jquery-ui-sortable' );
-wp_enqueue_script( 'jquery-ui-dialog' );
+wp_enqueue_script( 'jquery-autocomplete' );
+
+// Nav Menu functions
wp_enqueue_script( 'nav-menu-dynamic-functions' );
wp_enqueue_script( 'nav-menu-default-items' );
-wp_enqueue_script( 'jquery-autocomplete' );
wp_enqueue_script( 'nav-menu-php-functions' );
+
+// Metaboxes
+wp_enqueue_script( 'common' );
+wp_enqueue_script( 'wp-lists' );
+wp_enqueue_script( 'postbox' );
+
+// Thickbox
add_thickbox();
-require_once( 'admin-header.php' );
+// Load all the nav menu interface functions
require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
-function wp_reset_nav_menu() {
- wp_nav_menu_setup( true );
- return true;
-}
-
+// Container for any messages displayed to the user
$messages_div = '';
-$menu_id_in_edit = 0;
-$updated = false;
-$advanced_option_descriptions = 'no';
-// Check which menu is selected and if menu is in edit already
-if ( isset( $_GET['edit-menu'] ) ) {
- $menu_selected_id = (int) $_GET['edit-menu'];
- $updated = true;
-} elseif ( isset( $_POST[ 'menu-id-in-edit' ] ) ) {
- $menu_selected_id = (int) $_POST[ 'menu-id-in-edit' ];
-} else {
- $menu_selected_id = 0;
-}
+// Container that stores the name of the active menu
+$nav_menu_selected_title = '';
-// Delete a menu
-if ( isset($_GET['delete-menu']) && $_GET['delete-menu'] > 0 ) {
- // if ( ! current_user_can('delete_menus') )
- // wp_die( __( 'Cheatin’ uh?' ));
+// The menu id of the current menu being edited
+$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
- $menu_id = (int) $_GET['delete-menu'];
- check_admin_referer( 'delete_menu-' . $menu_id );
+// Allowed actions: add, update, delete
+$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
- wp_delete_nav_menu( $menu_id );
- $messages_div = '' . __('Menu successfully deleted.') . '
';
- $menu_selected_id = 0;
- $updated = true;
-}
+switch ( $action ) {
+ case 'delete':
+ check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
-// Default Menu to show
-$menus = wp_get_nav_menus();
-
-if ( empty($menus) && empty($_POST) ) {
- wp_create_default_nav_menu();
- $menus = wp_get_nav_menus();
-}
-
-if ( ! $menu_selected_id && ! empty($menus) )
- $menu_selected_id = $menus[0]->term_id;
-
-// Get the name of the current Menu
-$menu_title = '';
-$valid_menu = false;
-if ( $menu_selected_id > 0 ) {
- foreach ( $menus as $menu ) {
- if ( $menu->term_id == $menu_selected_id ) {
- $menu_title = $menu->name;
- $valid_menu = true;
- break;
+ if ( is_nav_menu($nav_menu_selected_id) ) {
+ wp_delete_nav_menu( $nav_menu_selected_id );
+ $messages_div = '' . __('Menu successfully deleted.') . '
';
+ $nav_menu_selected_id = 0;
}
- }
+ break;
+
+ case 'update':
+ check_admin_referer( 'update-nav_menu' );
+
+ // Add Menu
+ if ( isset($_POST['create-menu']) ) {
+ if ( current_theme_supports('nav-menus') ) {
+ $add_nav_menu = esc_html( $_POST['create-menu-name'] );
+
+ if ( $add_nav_menu ) {
+ $add_nav_menu = wp_create_nav_menu( $add_nav_menu );
+
+ if ( is_wp_error( $add_nav_menu ) ) {
+ $messages_div = '' . $add_nav_menu->get_error_message() . '
';
+ } else {
+ $nav_menu_selected_id = $add_nav_menu->term_id;
+ $nav_menu_selected_title = $add_nav_menu->name;
+ $messages_div = '' . sprintf( __('The %s menu has been successfully created.'), esc_html( $add_nav_menu->name ) ) . '
';
+ }
+ } else {
+ $messages_div = '' . __('Please enter a valid menu name.') . '
';
+ }
+ unset($add_nav_menu);
+ }
+ }
+
+ // Update menu name
+ if ( isset($_POST['menu-name']) ) {
+ $old_nav_menu = get_term( $nav_menu_selected_id, 'nav_menu', ARRAY_A );
+ $args = array( 'name' => $_POST['menu-name'], 'slug' => null, 'description' => $old_nav_menu['description'], 'parent' => $old_nav_menu['parent'], );
+ $new_nav_menu = wp_update_term( $nav_menu_selected_id, 'nav_menu', $args );
+ }
+
+ // Update menu items
+ $update_nav_items = 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') );
+ $parent_menu_ids = array();
+
+ // Loop through all POST variables
+ for ( $k = 0; $k < $update_nav_items; $k++ ) {
+
+ $menu_item_db_id = isset( $_POST['menu-item-db-id'][$k] ) ? $_POST['menu-item-db-id'][$k] : 0;
+ $menu_item_object_id = isset( $_POST['menu-item-object-id'][$k] ) ? $_POST['menu-item-object-id'][$k] : 0;
+ $menu_item_parent_id = isset( $_POST['menu-item-parent-id'][$k] ) ? $_POST['menu-item-parent-id'][$k] : 0;
+ $menu_item_position = isset( $_POST['menu-item-position'][$k] ) ? $_POST['menu-item-position'][$k] : 0;
+ $menu_item_type = isset( $_POST['menu-item-type'][$k] ) ? $_POST['menu-item-type'][$k] : 'custom';
+ $menu_item_append = isset( $_POST['menu-item-append'][$k] ) ? $_POST['menu-item-append'][$k] : 'custom';
+
+ $menu_item_title = isset( $_POST['menu-item-title'][$k] ) ? $_POST['menu-item-title'][$k] : '';
+ $menu_item_url = isset( $_POST['menu-item-url'][$k] ) ? $_POST['menu-item-url'][$k] : '';
+ $menu_item_description = isset( $_POST['menu-item-description'][$k] ) ? $_POST['menu-item-description'][$k]: '';
+ $menu_item_attr_title = isset( $_POST['menu-item-attr-title'][$k] ) ? $_POST['menu-item-attr-title'][$k] : '';
+ $menu_item_target = isset( $_POST['menu-item-target'][$k] ) ? $_POST['menu-item-target'][$k] : 0;
+ $menu_item_classes = isset( $_POST['menu-item-classes'][$k] ) ? $_POST['menu-item-classes'][$k] : '';
+ $menu_item_xfn = isset( $_POST['menu-item-xfn'][$k] ) ? $_POST['menu-item-xfn'][$k] : '';
+
+ // Menu item title can't be blank
+ if ( '' == $menu_item_title )
+ continue;
+
+ // Populate the menu item
+ $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
+ 'ping_status' => 0, 'post_parent' => $menu_item_parent_id, 'menu_order' => $menu_item_position,
+ 'post_excerpt' => $menu_item_attr_title, 'tax_input' => array( 'nav_menu' => $update_nav_menu->name ),
+ 'post_content' => $menu_item_description, 'post_title' => $menu_item_title );
+
+ // New menu item
+ if ( $menu_item_db_id == 0 ) {
+ $menu_item_db_id = wp_insert_post( $post );
+ } elseif ( isset( $menu_items[$menu_item_db_id] ) ) {
+ $post['ID'] = $menu_item_db_id;
+ wp_update_post( $post );
+ unset( $menu_items[$menu_item_db_id] );
+ }
+ $parent_menu_ids[$k] = $menu_item_db_id;
+
+ update_post_meta( $menu_item_db_id, 'menu_item_type', $menu_item_type );
+ update_post_meta( $menu_item_db_id, 'menu_item_append', $menu_item_append );
+ update_post_meta( $menu_item_db_id, 'menu_item_object_id', $menu_item_object_id );
+ update_post_meta( $menu_item_db_id, 'menu_item_target', esc_attr($menu_item_target) );
+ update_post_meta( $menu_item_db_id, 'menu_item_classes', esc_attr($menu_item_classes) );
+ update_post_meta( $menu_item_db_id, 'menu_item_xfn', esc_attr($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
+ if ( !empty( $menu_items ) ) {
+ foreach ( array_keys( $menu_items ) as $menu_item_id ) {
+ wp_delete_post( $menu_item_id );
+ }
+ }
+ $messages_div = '' . __('The menu has been updated.') . '
';
+ }
+ break;
}
-if ( isset( $_POST['li-count'] ) )
- $post_counter = $_POST['li-count'];
-else
- $post_counter = 0;
+// Get all nav menus
+$nav_menus = wp_get_nav_menus();
-// Create a new menu. Menus are stored as terms in the 'menu' taxonomy.
-if ( isset( $_POST['create-menu'] ) && ! $updated ) {
- $insert_menu_name = $_POST['create-menu-name'];
+// Get recently edited nav menu
+$recently_edited = get_user_option( 'nav_menu_recently_edited' );
- if ( $insert_menu_name ) {
- $menu = wp_create_nav_menu( $insert_menu_name );
- if ( is_wp_error( $menu ) ) {
- $messages_div = '' . $menu->get_error_message() . '
';
- } else {
- $menus[$menu->term_id] = $menu;
- $menu_selected_id = $menu->term_id;
- $menu_id_in_edit = $menu_selected_id;
- $menu_title = $menu->name;
- $messages_div = '' . sprintf( __('“%s” menu has been created.'), esc_html( $menu->name ) ) . '
';
- $post_counter = 0;
- }
+// 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) ) {
+ $recently_edited = $nav_menu_selected_id;
+
+// Else if $nav_menu_selected_id is not a menu, but $recently_edited is, grab that one.
+} elseif ( 0 == $nav_menu_selected_id && is_nav_menu($recently_edited) ) {
+ $nav_menu_selected_id = $recently_edited;
+
+// Else try to grab the first menu from the menus list
+} elseif ( 0 == $nav_menu_selected_id && ! empty($nav_menus) ) {
+ $nav_menu_selected_id = $nav_menus[0]->term_id;
+}
+
+// Update the user's setting
+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 );
+
+// If there's a menu, get it's name.
+if ( !$nav_menu_selected_title && $nav_menu_selected_title = is_nav_menu( $nav_menu_selected_id ) ) {
+ $nav_menu_selected_title = $nav_menu_selected_title->name;
+}
+
+// The user has no menus.
+if ( !is_nav_menu( $nav_menu_selected_id ) ) {
+ if ( current_theme_supports('nav-menus') ) {
+ $messages_div = '' . __('You haven\'t setup any menus yet. Create a new menu.') . '
';
} else {
- $messages_div = '' . __('Please enter a valid menu name.') . '
';
+ $messages_div = '' . __('The current theme does not support menus.') . '
';
}
- $updated = true;
-}
-
-if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
- $menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') );
- $parent_menu_ids = array();
-
- // Loop through all POST variables
- for ( $k = 1; $k <= $post_counter; $k++ ) {
- $db_id = isset( $_POST['item-dbid'.$k] )? $_POST['item-dbid'.$k] : 0;
- $object_id = isset( $_POST['item-postmenu'.$k] )? $_POST['item-postmenu'.$k] : 0;
- $parent_id = isset( $_POST['item-parent'.$k] )? $_POST['item-parent'.$k] : 0;
- $custom_title = isset( $_POST['item-title'.$k] )? $_POST['item-title'.$k] : '';
- $custom_linkurl = ( isset( $_POST['item-url'.$k] ) && 'custom' == $_POST['item-type'.$k] ) ? $_POST['item-url'.$k] : '';
- $custom_description = isset( $_POST['item-description'.$k] )? $_POST['item-description'.$k] : '';
-
- // doesn't seem to be used by UI
- $position = isset( $_POST['item-position'.$k] )? $_POST['item-position'.$k] : 0;
- $linktype = isset( $_POST['item-type'.$k] )? $_POST['item-type'.$k] : 'custom';
- $custom_anchor_title = isset( $_POST['item-attr-title'.$k] )? $_POST['item-attr-title'.$k] : $custom_title;
- $new_window = isset( $_POST['item-target'.$k] )? $_POST['item-target'.$k] : 0;
-
- $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID,
- 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position,
- 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ),
- 'post_content' => $custom_description, 'post_title' => $custom_title );
-
- if ( $parent_id > 0 && isset( $parent_menu_ids[$parent_id] ) )
- $post['post_parent'] = $parent_menu_ids[$parent_id];
-
- // New menu item
- if ( $db_id == 0 ) {
- $db_id = wp_insert_post( $post );
- } elseif ( isset( $menu_items[$db_id] ) ) {
- $post['ID'] = $db_id;
- wp_update_post( $post );
- unset( $menu_items[$db_id] );
- }
- $parent_menu_ids[ $k ] = $db_id;
-
- update_post_meta( $db_id, 'menu_type', $linktype );
- update_post_meta( $db_id, 'object_id', $object_id );
- if ( $new_window )
- update_post_meta( $db_id, 'menu_new_window', 1 );
- else
- update_post_meta( $db_id, 'menu_new_window', 0 );
- if ( $custom_linkurl )
- update_post_meta( $db_id, 'menu_link', esc_url_raw( $custom_linkurl ) );
-
- }
- if ( !empty( $menu_items ) ) {
- foreach ( array_keys( $menu_items ) as $menu_id ) {
- wp_delete_post( $menu_id );
- }
- }
- $messages_div = '' . __('The menu has been updated.') . '
';
+} else {
+ add_meta_box( 'manage-menu', __( 'Menu Settings' ), 'wp_nav_menu_manage_menu_metabox', 'menus', 'side', 'high', array( $nav_menu_selected_id, $nav_menu_selected_title ) );
}
+// Get the admin header
+require_once( 'admin-header.php' );
?>
@@ -180,266 +213,110 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) {
-
\ No newline at end of file
diff --git a/wp-content/themes/twentyten/header.php b/wp-content/themes/twentyten/header.php
index 4adef9071c..c6e7165c7f 100644
--- a/wp-content/themes/twentyten/header.php
+++ b/wp-content/themes/twentyten/header.php
@@ -43,7 +43,7 @@
diff --git a/wp-content/themes/twentyten/style.css b/wp-content/themes/twentyten/style.css
index a93a6e0b2a..887996c62b 100644
--- a/wp-content/themes/twentyten/style.css
+++ b/wp-content/themes/twentyten/style.css
@@ -152,7 +152,7 @@ code {
-------------------------------------------------------------- */
/* The main theme structure */
-#access .menu,
+#access .menu-header,
#colophon,
#branding,
#main,
@@ -360,15 +360,15 @@ a:hover {
display:block;
float:left;
}
-#access .menu {
+#access .menu-header {
font-size: 13px;
margin-left: 12px;
}
-#access .menu ul {
+#access .menu-header ul {
list-style: none;
margin: 0;
}
-#access .menu li {
+#access .menu-header li {
float:left;
position: relative;
}
diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php
index 221c034cbb..1492c6a488 100644
--- a/wp-includes/nav-menu-template.php
+++ b/wp-includes/nav-menu-template.php
@@ -23,8 +23,8 @@
* @param array $args Arguments
*/
function wp_nav_menu( $args = array() ) {
- $defaults = array( 'menu' => '', 'menu_class' => 'menu', 'format' => 'div', 'echo' => true,
- 'fallback_cb' => 'wp_page_menu', 'link_before' => '', 'link_after' => '', 'before_link' => '', 'after_link' => '', );
+ $defaults = array( 'menu' => '', 'container' => 'div', 'container_class' => '', 'menu_class' => 'menu', 'echo' => true,
+ 'fallback_cb' => 'wp_page_menu', 'before_link' => '', 'after_link' => '', 'before_title' => '', 'after_title' => '', );
$args = wp_parse_args( $args, $defaults );
$args = apply_filters( 'wp_nav_menu_args', $args );
@@ -45,23 +45,26 @@ function wp_nav_menu( $args = array() ) {
}
}
- if ( $menu )
+ if ( !is_wp_error($menu) )
$args->menu = $menu->term_id;
$nav_menu = '';
- if ( 'div' == $args->format ) {
- if ( $menu )
- $nav_menu .= '