Skip to content

Instantly share code, notes, and snippets.

@jasondevine
Last active February 21, 2021 00:40
Show Gist options
  • Save jasondevine/d0f945255ecfb0c94a5069ec000f41b6 to your computer and use it in GitHub Desktop.
Save jasondevine/d0f945255ecfb0c94a5069ec000f41b6 to your computer and use it in GitHub Desktop.
/**
* Multiple select customize control class.
*/
class Jayj_Customize_Control_Multiple_Select extends WP_Customize_Control {
/**
* The type of customize control being rendered.
*/
public $type = 'multiple-select';
/**
* Displays the multiple select on the customize screen.
*/
public function render_content() {
if ( empty( $this->choices ) )
return;
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<select <?php $this->link(); ?> multiple="multiple" style="height: 100%;">
<?php
foreach ( $this->choices as $value => $label ) {
$selected = ( in_array( $value, $this->value() ) ) ? selected( 1, 1, false ) : '';
echo '<option value="' . esc_attr( $value ) . '"' . $selected . '>' . $label . '</option>';
}
?>
</select>
</label>
<?php }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment