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