Completed
Push — develop ( d78a0c...d37b89 )
by Aristeides
02:26
created

Kirki_Control_Custom::to_json()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: custom.
4
 *
5
 * Creates a new custom control.
6
 * Custom controls accept raw HTML/JS.
7
 *
8
 * @package     Kirki
9
 * @subpackage  Controls
10
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
11
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
12
 * @since       1.0
13
 */
14
15
// Exit if accessed directly.
16
if ( ! defined( 'ABSPATH' ) ) {
17
	exit;
18
}
19
20
/**
21
 * The "custom" control allows you to add any raw HTML.
22
 */
23
class Kirki_Control_Custom extends WP_Customize_Control {
24
25
	/**
26
	 * The control type.
27
	 *
28
	 * @access public
29
	 * @var string
30
	 */
31
	public $type = 'kirki-custom';
32
33
	/**
34
	 * Refresh the parameters passed to the JavaScript via JSON.
35
	 *
36
	 * @see WP_Customize_Control::to_json()
37
	 */
38
	public function to_json() {
39
		parent::to_json();
40
		$this->json['value'] = $this->value();
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 WP_Customize_Control::to_json()}.
48
	 *
49
	 * @see WP_Customize_Control::print_template()
50
	 *
51
	 * @access protected
52
	 */
53
	protected function content_template() {
54
		?>
55
		<label>
56
			<# if ( data.label ) { #>
57
				<span class="customize-control-title">{{{ data.label }}}</span>
58
			<# } #>
59
			<# if ( data.description ) { #>
60
				<span class="description customize-control-description">{{{ data.description }}}</span>
61
			<# } #>
62
			<?php
63
				/**
64
				 * The value is defined by the developer in the field configuration as 'default'.
65
				 * There is no user input on this field, it's a raw HTML/JS field and we do not sanitize it.
66
				 * Do not be alarmed, this is not a security issue.
67
				 * In order for someone to be able to change this they would have to have access to your filesystem.
68
				 * If that happens, they can change whatever they want anyways. This field is not a concern.
69
				 */
70
			?>
71
			{{{ data.value }}}
72
		</label>
73
		<?php
74
75
	}
76
}
77