WordPress.org

Make WordPress Core

Opened 7 months ago

Last modified 11 days ago

#47692 new enhancement

Optgroup in Customizer Select Control

Reported by: chintan1896 Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.4
Component: Customize Keywords: needs-patch
Focuses: Cc:
PR Number:

Description

Optgroup add in Customizer Select Control

Attachments (3)

47692.diff (1.6 KB) - added by chintan1896 7 months ago.
wp-includes/class-wp-customize-control.php
47692-new.diff (1.8 KB) - added by chintan1896 2 months ago.
I attached new changes for optgroup
47692-updated.patch (1.2 KB) - added by chintan1896 11 days ago.
Changes for some choices in an optgroup and some at the top level of the select

Download all attachments as: .zip

Change History (9)

@chintan1896
7 months ago

wp-includes/class-wp-customize-control.php

#1 @chintan1896
7 months ago

Example for select optgroup

<?php
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'optgroup_example', array(
                'label'             => esc_attr__( 'Optgroup example', 'text-domain' ),
                'setting'           => 'optgroup_example',
                'type'              => 'select',
                'optgroup'          => true,
                'choices'           =>  array( 
                                    'optgroup-label-1' => array( 
                                                                'value-1'=> __( 'value-1', 'text-domain' ) 
                                                        ),
                                    'optgroup-label-2' => array( 
                                                                'value-2'=> __( 'value-2', 'text-domain' ) 
                                                        ),
                                ),
        ) ) );


Last edited 7 months ago by chintan1896 (previous) (diff)

#2 @silas2209
4 months ago

Any new updates here? I'd be very happy about this feature!

#3 @dlh
2 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 5.3 to 3.4

Support for optgroup would also needed to be added to the JavaScript control template, I think, not just the PHP template.

I also wonder about the $optgroup property in 47692.diff. What happens if a multidimensional array is used for $choices but $optgroup is false, or vice versa?

#4 @chintan1896
2 months ago

  • Keywords needs-testing has-patch added; needs-patch removed

Hey @dlh ,
Please review on latest patch.

@chintan1896
2 months ago

I attached new changes for optgroup

#5 @dlh
2 months ago

  • Keywords needs-patch added; needs-testing has-patch removed

Thanks for the updated patch, @chintan1896.

The new patch does guard against PHP errors, but it still seems to me to leave room for developer confusion. If $optgroup is changed without changing the shape of $choices, or vice versa, the control disappears.

Also, what if the developer wants some choices in an optgroup and some at the top level of the select?

I also don't see any change to the JavaScript control template in 47692-new.diff. Was it left out by accident?

@chintan1896
11 days ago

Changes for some choices in an optgroup and some at the top level of the select

#6 @chintan1896
11 days ago

Hey @dlh,
Please review on updated patch. It is overcome developer confusion and some choices in an optgroup and some at the top level of the select.

I have not enough knowledge in underscore.js . So i can't code in JavaScript control template.

This is a new example for optgroup and now we don't need to define optgroup it's automatically add optgroup if we added multidimensional array.

<?php
$wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'optgroup_example', array(
        'label'         => esc_attr__( 'Optgroup example', 'text-domain' ),
        'setting'       => 'optgroup_example',
        'type'          => 'select',
        'section'       => 'title_tagline',
        'choices'       =>  array(
                            'simple-option'    => __( 'Simple option', 'text-domain' ) ,
                            'optgroup-label-1' => array( 
                                                    'value-1'=> __( 'value-1', 'text-domain' ) 
                                                ),
                            'optgroup-label-2' => array( 
                                                    'value-2'=> __( 'value-2', 'text-domain' ) 
                                                ),
                        ),
) ) );
Last edited 11 days ago by chintan1896 (previous) (diff)
Note: See TracTickets for help on using tickets.