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

Kirki_Control_Dashicons::to_json()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 14
nc 4
nop 0
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Customizer Control: dashicons.
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.4
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Dashicons control (modified radio).
19
 */
20
class Kirki_Control_Dashicons extends WP_Customize_Control {
21
22
	/**
23
	 * The control type.
24
	 *
25
	 * @access public
26
	 * @var string
27
	 */
28
	public $type = 'kirki-dashicons';
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
	 * Refresh the parameters passed to the JavaScript via JSON.
48
	 *
49
	 * @access public
50
	 */
51
	public function to_json() {
52
		parent::to_json();
53
54
		$this->json['default'] = $this->setting->default;
55
		if ( isset( $this->default ) ) {
56
			$this->json['default'] = $this->default;
57
		}
58
		$this->json['output']  = $this->output;
59
		$this->json['value']   = $this->value();
60
		$this->json['choices'] = $this->choices;
61
		$this->json['link']    = $this->get_link();
62
		$this->json['id']      = $this->id;
63
64
		$this->json['inputAttrs'] = '';
65
		foreach ( $this->input_attrs as $attr => $value ) {
66
			$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" ';
67
		}
68
		$this->json['icons'] = Kirki_Helper::get_dashicons();
69
	}
70
71
	/**
72
	 * Enqueue control related scripts/styles.
73
	 *
74
	 * @access public
75
	 */
76
	public function enqueue() {
77
		wp_enqueue_script( 'kirki-dashicons', trailingslashit( Kirki::$url ) . 'controls/dashicons/dashicons.js', array( 'jquery', 'customize-base' ), false, true );
78
		wp_enqueue_style( 'kirki-dashicons-css', trailingslashit( Kirki::$url ) . 'controls/dashicons/dashicons.css', null );
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
		<# if ( data.label ) { #>
94
			<span class="customize-control-title">{{ data.label }}</span>
95
		<# } #>
96
		<# if ( data.description ) { #>
97
			<span class="description customize-control-description">{{{ data.description }}}</span>
98
		<# } #>
99
		<div class="icons-wrapper">
100
			<# if ( ! _.isUndefined( data.choices ) && 1 < _.size( data.choices ) ) { #>
101
				<# for ( key in data.choices ) { #>
102
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ key }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ key }}" {{{ data.link }}}<# if ( data.value === key ) { #> checked="checked"<# } #>>
103
						<label for="{{ data.id }}{{ key }}">
104
							<span class="dashicons dashicons-{{ data.choices[ key ] }}"></span>
105
						</label>
106
					</input>
107
				<# } #>
108
			<# } else { #>
109
				<h4>Admin Menu</h4>
110
				<# for ( key in data.icons['admin-menu'] ) { #>
111
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['admin-menu'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['admin-menu'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['admin-menu'][ key ] ) { #> checked="checked"<# } #>>
112
						<label for="{{ data.id }}{{ data.icons['admin-menu'][ key ] }}">
113
							<span class="dashicons dashicons-{{ data.icons['admin-menu'][ key ] }}"></span>
114
						</label>
115
					</input>
116
				<# } #>
117
				<h4>Welcome Screen</h4>
118
				<# for ( key in data.icons['welcome-screen'] ) { #>
119
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['welcome-screen'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['welcome-screen'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['welcome-screen'][ key ] ) { #> checked="checked"<# } #>>
120
						<label for="{{ data.id }}{{ data.icons['welcome-screen'][ key ] }}">
121
							<span class="dashicons dashicons-{{ data.icons['welcome-screen'][ key ] }}"></span>
122
						</label>
123
					</input>
124
				<# } #>
125
				<h4>Post Formats</h4>
126
				<# for ( key in data.icons['post-formats'] ) { #>
127
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['post-formats'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['post-formats'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['post-formats'][ key ] ) { #> checked="checked"<# } #>>
128
						<label for="{{ data.id }}{{ data.icons['post-formats'][ key ] }}">
129
							<span class="dashicons dashicons-{{ data.icons['post-formats'][ key ] }}"></span>
130
						</label>
131
					</input>
132
				<# } #>
133
				<h4>Media</h4>
134
				<# for ( key in data.icons['media'] ) { #>
135
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['media'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['media'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['media'][ key ] ) { #> checked="checked"<# } #>>
136
						<label for="{{ data.id }}{{ data.icons['media'][ key ] }}">
137
							<span class="dashicons dashicons-{{ data.icons['media'][ key ] }}"></span>
138
						</label>
139
					</input>
140
				<# } #>
141
				<h4>Image Editing</h4>
142
				<# for ( key in data.icons['image-editing'] ) { #>
143
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['image-editing'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['image-editing'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['image-editing'][ key ] ) { #> checked="checked"<# } #>>
144
						<label for="{{ data.id }}{{ data.icons['image-editing'][ key ] }}">
145
							<span class="dashicons dashicons-{{ data.icons['image-editing'][ key ] }}"></span>
146
						</label>
147
					</input>
148
				<# } #>
149
				<h4>TinyMCE</h4>
150
				<# for ( key in data.icons['tinymce'] ) { #>
151
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['tinymce'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['tinymce'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['tinymce'][ key ] ) { #> checked="checked"<# } #>>
152
						<label for="{{ data.id }}{{ data.icons['tinymce'][ key ] }}">
153
							<span class="dashicons dashicons-{{ data.icons['tinymce'][ key ] }}"></span>
154
						</label>
155
					</input>
156
				<# } #>
157
				<h4>Posts</h4>
158
				<# for ( key in data.icons['posts'] ) { #>
159
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['posts'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['posts'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['posts'][ key ] ) { #> checked="checked"<# } #>>
160
						<label for="{{ data.id }}{{ data.icons['posts'][ key ] }}">
161
							<span class="dashicons dashicons-{{ data.icons['posts'][ key ] }}"></span>
162
						</label>
163
					</input>
164
				<# } #>
165
				<h4>Sorting</h4>
166
				<# for ( key in data.icons['sorting'] ) { #>
167
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['sorting'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['sorting'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['sorting'][ key ] ) { #> checked="checked"<# } #>>
168
						<label for="{{ data.id }}{{ data.icons['sorting'][ key ] }}">
169
							<span class="dashicons dashicons-{{ data.icons['sorting'][ key ] }}"></span>
170
						</label>
171
					</input>
172
				<# } #>
173
				<h4>Social</h4>
174
				<# for ( key in data.icons['social'] ) { #>
175
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['social'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['social'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['social'][ key ] ) { #> checked="checked"<# } #>>
176
						<label for="{{ data.id }}{{ data.icons['social'][ key ] }}">
177
							<span class="dashicons dashicons-{{ data.icons['social'][ key ] }}"></span>
178
						</label>
179
					</input>
180
				<# } #>
181
				<h4>WordPress</h4>
182
				<# for ( key in data.icons['wordpress_org'] ) { #>
183
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['wordpress_org'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['wordpress_org'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['wordpress_org'][ key ] ) { #> checked="checked"<# } #>>
184
						<label for="{{ data.id }}{{ data.icons['wordpress_org'][ key ] }}">
185
							<span class="dashicons dashicons-{{ data.icons['wordpress_org'][ key ] }}"></span>
186
						</label>
187
					</input>
188
				<# } #>
189
				<h4>Products</h4>
190
				<# for ( key in data.icons['products'] ) { #>
191
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['products'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['products'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['products'][ key ] ) { #> checked="checked"<# } #>>
192
						<label for="{{ data.id }}{{ data.icons['products'][ key ] }}">
193
							<span class="dashicons dashicons-{{ data.icons['products'][ key ] }}"></span>
194
						</label>
195
					</input>
196
				<# } #>
197
				<h4>Taxonomies</h4>
198
				<# for ( key in data.icons['taxonomies'] ) { #>
199
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['taxonomies'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['taxonomies'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['taxonomies'][ key ] ) { #> checked="checked"<# } #>>
200
						<label for="{{ data.id }}{{ data.icons['taxonomies'][ key ] }}">
201
							<span class="dashicons dashicons-{{ data.icons['taxonomies'][ key ] }}"></span>
202
						</label>
203
					</input>
204
				<# } #>
205
				<h4>Widgets</h4>
206
				<# for ( key in data.icons['widgets'] ) { #>
207
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['widgets'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['widgets'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['widgets'][ key ] ) { #> checked="checked"<# } #>>
208
						<label for="{{ data.id }}{{ data.icons['widgets'][ key ] }}">
209
							<span class="dashicons dashicons-{{ data.icons['widgets'][ key ] }}"></span>
210
						</label>
211
					</input>
212
				<# } #>
213
				<h4>Notifications</h4>
214
				<# for ( key in data.icons['notifications'] ) { #>
215
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['notifications'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['notifications'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['notifications'][ key ] ) { #> checked="checked"<# } #>>
216
						<label for="{{ data.id }}{{ data.icons['notifications'][ key ] }}">
217
							<span class="dashicons dashicons-{{ data.icons['notifications'][ key ] }}"></span>
218
						</label>
219
					</input>
220
				<# } #>
221
				<h4>Misc</h4>
222
				<# for ( key in data.icons['misc'] ) { #>
223
					<input {{{ data.inputAttrs }}} class="dashicons-select" type="radio" value="{{ data.icons['misc'][ key ] }}" name="_customize-dashicons-radio-{{ data.id }}" id="{{ data.id }}{{ data.icons['misc'][ key ] }}" {{{ data.link }}}<# if ( data.value === data.icons['misc'][ key ] ) { #> checked="checked"<# } #>>
224
						<label for="{{ data.id }}{{ data.icons['misc'][ key ] }}">
225
							<span class="dashicons dashicons-{{ data.icons['misc'][ key ] }}"></span>
226
						</label>
227
					</input>
228
				<# } #>
229
			<# } #>
230
		</div>
231
		<?php
232
	}
233
}
234