[wp-trac] [WordPress Trac] #47692: Optgroup in Customizer Select Control
WordPress Trac
noreply at wordpress.org
Tue May 12 15:24:23 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):
Perhaps a way to transition this to new logic could be to add the
possibility of using "options" instead of "choices" in a transition phase,
explaining the difference in the documentation and inviting to transition
to the new style "options" instead of "choices". Then it could be handled
something like this:
{{{#!php
<?php
case 'select':
if ( empty( $this->choices ) && empty( $this->options ) ) {
return;
}
?>
<?php if ( ! empty( $this->label ) ) : ?>
<label for="<?php echo esc_attr( $input_id ); ?>" class
="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span id="<?php echo esc_attr( $description_id ); ?>"
class="description customize-control-description"><?php echo
$this->description; ?></span>
<?php endif; ?>
<select id="<?php echo esc_attr( $input_id ); ?>" <?php echo
$describedby_attr; ?> <?php $this->link(); ?>>
<?php
if( ! empty( $this->choices ) ){
foreach ( $this->choices as $value => $label ) {
echo '<option value="' . esc_attr( $value
) . '"' . selected( $this->value(), $value, false ) . '>' . $label .
'</option>';
}
}
else if( ! empty( $this->options ) ){
foreach ( $this->options as $label => $value ) {
if(is_array($value)){
echo '<optgroup label="' .
esc_attr( $label ) . '">';
foreach( $value as $label =>
$value ){
echo '<option value="' .
esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>'
. $label . '</option>';
}
echo '</optgroup>';
}
else{
echo '<option value="' . esc_attr(
$value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label
. '</option>';
}
}
}
?>
</select>
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/47692#comment:10>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list