Completed
Push — develop ( 656b88...85b7b9 )
by Aristeides
06:46
created

Kirki_Control_Dashicons   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 180
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 180
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A to_json() 0 19 3
A enqueue() 0 6 1
B content_template() 0 106 1
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
78
		wp_enqueue_script( 'kirki-dynamic-control', trailingslashit( Kirki::$url ) . 'assets/js/dynamic-control.js', array( 'jquery', 'kirki-dynamic-control', 'customize-base' ), false, true );
79
		wp_enqueue_script( 'kirki-dashicons', trailingslashit( Kirki::$url ) . 'controls/dashicons/dashicons.js', array( 'jquery', 'customize-base' ), false, true );
80
		wp_enqueue_style( 'kirki-dashicons-css', trailingslashit( Kirki::$url ) . 'controls/dashicons/dashicons.css', null );
81
	}
82
83
	/**
84
	 * An Underscore (JS) template for this control's content (but not its container).
85
	 *
86
	 * Class variables for this control class are available in the `data` JS object;
87
	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
88
	 *
89
	 * @see WP_Customize_Control::print_template()
90
	 *
91
	 * @access protected
92
	 */
93
	protected function content_template() {
94
		?>
95
		<# if ( data.label ) { #><span class="customize-control-title">{{ data.label }}</span><# } #>
96
		<# if ( data.description ) { #><span class="description customize-control-description">{{{ data.description }}}</span><# } #>
97
		<div class="icons-wrapper">
98
			<# if ( ! _.isUndefined( data.choices ) && 1 < _.size( data.choices ) ) { #>
99
				<# for ( key in data.choices ) { #>
100
					<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"<# } #>>
101
						<label for="{{ data.id }}{{ key }}"><span class="dashicons dashicons-{{ data.choices[ key ] }}"></span></label>
102
					</input>
103
				<# } #>
104
			<# } else { #>
105
				<h4>Admin Menu</h4>
106
				<# for ( key in data.icons['admin-menu'] ) { #>
107
					<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"<# } #>>
108
						<label for="{{ data.id }}{{ data.icons['admin-menu'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['admin-menu'][ key ] }}"></span></label>
109
					</input>
110
				<# } #>
111
				<h4>Welcome Screen</h4>
112
				<# for ( key in data.icons['welcome-screen'] ) { #>
113
					<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"<# } #>>
114
						<label for="{{ data.id }}{{ data.icons['welcome-screen'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['welcome-screen'][ key ] }}"></span></label>
115
					</input>
116
				<# } #>
117
				<h4>Post Formats</h4>
118
				<# for ( key in data.icons['post-formats'] ) { #>
119
					<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"<# } #>>
120
						<label for="{{ data.id }}{{ data.icons['post-formats'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['post-formats'][ key ] }}"></span></label>
121
					</input>
122
				<# } #>
123
				<h4>Media</h4>
124
				<# for ( key in data.icons['media'] ) { #>
125
					<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"<# } #>>
126
						<label for="{{ data.id }}{{ data.icons['media'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['media'][ key ] }}"></span></label>
127
					</input>
128
				<# } #>
129
				<h4>Image Editing</h4>
130
				<# for ( key in data.icons['image-editing'] ) { #>
131
					<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"<# } #>>
132
						<label for="{{ data.id }}{{ data.icons['image-editing'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['image-editing'][ key ] }}"></span></label>
133
					</input>
134
				<# } #>
135
				<h4>TinyMCE</h4>
136
				<# for ( key in data.icons['tinymce'] ) { #>
137
					<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"<# } #>>
138
						<label for="{{ data.id }}{{ data.icons['tinymce'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['tinymce'][ key ] }}"></span></label>
139
					</input>
140
				<# } #>
141
				<h4>Posts</h4>
142
				<# for ( key in data.icons['posts'] ) { #>
143
					<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"<# } #>>
144
						<label for="{{ data.id }}{{ data.icons['posts'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['posts'][ key ] }}"></span></label>
145
					</input>
146
				<# } #>
147
				<h4>Sorting</h4>
148
				<# for ( key in data.icons['sorting'] ) { #>
149
					<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"<# } #>>
150
						<label for="{{ data.id }}{{ data.icons['sorting'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['sorting'][ key ] }}"></span></label>
151
					</input>
152
				<# } #>
153
				<h4>Social</h4>
154
				<# for ( key in data.icons['social'] ) { #>
155
					<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"<# } #>>
156
						<label for="{{ data.id }}{{ data.icons['social'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['social'][ key ] }}"></span></label>
157
					</input>
158
				<# } #>
159
				<h4>WordPress</h4>
160
				<# for ( key in data.icons['wordpress_org'] ) { #>
161
					<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"<# } #>>
162
						<label for="{{ data.id }}{{ data.icons['wordpress_org'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['wordpress_org'][ key ] }}"></span></label>
163
					</input>
164
				<# } #>
165
				<h4>Products</h4>
166
				<# for ( key in data.icons['products'] ) { #>
167
					<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"<# } #>>
168
						<label for="{{ data.id }}{{ data.icons['products'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['products'][ key ] }}"></span></label>
169
					</input>
170
				<# } #>
171
				<h4>Taxonomies</h4>
172
				<# for ( key in data.icons['taxonomies'] ) { #>
173
					<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"<# } #>>
174
						<label for="{{ data.id }}{{ data.icons['taxonomies'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['taxonomies'][ key ] }}"></span></label>
175
					</input>
176
				<# } #>
177
				<h4>Widgets</h4>
178
				<# for ( key in data.icons['widgets'] ) { #>
179
					<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"<# } #>>
180
						<label for="{{ data.id }}{{ data.icons['widgets'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['widgets'][ key ] }}"></span></label>
181
					</input>
182
				<# } #>
183
				<h4>Notifications</h4>
184
				<# for ( key in data.icons['notifications'] ) { #>
185
					<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"<# } #>>
186
						<label for="{{ data.id }}{{ data.icons['notifications'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['notifications'][ key ] }}"></span></label>
187
					</input>
188
				<# } #>
189
				<h4>Misc</h4>
190
				<# for ( key in data.icons['misc'] ) { #>
191
					<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"<# } #>>
192
						<label for="{{ data.id }}{{ data.icons['misc'][ key ] }}"><span class="dashicons dashicons-{{ data.icons['misc'][ key ] }}"></span></label>
193
					</input>
194
				<# } #>
195
			<# } #>
196
		</div>
197
		<?php
198
	}
199
}
200