Customize: Link `elements` prior to embedding to prevent possible errors when a control is associated with a non-existent section.

Fixes issue specifically with attempting to access an orphaned control's `elements` immediately after it has been added. Normally this would not happen because a control would not be registered without a section, and also a control should only be interacted with once its `embedded` deferred has been resolved.

Also harden logic for gathering list of deferred setting IDs.

See #37964.
Fixes #42330.

Built from https://develop.svn.wordpress.org/trunk@42024


git-svn-id: http://core.svn.wordpress.org/trunk@41858 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-10-25 16:49:49 +00:00
parent 6b3b489a5d
commit 3ed6bbf4a4
3 changed files with 18 additions and 11 deletions

View File

@ -3474,12 +3474,18 @@
}
_.extend( settings, control.params.settings );
// Note: Settings can be an array or an object.
_.each( settings, function( setting, key ) {
if ( _.isObject( setting ) ) { // @todo Or check if instance of api.Setting?
control.settings[ key ] = setting;
} else {
deferredSettingIds.push( setting );
// Note: Settings can be an array or an object, with values being either setting IDs or Setting (or Value) objects.
_.each( settings, function( value, key ) {
var setting;
if ( _.isObject( value ) && _.isFunction( value.extended ) && value.extended( api.Value ) ) {
control.settings[ key ] = value;
} else if ( _.isString( value ) ) {
setting = api( value );
if ( setting ) {
control.settings[ key ] = setting;
} else {
deferredSettingIds.push( value );
}
}
} );
@ -3500,6 +3506,7 @@
// Identify the main setting.
control.setting = control.settings['default'] || null;
control.linkElements(); // Link initial elements present in server-rendered content.
control.embed();
};
@ -3511,7 +3518,7 @@
// After the control is embedded on the page, invoke the "ready" method.
control.deferred.embedded.done( function () {
control.linkElements();
control.linkElements(); // Link any additional elements after template is rendered by renderContent().
control.setupNotifications();
control.ready();
});

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-beta4-42023';
$wp_version = '4.9-beta4-42024';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.