[wp-trac] [WordPress Trac] #30701: Failures calling wp.customize.Control.activate() or wp.customize.Control.deactivate()
WordPress Trac
noreply at wordpress.org
Sat Dec 13 04:23:29 UTC 2014
#30701: Failures calling wp.customize.Control.activate() or
wp.customize.Control.deactivate()
--------------------------+-------------------
Reporter: westonruter | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: 4.1
Component: Customize | Version: trunk
Severity: normal | Keywords:
Focuses: javascript |
--------------------------+-------------------
The `wp.customize.Control` class has two methods `activate()` and
`deactivate()` which are ‘imported’ from `wp.customize.Section` and
`wp.customize.Panel`. The `activate` and `deactivate` methods are just
wrappers around the `_toggleActive` method. This method is defined on
`wp.customize.Section` and `wp.customize.Panel` but it was not imported
into `wp.customize.Control` as well, so when you attempt to call
`control.activate()` or `control.deactivate()` you get the infamous
'''Undefined is not a function''' since `control._toggleActive` does not
exist.
To reproduce the issue, try running this from the console:
{{{#!js
wp.customize.control('blogname').deactivate()
}}}
The fix is simple:
{{{#!diff
--- src/wp-admin/js/customize-controls.js
+++ src/wp-admin/js/customize-controls.js
@@ -913,6 +913,13 @@
*/
deactivate: Container.prototype.deactivate,
+ /**
+ * Re-use _toggleActive from Container class.
+ *
+ * @access private
+ */
+ _toggleActive: Container.prototype._toggleActive,
+
dropdownInit: function() {
var control = this,
statuses = this.container.find
('.dropdown-status'),
}}}
For interim fix if this does not make it into 4.1 is for plugins to do
this:
{{{#!js
if ( ! wp.customize.Control.prototype._toggleActive ) {
wp.customize.Control.prototype._toggleActive =
wp.customize.Section.prototype._toggleActive;
}
}}}
Relates to the Customizer JS APIs added in #28709. Props to
celloexpressions for alerting me to the issue.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30701>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list