Opened 9 years ago
Closed 9 years ago
#33428 closed defect (bug) (fixed)
Toggling customizer controls based on another control does not work anymore in 4.3
Reported by: | maimairel | Owned by: | westonruter |
---|---|---|---|
Milestone: | 4.3.1 | Priority: | normal |
Severity: | normal | Version: | 4.3 |
Component: | Customize | Keywords: | has-patch commit fixed-major |
Focuses: | javascript | Cc: |
Description
Hi,
Since update v4.3, the toggling of customizer controls based on another customizer control does not work anymore. It works, but gets hidden immediately after the customizer finished loading.
I checked the core code, and nothing has changed so it must be something else. It's this code that I'm talking about, in wp-admin/js/customize-controls.js
// Control visibility for default controls $.each({ 'background_image': { controls: [ 'background_repeat', 'background_position_x', 'background_attachment' ], callback: function( to ) { return !! to; } }, 'show_on_front': { controls: [ 'page_on_front', 'page_for_posts' ], callback: function( to ) { return 'page' === to; } }, 'header_textcolor': { controls: [ 'header_textcolor' ], callback: function( to ) { return 'blank' !== to; } } }, function( settingId, o ) { api( settingId, function( setting ) { $.each( o.controls, function( i, controlId ) { api.control( controlId, function( control ) { var visibility = function( to ) { control.container.toggle( o.callback( to ) ); }; visibility( setting.get() ); setting.bind( visibility ); }); }); }); });
Thank you :)
Attachments (3)
Change History (21)
This ticket was mentioned in Slack in #core by celloexpressions. View the logs.
9 years ago
#3
@
9 years ago
This bug can be reproduced in TwentyFifteen when accessing the Static Front Page customizer section.
=> The visibility of the controls page_for_posts and page_on_front depends upon the show_on_front setting value.
Since 4.3, the 2 dependant controls are always visible in the two following cases (as far as I understand) :
- first customizer load
- when the preview is refreshed (because the construct.activate() #2631 method is fired when api.previewer.preview is 'ready'
The bug can be fixed in those two cases by adding a check on the args param of the control.onChangeActive(active, args) method to see if the control is unchanged or not.
patch coming
#7
@
9 years ago
- Milestone changed from Awaiting Review to 4.3.1
- Owner set to westonruter
- Status changed from new to accepted
#9
@
9 years ago
I've identified that the regression was introduced in [33610] to fix #33220.
Specifically, the regression was caused by this change:
-
src/wp-admin/js/customize-controls.js
a b 2603 2624 _( constructs ).each( function ( activeConstructs, type ) { 2604 2625 api[ type ].each( function ( construct, id ) { 2605 2626 var active = !! ( activeConstructs && activeConstructs[ id ] ); 2606 construct.active( active ); 2627 if ( active ) { 2628 construct.activate(); 2629 } else { 2630 construct.deactivate(); 2631 } 2607 2632 } ); 2608 2633 } ); 2609 2634 } );
Prior to this change, calling construct.active( active )
would be a no-op if the construct.active.get()
already was already equal to the new active
variable. But now that we are explicitly calling construct.activate()
and construct.deactivate()
, we have to explicitly check whether the state is unchanged
.
#11
@
9 years ago
- Keywords needs-testing added
@maimairel Can you confirm the latest patch fixes your issue?
This ticket was mentioned in Slack in #core-customize by westonruter. View the logs.
9 years ago
#14
@
9 years ago
- Keywords needs-testing removed
I realized the unchanged
check also needs to be included in Container.onChangeActive
to do the same thing for sections and panels. See 33428.3.diff.
Incidentally, this also resolves #33494.
Adding the chat note by @ celloexpressions in Slack https://wordpress.slack.com/archives/core/p1440004003001718
Related: #33420 and #33434
Possible Duplicate: #29948