From 08cf9f0d98e41cfdc8dd3fb7f57ffa7692b5cfe1 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 12 Mar 2010 21:57:52 +0000 Subject: [PATCH] Always use lowercase strings or menu type. Don't double save custom link menu items (remove the AJAX save). see #12566 git-svn-id: http://svn.automattic.com/wordpress/trunk@13685 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/admin-ajax.php | 20 -------------- wp-admin/js/nav-menu-default-items.dev.js | 32 +++++------------------ wp-admin/js/nav-menu-default-items.js | 2 +- wp-admin/nav-menus.php | 2 +- wp-includes/nav-menu-template.php | 2 +- 5 files changed, 10 insertions(+), 48 deletions(-) diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php index ff5731ece1..98e15cf889 100644 --- a/wp-admin/admin-ajax.php +++ b/wp-admin/admin-ajax.php @@ -477,26 +477,6 @@ case 'dim-comment' : // On success, die with time() instead of 1 _wp_ajax_delete_comment_response( $comment->comment_ID ); die( '0' ); break; -case 'add-menu-link': - if ( !current_user_can( 'manage_links' ) ) - die('-1'); - - $link_url = isset($_POST['link_url']) ? $_POST['link_url'] : false; - $link_name = isset($_POST['link_name']) ? $_POST['link_name'] : false; - - if ( !$link_url || !$link_name ) - die('-1'); - - $post = array( 'post_type' => 'nav_menu_item', 'post_title' => $link_name, 'ping_status' => false, 'post_excerpt' => '', 'post_content' => '' ); - $db_id = wp_insert_post( $post ); - - update_post_meta( $db_id, 'menu_type', 'custom' ); - update_post_meta( $db_id, 'object_id', '' ); - update_post_meta( $db_id, 'menu_new_window', 0 ); - update_post_meta( $db_id, 'menu_link', esc_url_raw( $link_url ) ); - - echo $db_id; - break; case 'add-link-category' : // On the Fly check_ajax_referer( $action ); if ( !current_user_can( 'manage_categories' ) ) diff --git a/wp-admin/js/nav-menu-default-items.dev.js b/wp-admin/js/nav-menu-default-items.dev.js index 652b9acded..0eb6b8a5c0 100644 --- a/wp-admin/js/nav-menu-default-items.dev.js +++ b/wp-admin/js/nav-menu-default-items.dev.js @@ -76,10 +76,10 @@ jQuery(document).ready(function($){ $(this).hide(); $(this).siblings('.show-all').show(); }); - + // Add menu item to queue $('.list input').click(function(){ - + 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(); @@ -89,12 +89,12 @@ jQuery(document).ready(function($){ 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(); @@ -105,26 +105,8 @@ jQuery(document).ready(function($){ // Don't save the link if it was left with it's default settings if ( 'http://' == link_url || 'Menu Item' == link_name ) return; - - // Parameters to send off - params = { - action: 'add-menu-link', - link_url: link_url, - link_name: link_name, - }; - - // save the link - $.post( ajaxurl, params, function(response) { - if ( null == response || '-1' == response ) - return false; - - params.link_id = response; - - // add it to the available links section - // wp_update_links_list( params ); - - // and update the Menu with the new link - wp_add_item_to_menu( 'Custom', params.link_name, params.link_url, params.link_id, 0, '' ); - }, 'json'); + + // and update the Menu with the new link + wp_add_item_to_menu( 'custom', link_name, link_url, 0, 0, '' ); }); }); \ 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 3494c27e92..32a2324fe6 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}params={action:"add-menu-link",link_url:b,link_name:c,};a.post(ajaxurl,params,function(d){if(null==d||"-1"==d){return false}params.link_id=d;wp_add_item_to_menu("Custom",params.link_name,params.link_url,params.link_id,0,"")},"json")})}); \ No newline at end of file +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 diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 916e1b1920..685241b632 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -128,7 +128,7 @@ if ( $post_counter > 0 && $menu_selected_id > 0 && ! $updated ) { $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['linktype'.$k] ) ? $_POST['item-url'.$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 diff --git a/wp-includes/nav-menu-template.php b/wp-includes/nav-menu-template.php index d51645e9cc..4bc9148adb 100644 --- a/wp-includes/nav-menu-template.php +++ b/wp-includes/nav-menu-template.php @@ -198,7 +198,7 @@ function wp_get_nav_menu_item( $menu_item, $context, $args = array() ) { $item .= ''; // Menu Item Settings - $item .= ''; + $item .= ''; $item .= ''; $item .= ''; $item .= '';