Make WordPress Core

Changeset 42024


Ignore:
Timestamp:
10/25/2017 04:48:19 PM (7 years ago)
Author:
westonruter
Message:

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.

File:
1 edited

Legend:

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

    r41997 r42024  
    34753475            _.extend( settings, control.params.settings );
    34763476
    3477             // Note: Settings can be an array or an object.
    3478             _.each( settings, function( setting, key ) {
    3479                 if ( _.isObject( setting ) ) { // @todo Or check if instance of api.Setting?
    3480                     control.settings[ key ] = setting;
    3481                 } else {
    3482                     deferredSettingIds.push( setting );
     3477            // Note: Settings can be an array or an object, with values being either setting IDs or Setting (or Value) objects.
     3478            _.each( settings, function( value, key ) {
     3479                var setting;
     3480                if ( _.isObject( value ) && _.isFunction( value.extended ) && value.extended( api.Value ) ) {
     3481                    control.settings[ key ] = value;
     3482                } else if ( _.isString( value ) ) {
     3483                    setting = api( value );
     3484                    if ( setting ) {
     3485                        control.settings[ key ] = setting;
     3486                    } else {
     3487                        deferredSettingIds.push( value );
     3488                    }
    34833489                }
    34843490            } );
     
    35013507                control.setting = control.settings['default'] || null;
    35023508
     3509                control.linkElements(); // Link initial elements present in server-rendered content.
    35033510                control.embed();
    35043511            };
     
    35123519            // After the control is embedded on the page, invoke the "ready" method.
    35133520            control.deferred.embedded.done( function () {
    3514                 control.linkElements();
     3521                control.linkElements(); // Link any additional elements after template is rendered by renderContent().
    35153522                control.setupNotifications();
    35163523                control.ready();
Note: See TracChangeset for help on using the changeset viewer.