WordPress.org

Make WordPress Core

Changeset 35581


Ignore:
Timestamp:
11/09/2015 01:18:32 AM (6 years ago)
Author:
westonruter
Message:

Customize: Fix sub-nav menu items from appearing to bump to root level in preview upon saving.

This issue would appear when the parent nav menu item was also newly-inserted. The issue was only apparent in the prevew, as the actual data saved was correct. The menu_item_parent properties of the saved sub-nav menu items needed to get updated to refer to the newly-inserted parent nav_menu_item post IDs, as opposed to retaining the placeholder IDs.

Fixes #34628.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/js/customize-nav-menus.js

    r35302 r35581  
    24552455    api.Menus.applySavedData = function( data ) {
    24562456
    2457         var insertedMenuIdMapping = {};
     2457        var insertedMenuIdMapping = {}, insertedMenuItemIdMapping = {};
    24582458
    24592459        _( data.nav_menu_updates ).each(function( update ) {
     
    25862586        } );
    25872587
     2588        // Build up mapping of nav_menu_item placeholder IDs to inserted IDs.
     2589        _( data.nav_menu_item_updates ).each(function( update ) {
     2590            if ( update.previous_post_id ) {
     2591                insertedMenuItemIdMapping[ update.previous_post_id ] = update.post_id;
     2592            }
     2593        });
     2594
    25882595        _( data.nav_menu_item_updates ).each(function( update ) {
    25892596            var oldCustomizeId, newCustomizeId, oldSetting, newSetting, settingValue, oldControl, newControl;
     
    26102617                }
    26112618                settingValue = _.clone( settingValue );
     2619
     2620                // If the parent menu item was also inserted, update the menu_item_parent to the new ID.
     2621                if ( settingValue.menu_item_parent < 0 ) {
     2622                    if ( ! insertedMenuItemIdMapping[ settingValue.menu_item_parent ] ) {
     2623                        throw new Error( 'inserted ID for menu_item_parent not available' );
     2624                    }
     2625                    settingValue.menu_item_parent = insertedMenuItemIdMapping[ settingValue.menu_item_parent ];
     2626                }
    26122627
    26132628                // If the menu was also inserted, then make sure it uses the new menu ID for nav_menu_term_id.
Note: See TracChangeset for help on using the changeset viewer.