Make WordPress Core

Ticket #27113: 27113.1.diff

File 27113.1.diff, 1003 bytes (added by danielbachhuber, 12 years ago)

Explicitly set the menu term when creating a menu item, rather than depending on tax_input

  • src/wp-includes/nav-menu.php

     
    357357
    358358        $update = 0 != $menu_item_db_id;
    359359
    360         // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
    361         if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) )
    362                 $post['tax_input'] = array( 'nav_menu' => array( intval( $menu->term_id ) ) );
    363 
    364360        // New menu item. Default is draft status
    365361        if ( ! $update ) {
    366362                $post['ID'] = 0;
     
    368364                $menu_item_db_id = wp_insert_post( $post );
    369365                if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) )
    370366                        return $menu_item_db_id;
     367
     368                // Associate the menu item with the menu term
     369                if ( $menu_id ) {
     370                        wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' );
     371                }
    371372        }
    372373
    373374        if ( 'custom' == $args['menu-item-type'] ) {