Make WordPress Core


Ignore:
Timestamp:
03/15/2014 06:06:41 AM (11 years ago)
Author:
nacin
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/nav-menu.php

    r27251 r27556  
    366366    $update = 0 != $menu_item_db_id;
    367367
    368     // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
    369     if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) )
    370         $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
    371 
    372368    // New menu item. Default is draft status
    373369    if ( ! $update ) {
     
    377373        if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) )
    378374            return $menu_item_db_id;
     375    }
     376
     377    // Associate the menu item with the menu term
     378    // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
     379     if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) {
     380        wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' );
    379381    }
    380382
Note: See TracChangeset for help on using the changeset viewer.