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. Built from https://develop.svn.wordpress.org/trunk@35581 git-svn-id: http://core.svn.wordpress.org/trunk@35545 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c470b872bd
commit
5411447dd3
|
@ -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 ];
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.4-beta3-35580';
|
||||
$wp_version = '4.4-beta3-35581';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue