Created
June 7, 2015 06:46
-
-
Save justintadlock/177b2f41335a57b6e915 to your computer and use it in GitHub Desktop.
Example customizer select control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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