class-kirki-controls-select-control.php (2826B)
1 <?php 2 /** 3 * Customizer Control: kirki-select. 4 * 5 * @package Kirki 6 * @subpackage Controls 7 * @copyright Copyright (c) 2016, Aristeides Stathopoulos 8 * @license http://opensource.org/licenses/https://opensource.org/licenses/MIT 9 * @since 1.0 10 */ 11 12 // Exit if accessed directly. 13 if ( ! defined( 'ABSPATH' ) ) { 14 exit; 15 } 16 17 if ( ! class_exists( 'Kirki_Controls_Select_Control' ) ) { 18 19 /** 20 * Select control. 21 */ 22 class Kirki_Controls_Select_Control extends Kirki_Customize_Control { 23 24 /** 25 * The control type. 26 * 27 * @access public 28 * @var string 29 */ 30 public $type = 'kirki-select'; 31 32 /** 33 * Maximum number of options the user will be able to select. 34 * Set to 1 for single-select. 35 * 36 * @access public 37 * @var int 38 */ 39 public $multiple = 1; 40 41 /** 42 * Refresh the parameters passed to the JavaScript via JSON. 43 * 44 * @access public 45 */ 46 public function to_json() { 47 parent::to_json(); 48 $this->json['multiple'] = $this->multiple; 49 } 50 51 /** 52 * Enqueue control related scripts/styles. 53 * 54 * @access public 55 */ 56 public function enqueue() { 57 wp_enqueue_script( 'kirki-select' ); 58 } 59 60 /** 61 * An Underscore (JS) template for this control's content (but not its container). 62 * 63 * Class variables for this control class are available in the `data` JS object; 64 * export custom variables by overriding {@see Kirki_Customize_Control::to_json()}. 65 * 66 * @see WP_Customize_Control::print_template() 67 * 68 * @access protected 69 */ 70 protected function content_template() { 71 ?> 72 <# if ( ! data.choices ) return; #> 73 <# if ( data.tooltip ) { #> 74 <a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span class='dashicons dashicons-info'></span></a> 75 <# } #> 76 <label> 77 <# if ( data.label ) { #> 78 <span class="customize-control-title">{{ data.label }}</span> 79 <# } #> 80 <# if ( data.description ) { #> 81 <span class="description customize-control-description">{{{ data.description }}}</span> 82 <# } #> 83 <select {{{ data.inputAttrs }}} {{{ data.link }}} data-multiple="{{ data.multiple }}"<# if ( 1 < data.multiple ) { #> multiple<# } #>> 84 <# if ( 1 < data.multiple && data.value ) { #> 85 <# for ( key in data.value ) { #> 86 <option value="{{ data.value[ key ] }}" selected>{{ data.choices[ data.value[ key ] ] }}</option> 87 <# } #> 88 <# for ( key in data.choices ) { #> 89 <# if ( data.value[ key ] in data.value ) { #> 90 <# } else { #> 91 <option value="{{ key }}">{{ data.choices[ key ] }}</option> 92 <# } #> 93 <# } #> 94 <# } else { #> 95 <# for ( key in data.choices ) { #> 96 <option value="{{ key }}"<# if ( key === data.value ) { #>selected<# } #>>{{ data.choices[ key ] }}</option> 97 <# } #> 98 <# } #> 99 </select> 100 </label> 101 <?php 102 } 103 } 104 }