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. git-svn-id: https://develop.svn.wordpress.org/trunk@35581 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2e2ea4876b
commit
c5e342b9f9
@ -2454,7 +2454,7 @@
|
||||
*/
|
||||
api.Menus.applySavedData = function( data ) {
|
||||
|
||||
var insertedMenuIdMapping = {};
|
||||
var insertedMenuIdMapping = {}, insertedMenuItemIdMapping = {};
|
||||
|
||||
_( data.nav_menu_updates ).each(function( update ) {
|
||||
var oldCustomizeId, newCustomizeId, customizeId, oldSetting, newSetting, setting, settingValue, oldSection, newSection, wasSaved, widgetTemplate, navMenuCount;
|
||||
@ -2585,6 +2585,13 @@
|
||||
}
|
||||
} );
|
||||
|
||||
// Build up mapping of nav_menu_item placeholder IDs to inserted IDs.
|
||||
_( data.nav_menu_item_updates ).each(function( update ) {
|
||||
if ( update.previous_post_id ) {
|
||||
insertedMenuItemIdMapping[ update.previous_post_id ] = update.post_id;
|
||||
}
|
||||
});
|
||||
|
||||
_( data.nav_menu_item_updates ).each(function( update ) {
|
||||
var oldCustomizeId, newCustomizeId, oldSetting, newSetting, settingValue, oldControl, newControl;
|
||||
if ( 'inserted' === update.status ) {
|
||||
@ -2610,6 +2617,14 @@
|
||||
}
|
||||
settingValue = _.clone( settingValue );
|
||||
|
||||
// If the parent menu item was also inserted, update the menu_item_parent to the new ID.
|
||||
if ( settingValue.menu_item_parent < 0 ) {
|
||||
if ( ! insertedMenuItemIdMapping[ settingValue.menu_item_parent ] ) {
|
||||
throw new Error( 'inserted ID for menu_item_parent not available' );
|
||||
}
|
||||
settingValue.menu_item_parent = insertedMenuItemIdMapping[ settingValue.menu_item_parent ];
|
||||
}
|
||||
|
||||
// If the menu was also inserted, then make sure it uses the new menu ID for nav_menu_term_id.
|
||||
if ( insertedMenuIdMapping[ settingValue.nav_menu_term_id ] ) {
|
||||
settingValue.nav_menu_term_id = insertedMenuIdMapping[ settingValue.nav_menu_term_id ];
|
||||
|
Loading…
Reference in New Issue
Block a user