Radio.php
90 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customizer Control: kirki-radio. |
| 4 | * |
| 5 | * @package kirki-framework/control-radio |
| 6 | * @copyright Copyright (c) 2023, Themeum |
| 7 | * @license https://opensource.org/licenses/MIT |
| 8 | * @since 1.0 |
| 9 | */ |
| 10 | |
| 11 | namespace Kirki\Control; |
| 12 | |
| 13 | use Kirki\Control\Base; |
| 14 | use Kirki\URL; |
| 15 | |
| 16 | // Exit if accessed directly. |
| 17 | if ( ! defined( 'ABSPATH' ) ) { |
| 18 | exit; |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Radio control |
| 23 | */ |
| 24 | class Radio extends Base { |
| 25 | |
| 26 | /** |
| 27 | * The control type. |
| 28 | * |
| 29 | * @access public |
| 30 | * @var string |
| 31 | */ |
| 32 | public $type = 'kirki-radio'; |
| 33 | |
| 34 | /** |
| 35 | * The version. Used in scripts & styles for cache-busting. |
| 36 | * |
| 37 | * @static |
| 38 | * @access public |
| 39 | * @since 1.0 |
| 40 | * @var string |
| 41 | */ |
| 42 | public static $control_ver = '1.1'; |
| 43 | |
| 44 | /** |
| 45 | * Enqueue control related scripts/styles. |
| 46 | * |
| 47 | * @access public |
| 48 | */ |
| 49 | |
| 50 | |
| 51 | /** |
| 52 | * An Underscore (JS) template for this control's content (but not its container). |
| 53 | * |
| 54 | * Class variables for this control class are available in the `data` JS object; |
| 55 | * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
| 56 | * |
| 57 | * @see WP_Customize_Control::print_template() |
| 58 | * |
| 59 | * @access protected |
| 60 | * @since 1.1 |
| 61 | * @return void |
| 62 | */ |
| 63 | protected function content_template() { |
| 64 | ?> |
| 65 | <span class="customize-control-title">{{{ data.label }}}</span> |
| 66 | <# if ( data.description ) { #> |
| 67 | <span class="description customize-control-description">{{{ data.description }}}</span> |
| 68 | <# } #> |
| 69 | <# _.each( data.choices, function( val, key ) { #> |
| 70 | <label> |
| 71 | <input |
| 72 | {{{ data.inputAttrs }}} |
| 73 | type="radio" |
| 74 | data-id="{{ data.id }}" |
| 75 | value="{{ key }}" |
| 76 | {{ data.link }} |
| 77 | name="_customize-radio-{{ data.id }}" |
| 78 | <# if ( data.value === key ) { #> checked<# } #> |
| 79 | /> |
| 80 | <# if ( _.isArray( val ) ) { #> |
| 81 | {{{ val[0] }}}<span class="option-description">{{{ val[1] }}}</span> |
| 82 | <# } else { #> |
| 83 | {{ val }} |
| 84 | <# } #> |
| 85 | </label> |
| 86 | <# } ); #> |
| 87 | <?php |
| 88 | } |
| 89 | } |
| 90 |