Completed
Push — develop ( 6bc4f7...cab9c0 )
by Aristeides
04:02
created

Kirki_Control_Date::to_json()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 4
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: kirki-date.
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2017, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       2.2
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * A simple date control, using jQuery UI.
19
 */
20
class Kirki_Control_Date extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-date';
29
30
	/**
31
	 * Used to automatically generate all CSS output.
32
	 *
33
	 * @access public
34
	 * @var array
35
	 */
36
	public $output = array();
37
38
	/**
39
	 * Data type
40
	 *
41
	 * @access public
42
	 * @var string
43
	 */
44
	public $option_type = 'theme_mod';
45
46
	/**
47
	 * Enqueue control related scripts/styles.
48
	 *
49
	 * @access public
50
	 */
51
	public function enqueue() {
52
		wp_enqueue_script( 'kirki-date', trailingslashit( Kirki::$url ) . 'controls/date/date.js', array( 'jquery', 'customize-base', 'jquery-ui-datepicker' ), false, true );
53
		wp_enqueue_style( 'kirki-date-css', trailingslashit( Kirki::$url ) . 'controls/date/date.css', null );
54
	}
55
56
	/**
57
	 * Refresh the parameters passed to the JavaScript via JSON.
58
	 *
59
	 * @see WP_Customize_Control::to_json()
60
	 */
61
	public function to_json() {
62
		parent::to_json();
63
64
		$this->json['default'] = $this->setting->default;
65
		if ( isset( $this->default ) ) {
66
			$this->json['default'] = $this->default;
67
		}
68
		$this->json['output']  = $this->output;
69
		$this->json['value']   = $this->value();
70
		$this->json['choices'] = $this->choices;
71
		$this->json['link']    = $this->get_link();
72
		$this->json['id']      = $this->id;
73
74
		$this->json['inputAttrs'] = '';
75
		foreach ( $this->input_attrs as $attr => $value ) {
76
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
77
		}
78
79
	}
80
81
	/**
82
	 * An Underscore (JS) template for this control's content (but not its container).
83
	 *
84
	 * Class variables for this control class are available in the `data` JS object;
85
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
86
	 *
87
	 * @see WP_Customize_Control::print_template()
88
	 *
89
	 * @access protected
90
	 */
91
	protected function content_template() {
92
		?>
93
		<label>
94
			<# if ( data.label ) { #>
95
				<span class="customize-control-title">{{{ data.label }}}</span>
96
			<# } #>
97
			<# if ( data.description ) { #>
98
				<span class="description customize-control-description">{{{ data.description }}}</span>
99
			<# } #>
100
			<div class="customize-control-content">
101
				<input {{{ data.inputAttrs }}} class="datepicker" type="text" id="{{ data.id }}" value="{{ data.value }}" {{{ data.link }}} />
102
			</div>
103
		</label>
104
		<?php
105
	}
106
}
107