From 08db3b53c5ff947332cfe10877c638b22b0bbfec Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 15 Mar 2014 06:07:16 +0000 Subject: [PATCH] Explicitly assign menu term relationship rather than piggybacking on wp_insert_post() with the tax_input argument. That argument currently depends on user context (see #19373). Adds unit test for properly updating orphaned menu items. props danielbachhuber. fixes #27113. Built from https://develop.svn.wordpress.org/trunk@27556 git-svn-id: http://core.svn.wordpress.org/trunk@27399 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/nav-menu.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/wp-includes/nav-menu.php b/wp-includes/nav-menu.php index 363c2ac4de..e01000c9cf 100644 --- a/wp-includes/nav-menu.php +++ b/wp-includes/nav-menu.php @@ -365,10 +365,6 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item $update = 0 != $menu_item_db_id; - // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms() - if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) - $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) ); - // New menu item. Default is draft status if ( ! $update ) { $post['ID'] = 0; @@ -378,6 +374,12 @@ function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item return $menu_item_db_id; } + // Associate the menu item with the menu term + // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms() + if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) { + wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' ); + } + if ( 'custom' == $args['menu-item-type'] ) { $args['menu-item-object-id'] = $menu_item_db_id; $args['menu-item-object'] = 'custom';