Make WordPress Core

Ticket #47692: customizer_javascript_optgroup.diff

File customizer_javascript_optgroup.diff, 2.0 KB (added by Lwangaman, 5 years ago)

patch for wp-includes/class-wp-customize-manager.php which enables optgroup in select choices

  • wp-includes/class-wp-customize-manager.php

    diff --git wp-includes/class-wp-customize-manager.php wp-includes/class-wp-customize-manager.php
    index 9d55fb2..22791bc 100644
    final class WP_Customize_Manager { 
    42074207                                                                <#
    42084208                                                                var value, text;
    42094209                                                                if ( _.isObject( val ) ) {
    4210                                                                         value = val.value;
    4211                                                                         text = val.text;
     4210                                                                        if(val.hasOwnProperty('value') && val.hasOwnProperty('text') ){
     4211                                                                                value = val.value;
     4212                                                                                text = val.text;
     4213                                                                                #>
     4214                                                                                <option value="{{ value }}">{{ text }}</option>
     4215                                                                                <#
     4216                                                                        }
     4217                                                                        else{
     4218                                                                                //if val is an object but doesn't directly have "value" or "text" properties, we are probably dealing with an optgroup
     4219                                                                                text = key;
     4220                                                                                value = val;
     4221                                                                                #>
     4222                                                                                <optgroup label="{{ text }}">                                                                           
     4223                                                                                <#
     4224                                                                                var optgroupvalue, optgrouptext;
     4225                                                                                if( _.isArray( value ) ){
     4226                                                                                        _.each( value, function( val, key ) {
     4227                                                                                                if( _.isObject( val ) && val.hasOwnProperty('value') && val.hasOwnProperty('text') ){
     4228                                                                                                        optgroupvalue = val.value;
     4229                                                                                                        optgrouptext = val.text;
     4230                                                                                                        #>
     4231                                                                                                        <option value="{{ optgroupvalue }}">{{ optgrouptext }}</option>
     4232                                                                                                        <#
     4233                                                                                                }
     4234                                                                                        } );
     4235                                                                                }
     4236                                                                                else{
     4237                                                                                        _.each( value, function( val, key ) {
     4238                                                                                                optgroupvalue = key;
     4239                                                                                                optgrouptext = val;
     4240                                                                                                #>
     4241                                                                                                <option value="{{ optgroupvalue }}">{{ optgrouptext }}</option>
     4242                                                                                                <#
     4243                                                                                        } );
     4244                                                                                }
     4245                                                                                #>
     4246                                                                                </optgroup>
     4247                                                                                <#
     4248                                                                        }
    42124249                                                                } else {
    42134250                                                                        value = key;
    42144251                                                                        text = val;
     4252                                                                        #>
     4253                                                                        <option value="{{ value }}">{{ text }}</option>                                                         
     4254                                                                        <#
    42154255                                                                }
    42164256                                                                #>
    4217                                                                 <option value="{{ value }}">{{ text }}</option>
    42184257                                                        <# } ); #>
    42194258                                                </select>
    42204259                                        <# } else { #>