class-kirki-controls-radio-control.php (2111B)
1 <?php 2 /** 3 * Customizer Control: kirki-radio. 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_Radio_Control' ) ) { 18 19 /** 20 * Radio control 21 */ 22 class Kirki_Controls_Radio_Control extends Kirki_Customize_Control { 23 24 /** 25 * The control type. 26 * 27 * @access public 28 * @var string 29 */ 30 public $type = 'kirki-radio'; 31 32 /** 33 * Enqueue control related scripts/styles. 34 * 35 * @access public 36 */ 37 public function enqueue() { 38 wp_enqueue_script( 'kirki-radio' ); 39 } 40 41 /** 42 * An Underscore (JS) template for this control's content (but not its container). 43 * 44 * Class variables for this control class are available in the `data` JS object; 45 * export custom variables by overriding {@see Kirki_Customize_Control::to_json()}. 46 * 47 * @see WP_Customize_Control::print_template() 48 * 49 * @access protected 50 */ 51 protected function content_template() { 52 ?> 53 <# if ( ! data.choices ) { return; } #> 54 55 <# if ( data.tooltip ) { #> 56 <a href="#" class="tooltip hint--left" data-hint="{{ data.tooltip }}"><span class='dashicons dashicons-info'></span></a> 57 <# } #> 58 <# if ( data.label ) { #> 59 <span class="customize-control-title">{{ data.label }}</span> 60 <# } #> 61 <# if ( data.description ) { #> 62 <span class="description customize-control-description">{{{ data.description }}}</span> 63 <# } #> 64 <# for ( key in data.choices ) { #> 65 <label> 66 <input {{{ data.inputAttrs }}} type="radio" value="{{ key }}" name="_customize-radio-{{ data.id }}" {{{ data.link }}}<# if ( data.value === key ) { #> checked<# } #> /> 67 <# if ( _.isArray( data.choices[ key ] ) ) { #> 68 {{ data.choices[ key ][0] }} 69 <span class="option-description">{{ data.choices[ key ][1] }}</span> 70 <# } else { #> 71 {{ data.choices[ key ] }} 72 <# } #> 73 </label> 74 <# } #> 75 <?php 76 } 77 } 78 }