Skip to content

Instantly share code, notes, and snippets.

@justintadlock
Created June 7, 2015 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justintadlock/177b2f41335a57b6e915 to your computer and use it in GitHub Desktop.
Save justintadlock/177b2f41335a57b6e915 to your computer and use it in GitHub Desktop.
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