Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example customizer select control
<?php
class Hybrid_Customize_Control_Select extends WP_Customize_Control {
public $type = 'select-custom';
public function to_json() {
parent::to_json();
$this->json['choices'] = $this->choices;
$this->json['link'] = $this->get_link();
$this->json['value'] = $this->value();
}
public function content_template() { ?>
<# if ( ! data.choices ) {
return;
} #>
<label>
<# if ( data.label ) { #>
<span class="customize-control-title">{{ data.label }}</span>
<# } #>
<# if ( data.description ) { #>
<span class="description customize-control-description">{{{ data.description }}}</span>
<# } #>
<select {{{ data.link }}}>
<# _.each( data.choices, function( label, choice ) { #>
<option value="{{ choice }}" <# if ( choice === data.value ) { #> selected="selected" <# } #>>{{ label }}</option>
<# } ) #>
</select>
</label>
<?php }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment