class-kirki-controls-checkbox-control.php (1939B)
1 <?php 2 /** 3 * Customizer Control: kirki-checkbox. 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_Checkbox_Control' ) ) { 18 19 /** 20 * Creates a checkbox control in the customizer. 21 * This is an almost verbatim copy of WordPress core's implementation 22 * but we converted the template to use Underscore.js, and added the tooltip. 23 */ 24 class Kirki_Controls_Checkbox_Control extends Kirki_Customize_Control { 25 26 /** 27 * The control type. 28 * 29 * @access public 30 * @var string 31 */ 32 public $type = 'kirki-checkbox'; 33 34 /** 35 * Enqueue control related scripts/styles. 36 * 37 * @access public 38 */ 39 public function enqueue() { 40 wp_enqueue_script( 'kirki-checkbox' ); 41 } 42 43 /** 44 * An Underscore (JS) template for this control's content (but not its container). 45 * 46 * Class variables for this control class are available in the `data` JS object; 47 * export custom variables by overriding {@see Kirki_Customize_Control::to_json()}. 48 * 49 * @see WP_Customize_Control::print_template() 50 * 51 * @access protected 52 */ 53 protected function content_template() { 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 <label> 59 <input type="checkbox" {{{ data.inputAttrs }}} value="{{ data.value }}" {{{ data.link }}}<# if ( '1' === data.value || 1 === data.value || true === data.value || 'on' === data.value ) { #> checked<# } #> /> 60 {{ data.label }} 61 <# if ( data.description ) { #> 62 <span class="description customize-control-description">{{{ data.description }}}</span> 63 <# } #> 64 </label> 65 <?php 66 } 67 } 68 }