[wp-trac] [WordPress Trac] #30740: WP_Customize_Manager::register_control_type should also address registering JS subclasses

WordPress Trac noreply at wordpress.org
Tue Mar 14 17:26:08 UTC 2017


#30740: WP_Customize_Manager::register_control_type should also address registering
JS subclasses
------------------------------+-------------------------
 Reporter:  celloexpressions  |       Owner:
     Type:  enhancement       |      Status:  closed
 Priority:  normal            |   Milestone:
Component:  Customize         |     Version:  4.1
 Severity:  normal            |  Resolution:  maybelater
 Keywords:  needs-patch       |     Focuses:
------------------------------+-------------------------
Changes (by westonruter):

 * status:  new => closed
 * resolution:   => maybelater
 * milestone:  Future Release =>


Comment:

 I'm not sure of the need for this now. Basically what I think this would
 look like is adding some JS identifier in the call to
 `register_control_type`, for example given a `My_Custom_Control` PHP class
 that has a `$type` of `my_custom` this ticket would entail doing something
 like this:

 {{{#!php
 <?php
 $wp_customize->register_control_type( 'My_Custom_Control',
 'MyCustomPlugin.Control' );
 }}}

 Which would then translate into PHP generating this JS:

 {{{#!js
 wp.customize.controlConstructor[ "my_custom" ] = MyCustomPlugin.Control;
 }}}

 However, we have to enqueue the JS for `MyCustomPlugin.Control` anyway, so
 it is just as easy to handle that in the JS file where that is defined to
 begin with, for example:

 {{{#!js
 wp.customize.controlConstructor.my_custom = ( function() {
     var MyCustomPlugin = wp.customize.Control.extend({ /*...*/ });
     return MyCustomPlugin;
 } )();
 }}}

 This is what I've been doing for the past couple years and it works great.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30740#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list