[wp-trac] [WordPress Trac] #37964: Allow customizer controls to be encapsulated by accepting pre-instantiated settings

WordPress Trac noreply at wordpress.org
Wed Oct 26 13:31:09 UTC 2016


#37964: Allow customizer controls to be encapsulated by accepting pre-instantiated
settings
-------------------------------------------------+-------------------------
 Reporter:  westonruter                          |       Owner:
     Type:  enhancement                          |  westonruter
 Priority:  normal                               |      Status:  accepted
Component:  Customize                            |   Milestone:  4.7
 Severity:  normal                               |     Version:  3.4
 Keywords:  has-patch needs-unit-tests needs-    |  Resolution:
  testing                                        |     Focuses:  javascript
-------------------------------------------------+-------------------------

Comment (by sayedwp):

 @westonruter Since the setting less control would not have `notifications`
 set by default its throwing error that `setting.notifications` is
 `undefined`, so we probably want to add a condition for
 `control.setupNotifications()` ?

 I am able to create control using `api.DynamicControl` using
 [https://github.com/xwp/wp-customize-posts/ wp-customize-posts] plugin
 without any errors however when I try to add a setting less control in
 other sections, the control is created and I can see that in console but
 it does not append/render in the section.

 Here is the code I tried


 {{{
 (function( api ) {

         api.section.bind( 'add', function( section ) {
                 if ( 'colors' === section.id ) {

                         var addSettingLessControl = function
 addSettingLessControl() {
                                 var control, id = 'product_color';

                                 control = new api.Control( id, {
                                         type: 'color',
                                         params: {
                                                 section: section.id,
                                                 label: "Test Control",
                                                 active: true,
                                                 type: 'color',
                                                 input_attrs: {
                                                         'data-customize-
 setting-link': id
                                                 },
                                                 settings: {
                                                         'default': new
 api.Value( '#000000' )
                                                 }
                                         }
                                 } );

                                 api.control.add( control.id, control );
                         };

                         section.expanded.bind( function( expanded ) {
                                 if ( expanded ) {
                                         addSettingLessControl();
                                 }
                         } );
                 }
         } );

 })( wp.customize );
 }}}


 Am I doing something wrong here?


 Tested with "'4.7-alpha-38934'" and twenty-sixteen theme.

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


More information about the wp-trac mailing list