|
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 http://opensource.org/licenses/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', null ); |
|
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
|
|
|
); |
|
125
|
|
|
|
|
126
|
|
|
wp_localize_script( |
|
127
|
|
|
'kirki-script', |
|
128
|
|
|
'kirkiL10n', |
|
129
|
|
|
array( |
|
130
|
|
|
'isScriptDebug' => ( defined( 'SCRIPT_DEBUG' ) && true === SCRIPT_DEBUG ), |
|
131
|
|
|
'noFileSelected' => esc_attr__( 'No File Selected', 'kirki' ), |
|
132
|
|
|
'remove' => esc_attr__( 'Remove', 'kirki' ), |
|
133
|
|
|
'default' => esc_attr__( 'Default', 'kirki' ), |
|
134
|
|
|
'selectFile' => esc_attr__( 'Select File', 'kirki' ), |
|
135
|
|
|
'standardFonts' => esc_attr__( 'Standard Fonts', 'kirki' ), |
|
136
|
|
|
'googleFonts' => esc_attr__( 'Google Fonts', 'kirki' ), |
|
137
|
|
|
'defaultCSSValues' => esc_attr__( 'CSS Defaults', 'kirki' ), |
|
138
|
|
|
'defaultBrowserFamily' => esc_attr__( 'Default Browser Font-Family', 'kirki' ), |
|
139
|
|
|
) |
|
140
|
|
|
); |
|
141
|
|
|
|
|
142
|
|
|
$suffix = str_replace( '.min', '', $suffix ); |
|
143
|
|
|
// Enqueue the style. |
|
144
|
|
|
wp_enqueue_style( |
|
145
|
|
|
'kirki-styles', |
|
146
|
|
|
"{$kirki_url}controls/css/styles{$suffix}.css", |
|
147
|
|
|
array(), |
|
148
|
|
|
KIRKI_VERSION |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Refresh the parameters passed to the JavaScript via JSON. |
|
154
|
|
|
* |
|
155
|
|
|
* @see WP_Customize_Control::to_json() |
|
156
|
|
|
*/ |
|
157
|
|
|
public function to_json() { |
|
158
|
|
|
// Get the basics from the parent class. |
|
159
|
|
|
parent::to_json(); |
|
160
|
|
|
// Default. |
|
161
|
|
|
$this->json['default'] = $this->setting->default; |
|
162
|
|
|
if ( isset( $this->default ) ) { |
|
163
|
|
|
$this->json['default'] = $this->default; |
|
164
|
|
|
} |
|
165
|
|
|
// Required. |
|
166
|
|
|
$this->json['required'] = $this->required; |
|
167
|
|
|
// Output. |
|
168
|
|
|
$this->json['output'] = $this->output; |
|
169
|
|
|
// Value. |
|
170
|
|
|
$this->json['value'] = $this->value(); |
|
171
|
|
|
// Choices. |
|
172
|
|
|
$this->json['choices'] = $this->choices; |
|
173
|
|
|
// The link. |
|
174
|
|
|
$this->json['link'] = $this->get_link(); |
|
175
|
|
|
// The ID. |
|
176
|
|
|
$this->json['id'] = $this->id; |
|
177
|
|
|
// Translation strings. |
|
178
|
|
|
$this->json['l10n'] = $this->l10n(); |
|
179
|
|
|
// The ajaxurl in case we need it. |
|
180
|
|
|
$this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
|
181
|
|
|
// Input attributes. |
|
182
|
|
|
$this->json['inputAttrs'] = ''; |
|
183
|
|
|
foreach ( $this->input_attrs as $attr => $value ) { |
|
184
|
|
|
$this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
185
|
|
|
} |
|
186
|
|
|
// The kirki-config. |
|
187
|
|
|
$this->json['kirkiConfig'] = $this->kirki_config; |
|
188
|
|
|
// The option-type. |
|
189
|
|
|
$this->json['kirkiOptionType'] = $this->option_type; |
|
190
|
|
|
// The option-name. |
|
191
|
|
|
$this->json['kirkiOptionName'] = $this->option_name; |
|
192
|
|
|
// The preset. |
|
193
|
|
|
$this->json['preset'] = $this->preset; |
|
194
|
|
|
// The CSS-Variables. |
|
195
|
|
|
$this->json['css-var'] = $this->css_vars; |
|
196
|
|
|
} |
|
197
|
|
|
|
|
198
|
|
|
/** |
|
199
|
|
|
* Render the control's content. |
|
200
|
|
|
* |
|
201
|
|
|
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
|
202
|
|
|
* |
|
203
|
|
|
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`. |
|
204
|
|
|
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly. |
|
205
|
|
|
* |
|
206
|
|
|
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
|
207
|
|
|
* |
|
208
|
|
|
* @since 3.4.0 |
|
209
|
|
|
*/ |
|
210
|
|
|
protected function render_content() {} |
|
211
|
|
|
|
|
212
|
|
|
/** |
|
213
|
|
|
* An Underscore (JS) template for this control's content (but not its container). |
|
214
|
|
|
* |
|
215
|
|
|
* Class variables for this control class are available in the `data` JS object; |
|
216
|
|
|
* export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
217
|
|
|
* |
|
218
|
|
|
* @see WP_Customize_Control::print_template() |
|
219
|
|
|
* |
|
220
|
|
|
* @access protected |
|
221
|
|
|
*/ |
|
222
|
|
|
protected function content_template() {} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* Returns an array of translation strings. |
|
226
|
|
|
* |
|
227
|
|
|
* @access protected |
|
228
|
|
|
* @since 3.0.0 |
|
229
|
|
|
* @return array |
|
230
|
|
|
*/ |
|
231
|
|
|
protected function l10n() { |
|
232
|
|
|
return array(); |
|
233
|
|
|
} |
|
234
|
|
|
} |
|
235
|
|
|
|