[wp-trac] [WordPress Trac] #47692: Optgroup in Customizer Select Control

WordPress Trac noreply at wordpress.org
Wed May 20 21:08:21 UTC 2020


#47692: Optgroup in Customizer Select Control
-------------------------+-----------------------------
 Reporter:  chintan1896  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Customize    |     Version:  3.4
 Severity:  normal       |  Resolution:
 Keywords:  needs-patch  |     Focuses:
-------------------------+-----------------------------

Comment (by Lwangaman):

 Using PHP I can confirm that the updated patch by @chintan1896 is working
 correctly, here is the result in the WordPress Customizer:
 [[Image(https://imgur.com/3rQwSHi)]]

 And here is my PHP code:


 {{{#!php
 <?php
                 $wp_customize->add_setting(
                         'myoptgroup', //No need to use a SERIALIZED name,
 as `theme_mod` settings already live under one db record
                         array(
                                 'default'    => 'carrots', //Default
 setting/value to save
                                 'type'       => 'theme_mod', //Is this an
 'option' or a 'theme_mod'?
                                 'capability' => 'edit_theme_options',
 //Optional. Special permissions for accessing this setting.
                                 'transport'  => 'postMessage' //What
 triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)?
                         )
                 );

                 $wp_customize->add_control(
                         'myoptgroup_ctl',
                         array(
                                 'label'                 => 'My OptGroup
 with Food choices',
                                 'settings'              => 'myoptgroup',
                                 'priority'              => 10,
                                 'section'               =>
 'a_section_of_my_options',
                                 'type'                  => 'select',
                                 'choices'               => array(
                                                         'Fruits'
 => array('apples' => 'Green apples', 'pears' => 'Pears', 'bananas' =>
 'Chiquita bananas' ),
                                                         'Vegetables'    =>
 array('peas' => 'Peas', 'carrots' => 'Carrots', 'tomatoes' => 'Cherry
 tomatoes' ),
                                                         'Meats'
 => array('chicken' => 'Grilled chicken breast', 'turkey' => 'Roasted
 turkey', 'sausages' => 'Blood sausages' ),
                                                         'Desserts'
 => array('icecream' => 'Mint chocolate chip ice cream', 'pudding' =>
 'Tapioca pudding'),
                                                         'supper'
 => 'Home cooked dinner meal',
                                                         'lunch'
 => 'Fast food take-away lunch'
                                                 )
                         )
                 );
         }

 }}}

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


More information about the wp-trac mailing list