-
Notifications
You must be signed in to change notification settings - Fork 37
Improve handling of active state for dynamically-created controls/sections/panels #157
Comments
@sayedwp The wp.customize.control('post[post][5779][post_excerpt]').deactivate() But actually, there is no effect. The control does not hide. The reason for this is we override the wp-customize-posts/js/customize-post-section.js Lines 662 to 665 in d75de18
So this override would need to be removed or overridden. See also the custom logic for wp-customize-posts/js/customize-post-section.js Lines 78 to 85 in d75de18
|
okay I see, it was not working because of |
Yes, it's not exactly intuitive right now. An improvement is needed in core to prevent dynamically-added controls from being deactivated when the preview refreshes, to avoid us needing to add these The relevant code is right here: https://github.com/xwp/wordpress-develop/blob/230f2986fb744a9d0dcaa09a448f9982b26322d6/src/wp-admin/js/customize-controls.js#L2883-L2911 And the specific code causing the problem is: var active = !! ( activeConstructs && activeConstructs[ id ] ); We could potentially fix this in Core by something like: if ( ! activeConstructs ) {
return;
}
var active, isDynamicallyCreated;
if ( ! _.isUndefined( activeConstructs[ id ] ) {
active = _.isUndefined( activeConstructs[ id ];
} else {
isDynamicallyCreated = ! _.isUndefined( wp.customize.settings[ type + 's' ][ id ] );
active = isDynamicallyCreated ? null : false;
}
if ( _.isBoolean( active ) ) {
if ( active ) {
construct.activate();
} else {
construct.deactivate();
}
} The Could you give that a try and see if it works? We could get this into 4.6. |
Moved to Trac: https://core.trac.wordpress.org/ticket/37270 |
When creating a dynamic control using
wp.customize.DynamicControl
, it does not give access to the methods that are available in the default controls. So we cannot dowp.customize.control( 'dynamicId' ).deactivate();
on these newly added controls.Default control :
Dynamic Control :
I am using the develop branch( Version: 0.5.0 ) of this plugin
The text was updated successfully, but these errors were encountered: