1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Customizer Controls Base. |
4
|
|
|
* |
5
|
|
|
* Extend this in other controls. |
6
|
|
|
* |
7
|
|
|
* @package Kirki |
8
|
|
|
* @subpackage Controls |
9
|
|
|
* @copyright Copyright (c) 2017, Aristeides Stathopoulos |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @since 3.0.12 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A base for controls. |
16
|
|
|
*/ |
17
|
|
|
class Kirki_Control_Base extends WP_Customize_Control { |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Used to automatically generate all CSS output. |
21
|
|
|
* |
22
|
|
|
* @access public |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
public $output = array(); |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Data type |
29
|
|
|
* |
30
|
|
|
* @access public |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
public $option_type = 'theme_mod'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Option name (if using options). |
37
|
|
|
* |
38
|
|
|
* @access public |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
public $option_name = false; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The kirki_config we're using for this control |
45
|
|
|
* |
46
|
|
|
* @access public |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
public $kirki_config = 'global'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Whitelisting the "required" argument. |
53
|
|
|
* |
54
|
|
|
* @since 3.0.17 |
55
|
|
|
* @access public |
56
|
|
|
* @var array |
57
|
|
|
*/ |
58
|
|
|
public $required = array(); |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Whitelisting the "preset" argument. |
62
|
|
|
* |
63
|
|
|
* @since 3.0.26 |
64
|
|
|
* @access public |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
public $preset = array(); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Whitelisting the "css_vars" argument. |
71
|
|
|
* |
72
|
|
|
* @since 3.0.28 |
73
|
|
|
* @access public |
74
|
|
|
* @var string |
75
|
|
|
*/ |
76
|
|
|
public $css_vars = ''; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Extra script dependencies. |
80
|
|
|
* |
81
|
|
|
* @since 3.1.0 |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
|
|
public function kirki_script_dependencies() { |
85
|
|
|
return array(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Enqueue control related scripts/styles. |
90
|
|
|
* |
91
|
|
|
* @access public |
92
|
|
|
*/ |
93
|
|
|
public function enqueue() { |
94
|
|
|
|
95
|
|
|
// Build the suffix for the script. |
96
|
|
|
$suffix = ''; |
97
|
|
|
$suffix .= ( ! defined( 'SCRIPT_DEBUG' ) || true !== SCRIPT_DEBUG ) ? '.min' : ''; |
98
|
|
|
|
99
|
|
|
// The Kirki plugin URL. |
100
|
|
|
$kirki_url = trailingslashit( Kirki::$url ); |
101
|
|
|
|
102
|
|
|
// Enqueue ColorPicker. |
103
|
|
|
wp_enqueue_script( 'wp-color-picker-alpha', trailingslashit( Kirki::$url ) . 'assets/vendor/wp-color-picker-alpha/wp-color-picker-alpha.js', array( 'wp-color-picker' ), KIRKI_VERSION, true ); |
104
|
|
|
wp_enqueue_style( 'wp-color-picker' ); |
105
|
|
|
|
106
|
|
|
// Enqueue selectWoo. |
107
|
|
|
wp_enqueue_script( 'selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/js/selectWoo.full.js', array( 'jquery' ), '1.0.1', true ); |
108
|
|
|
wp_enqueue_style( 'selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/css/selectWoo.css', array(), '1.0.1' ); |
109
|
|
|
wp_enqueue_style( 'kirki-selectWoo', trailingslashit( Kirki::$url ) . 'assets/vendor/selectWoo/kirki.css', array(), KIRKI_VERSION ); |
110
|
|
|
|
111
|
|
|
// Enqueue the script. |
112
|
|
|
wp_enqueue_script( |
113
|
|
|
'kirki-script', |
114
|
|
|
"{$kirki_url}controls/js/script{$suffix}.js", |
115
|
|
|
array( |
116
|
|
|
'jquery', |
117
|
|
|
'customize-base', |
118
|
|
|
'wp-color-picker-alpha', |
119
|
|
|
'selectWoo', |
120
|
|
|
'jquery-ui-button', |
121
|
|
|
'jquery-ui-datepicker', |
122
|
|
|
), |
123
|
|
|
KIRKI_VERSION, |
124
|
|
|
false |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
wp_localize_script( |
128
|
|
|
'kirki-script', |
129
|
|
|
'kirkiL10n', |
130
|
|
|
array( |
131
|
|
|
'isScriptDebug' => ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ), |
132
|
|
|
'noFileSelected' => esc_html__( 'No File Selected', 'kirki' ), |
133
|
|
|
'remove' => esc_html__( 'Remove', 'kirki' ), |
134
|
|
|
'default' => esc_html__( 'Default', 'kirki' ), |
135
|
|
|
'selectFile' => esc_html__( 'Select File', 'kirki' ), |
136
|
|
|
'standardFonts' => esc_html__( 'Standard Fonts', 'kirki' ), |
137
|
|
|
'googleFonts' => esc_html__( 'Google Fonts', 'kirki' ), |
138
|
|
|
'defaultCSSValues' => esc_html__( 'CSS Defaults', 'kirki' ), |
139
|
|
|
'defaultBrowserFamily' => esc_html__( 'Default Browser Font-Family', 'kirki' ), |
140
|
|
|
) |
141
|
|
|
); |
142
|
|
|
|
143
|
|
|
$suffix = str_replace( '.min', '', $suffix ); |
144
|
|
|
|
145
|
|
|
// Enqueue the style. |
146
|
|
|
wp_enqueue_style( |
147
|
|
|
'kirki-styles', |
148
|
|
|
"{$kirki_url}controls/css/styles{$suffix}.css", |
149
|
|
|
array(), |
150
|
|
|
KIRKI_VERSION |
151
|
|
|
); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
156
|
|
|
* |
157
|
|
|
* @see WP_Customize_Control::to_json() |
158
|
|
|
*/ |
159
|
|
|
public function to_json() { |
160
|
|
|
|
161
|
|
|
// Get the basics from the parent class. |
162
|
|
|
parent::to_json(); |
163
|
|
|
|
164
|
|
|
// Default value. |
165
|
|
|
$this->json['default'] = $this->setting->default; |
166
|
|
|
if ( isset( $this->default ) ) { |
167
|
|
|
$this->json['default'] = $this->default; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
// Required. |
171
|
|
|
$this->json['required'] = $this->required; |
172
|
|
|
|
173
|
|
|
// Output. |
174
|
|
|
$this->json['output'] = $this->output; |
175
|
|
|
|
176
|
|
|
// Value. |
177
|
|
|
$this->json['value'] = $this->value(); |
178
|
|
|
|
179
|
|
|
// Choices. |
180
|
|
|
$this->json['choices'] = $this->choices; |
181
|
|
|
|
182
|
|
|
// The link. |
183
|
|
|
$this->json['link'] = $this->get_link(); |
184
|
|
|
|
185
|
|
|
// The ID. |
186
|
|
|
$this->json['id'] = $this->id; |
187
|
|
|
|
188
|
|
|
// Translation strings. |
189
|
|
|
$this->json['l10n'] = $this->l10n(); |
190
|
|
|
|
191
|
|
|
// The ajaxurl in case we need it. |
192
|
|
|
$this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
193
|
|
|
|
194
|
|
|
// Input attributes. |
195
|
|
|
$this->json['inputAttrs'] = ''; |
196
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
197
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
// The kirki-config. |
201
|
|
|
$this->json['kirkiConfig'] = $this->kirki_config; |
202
|
|
|
|
203
|
|
|
// The option-type. |
204
|
|
|
$this->json['kirkiOptionType'] = $this->option_type; |
205
|
|
|
|
206
|
|
|
// The option-name. |
207
|
|
|
$this->json['kirkiOptionName'] = $this->option_name; |
208
|
|
|
|
209
|
|
|
// The preset. |
210
|
|
|
$this->json['preset'] = $this->preset; |
211
|
|
|
|
212
|
|
|
// The CSS-Variables. |
213
|
|
|
$this->json['css-var'] = $this->css_vars; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Render the control's content. |
218
|
|
|
* |
219
|
|
|
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
220
|
|
|
* |
221
|
|
|
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
222
|
|
|
* |
223
|
|
|
* @since 3.4.0 |
224
|
|
|
*/ |
225
|
|
|
protected function render_content() {} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
229
|
|
|
* |
230
|
|
|
* Class variables for this control class are available in the `data` JS object; |
231
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
232
|
|
|
* |
233
|
|
|
* @see WP_Customize_Control::print_template() |
234
|
|
|
* |
235
|
|
|
* @access protected |
236
|
|
|
*/ |
237
|
|
|
protected function content_template() {} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Returns an array of translation strings. |
241
|
|
|
* |
242
|
|
|
* @access protected |
243
|
|
|
* @since 3.0.0 |
244
|
|
|
* @return array |
245
|
|
|
*/ |
246
|
|
|
protected function l10n() { |
247
|
|
|
return array(); |
248
|
|
|
} |
249
|
|
|
} |
250
|
|
|
|