@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | |
15 | 15 | // Exit if accessed directly. |
16 | 16 | if ( ! defined( 'ABSPATH' ) ) { |
17 | - exit; |
|
17 | + exit; |
|
18 | 18 | } |
19 | 19 | |
20 | 20 | /** |
@@ -22,391 +22,391 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class Helper { |
24 | 24 | |
25 | - /** |
|
26 | - * Recursive replace in arrays. |
|
27 | - * |
|
28 | - * @static |
|
29 | - * @access public |
|
30 | - * @param array $array The first array. |
|
31 | - * @param array $array1 The second array. |
|
32 | - * @return mixed |
|
33 | - */ |
|
34 | - public static function array_replace_recursive( $array, $array1 ) { |
|
35 | - if ( function_exists( 'array_replace_recursive' ) ) { |
|
36 | - return array_replace_recursive( $array, $array1 ); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Handle the arguments, merge one by one. |
|
41 | - * |
|
42 | - * In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case |
|
43 | - * since this method is only used when the array_replace_recursive() function doesn't exist |
|
44 | - * and that was introduced in PHP v5.3. |
|
45 | - * |
|
46 | - * Once WordPress-Core raises its minimum requirements we'll be able to remove this fallback completely. |
|
47 | - */ |
|
48 | - $args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue |
|
49 | - $array = $args[0]; |
|
50 | - if ( ! is_array( $array ) ) { |
|
51 | - return $array; |
|
52 | - } |
|
53 | - $count = count( $args ); |
|
54 | - for ( $i = 1; $i < $count; $i++ ) { |
|
55 | - if ( is_array( $args[ $i ] ) ) { |
|
56 | - $array = self::recurse( $array, $args[ $i ] ); |
|
57 | - } |
|
58 | - } |
|
59 | - return $array; |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * Helper method to be used from the array_replace_recursive method. |
|
64 | - * |
|
65 | - * @static |
|
66 | - * @access public |
|
67 | - * @param array $array The first array. |
|
68 | - * @param array $array1 The second array. |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public static function recurse( $array, $array1 ) { |
|
72 | - foreach ( $array1 as $key => $value ) { |
|
73 | - |
|
74 | - // Create new key in $array, if it is empty or not an array. |
|
75 | - if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) { |
|
76 | - $array[ $key ] = []; |
|
77 | - } |
|
78 | - |
|
79 | - // Overwrite the value in the base array. |
|
80 | - if ( is_array( $value ) ) { |
|
81 | - $value = self::recurse( $array[ $key ], $value ); |
|
82 | - } |
|
83 | - $array[ $key ] = $value; |
|
84 | - } |
|
85 | - return $array; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Initialize the WP_Filesystem. |
|
90 | - * |
|
91 | - * @static |
|
92 | - * @access public |
|
93 | - * @return object WP_Filesystem |
|
94 | - */ |
|
95 | - public static function init_filesystem() { |
|
96 | - $credentials = []; |
|
97 | - |
|
98 | - if ( ! defined( 'FS_METHOD' ) ) { |
|
99 | - define( 'FS_METHOD', 'direct' ); |
|
100 | - } |
|
101 | - |
|
102 | - $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; |
|
103 | - |
|
104 | - if ( 'ftpext' === $method ) { |
|
105 | - // If defined, set it to that, Else, set to NULL. |
|
106 | - $credentials['hostname'] = defined( 'FTP_HOST' ) ? preg_replace( '|\w+://|', '', FTP_HOST ) : null; |
|
107 | - $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : null; |
|
108 | - $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : null; |
|
109 | - |
|
110 | - // Set FTP port. |
|
111 | - if ( strpos( $credentials['hostname'], ':' ) && null !== $credentials['hostname'] ) { |
|
112 | - list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 ); |
|
113 | - if ( ! is_numeric( $credentials['port'] ) ) { |
|
114 | - unset( $credentials['port'] ); |
|
115 | - } |
|
116 | - } else { |
|
117 | - unset( $credentials['port'] ); |
|
118 | - } |
|
119 | - |
|
120 | - // Set connection type. |
|
121 | - if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $method ) { |
|
122 | - $credentials['connection_type'] = 'ftps'; |
|
123 | - } elseif ( ! array_filter( $credentials ) ) { |
|
124 | - $credentials['connection_type'] = null; |
|
125 | - } else { |
|
126 | - $credentials['connection_type'] = 'ftp'; |
|
127 | - } |
|
128 | - } |
|
129 | - |
|
130 | - // The WordPress filesystem. |
|
131 | - global $wp_filesystem; |
|
132 | - |
|
133 | - if ( empty( $wp_filesystem ) ) { |
|
134 | - require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
135 | - WP_Filesystem( $credentials ); |
|
136 | - } |
|
137 | - |
|
138 | - return $wp_filesystem; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Returns the attachment object. |
|
143 | - * |
|
144 | - * @static |
|
145 | - * @access public |
|
146 | - * @see https://pippinsplugins.com/retrieve-attachment-id-from-image-url/ |
|
147 | - * @param string $url URL to the image. |
|
148 | - * @return int|string Numeric ID of the attachement. |
|
149 | - */ |
|
150 | - public static function get_image_id( $url ) { |
|
151 | - global $wpdb; |
|
152 | - if ( empty( $url ) ) { |
|
153 | - return 0; |
|
154 | - } |
|
155 | - |
|
156 | - $attachment = wp_cache_get( 'kirki_image_id_' . md5( $url ), null ); |
|
157 | - if ( false === $attachment ) { |
|
158 | - $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = %s;", $url ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
|
159 | - wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null ); |
|
160 | - } |
|
161 | - |
|
162 | - if ( ! empty( $attachment ) ) { |
|
163 | - return $attachment[0]; |
|
164 | - } |
|
165 | - return 0; |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Returns an array of the attachment's properties. |
|
170 | - * |
|
171 | - * @param string $url URL to the image. |
|
172 | - * @return array |
|
173 | - */ |
|
174 | - public static function get_image_from_url( $url ) { |
|
175 | - $image_id = self::get_image_id( $url ); |
|
176 | - $image = wp_get_attachment_image_src( $image_id, 'full' ); |
|
177 | - |
|
178 | - return [ |
|
179 | - 'url' => $image[0], |
|
180 | - 'width' => $image[1], |
|
181 | - 'height' => $image[2], |
|
182 | - 'thumbnail' => $image[3], |
|
183 | - ]; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Get an array of posts. |
|
188 | - * |
|
189 | - * @static |
|
190 | - * @access public |
|
191 | - * @param array $args Define arguments for the get_posts function. |
|
192 | - * @return array |
|
193 | - */ |
|
194 | - public static function get_posts( $args ) { |
|
195 | - if ( is_string( $args ) ) { |
|
196 | - $args = add_query_arg( |
|
197 | - [ |
|
198 | - 'suppress_filters' => false, |
|
199 | - ] |
|
200 | - ); |
|
201 | - } elseif ( is_array( $args ) && ! isset( $args['suppress_filters'] ) ) { |
|
202 | - $args['suppress_filters'] = false; |
|
203 | - } |
|
204 | - |
|
205 | - // Get the posts. |
|
206 | - // TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts. |
|
207 | - $posts = get_posts( $args ); |
|
208 | - |
|
209 | - // Properly format the array. |
|
210 | - $items = []; |
|
211 | - foreach ( $posts as $post ) { |
|
212 | - $items[ $post->ID ] = $post->post_title; |
|
213 | - } |
|
214 | - wp_reset_postdata(); |
|
215 | - |
|
216 | - return $items; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Get an array of publicly-querable taxonomies. |
|
221 | - * |
|
222 | - * @static |
|
223 | - * @access public |
|
224 | - * @return array |
|
225 | - */ |
|
226 | - public static function get_taxonomies() { |
|
227 | - $items = []; |
|
228 | - |
|
229 | - // Get the taxonomies. |
|
230 | - $taxonomies = get_taxonomies( |
|
231 | - [ |
|
232 | - 'public' => true, |
|
233 | - ] |
|
234 | - ); |
|
235 | - |
|
236 | - // Build the array. |
|
237 | - foreach ( $taxonomies as $taxonomy ) { |
|
238 | - $id = $taxonomy; |
|
239 | - $taxonomy = get_taxonomy( $taxonomy ); |
|
240 | - $items[ $id ] = $taxonomy->labels->name; |
|
241 | - } |
|
242 | - |
|
243 | - return $items; |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Get an array of publicly-querable post-types. |
|
248 | - * |
|
249 | - * @static |
|
250 | - * @access public |
|
251 | - * @return array |
|
252 | - */ |
|
253 | - public static function get_post_types() { |
|
254 | - $items = []; |
|
255 | - |
|
256 | - // Get the post types. |
|
257 | - $post_types = get_post_types( |
|
258 | - [ |
|
259 | - 'public' => true, |
|
260 | - ], |
|
261 | - 'objects' |
|
262 | - ); |
|
263 | - |
|
264 | - // Build the array. |
|
265 | - foreach ( $post_types as $post_type ) { |
|
266 | - $items[ $post_type->name ] = $post_type->labels->name; |
|
267 | - } |
|
268 | - |
|
269 | - return $items; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Get an array of terms from a taxonomy. |
|
274 | - * |
|
275 | - * @static |
|
276 | - * @access public |
|
277 | - * @param string|array $taxonomies See https://developer.wordpress.org/reference/functions/get_terms/ for details. |
|
278 | - * @return array |
|
279 | - */ |
|
280 | - public static function get_terms( $taxonomies ) { |
|
281 | - $items = []; |
|
282 | - |
|
283 | - // Get the post types. |
|
284 | - $terms = get_terms( $taxonomies ); |
|
285 | - |
|
286 | - // Build the array. |
|
287 | - foreach ( $terms as $term ) { |
|
288 | - $items[ $term->term_id ] = $term->name; |
|
289 | - } |
|
290 | - |
|
291 | - return $items; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Returns an array of navigation menus. |
|
296 | - * |
|
297 | - * @access public |
|
298 | - * @param string $value_field The value to be stored in options. Accepted values: id|slug. |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public static function get_nav_menus( $value_field = 'id' ) { |
|
302 | - $choices = []; |
|
303 | - $nav_menus = wp_get_nav_menus(); |
|
304 | - |
|
305 | - foreach ( $nav_menus as $term ) { |
|
306 | - $choices[ 'slug' === $value_field ? $term->slug : $term->term_id ] = $term->name; |
|
307 | - } |
|
308 | - |
|
309 | - return $choices; |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Gets an array of material-design colors. |
|
314 | - * |
|
315 | - * @static |
|
316 | - * @access public |
|
317 | - * @param string $context Allows us to get subsets of the palette. |
|
318 | - * @return array |
|
319 | - */ |
|
320 | - public static function get_material_design_colors( $context = 'primary' ) { |
|
321 | - return \Kirki\Util\MaterialColors::get_colors( $context ); |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get an array of all available dashicons. |
|
326 | - * |
|
327 | - * @static |
|
328 | - * @access public |
|
329 | - * @return array |
|
330 | - */ |
|
331 | - public static function get_dashicons() { |
|
332 | - if ( class_exists( '\Kirki\Util\Dashicons' ) ) { |
|
333 | - return \Kirki\Util\Dashicons::get_icons(); |
|
334 | - } |
|
335 | - return []; |
|
336 | - } |
|
337 | - |
|
338 | - /** |
|
339 | - * Compares the 2 values given the condition |
|
340 | - * |
|
341 | - * @param mixed $value1 The 1st value in the comparison. |
|
342 | - * @param mixed $value2 The 2nd value in the comparison. |
|
343 | - * @param string $operator The operator we'll use for the comparison. |
|
344 | - * @return boolean whether The comparison has succeded (true) or failed (false). |
|
345 | - */ |
|
346 | - public static function compare_values( $value1, $value2, $operator ) { |
|
347 | - if ( '===' === $operator ) { |
|
348 | - return $value1 === $value2; |
|
349 | - } |
|
350 | - if ( '!==' === $operator ) { |
|
351 | - return $value1 !== $value2; |
|
352 | - } |
|
353 | - if ( ( '!=' === $operator || 'not equal' === $operator ) ) { |
|
354 | - return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
|
355 | - } |
|
356 | - if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) { |
|
357 | - return $value2 >= $value1; |
|
358 | - } |
|
359 | - if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) { |
|
360 | - return $value2 <= $value1; |
|
361 | - } |
|
362 | - if ( ( '>' === $operator || 'greater' === $operator ) ) { |
|
363 | - return $value2 > $value1; |
|
364 | - } |
|
365 | - if ( ( '<' === $operator || 'smaller' === $operator ) ) { |
|
366 | - return $value2 < $value1; |
|
367 | - } |
|
368 | - if ( 'contains' === $operator || 'in' === $operator ) { |
|
369 | - if ( is_array( $value1 ) && is_array( $value2 ) ) { |
|
370 | - foreach ( $value2 as $val ) { |
|
371 | - if ( in_array( $val, $value1 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray |
|
372 | - return true; |
|
373 | - } |
|
374 | - } |
|
375 | - return false; |
|
376 | - } |
|
377 | - if ( is_array( $value1 ) && ! is_array( $value2 ) ) { |
|
378 | - return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
379 | - } |
|
380 | - if ( is_array( $value2 ) && ! is_array( $value1 ) ) { |
|
381 | - return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
382 | - } |
|
383 | - return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) ); |
|
384 | - } |
|
385 | - if ( 'does not contain' === $operator || 'not in' === $operator ) { |
|
386 | - return ! self::compare_values( $value1, $value2, $operator ); |
|
387 | - } |
|
388 | - return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Prepare PHP array to be used as JS object. |
|
393 | - * |
|
394 | - * @see See https://developer.wordpress.org/reference/classes/wp_scripts/localize/ |
|
395 | - * |
|
396 | - * @param array $values The data which can be either a single or multi-dimensional array. |
|
397 | - * @return array |
|
398 | - */ |
|
399 | - public static function prepare_php_array_for_js( $values ) { |
|
400 | - |
|
401 | - foreach ( $values as $key => $value ) { |
|
402 | - if ( ! is_scalar( $value ) ) { |
|
403 | - continue; |
|
404 | - } |
|
405 | - |
|
406 | - $values[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
407 | - } |
|
408 | - |
|
409 | - return $values; |
|
410 | - |
|
411 | - } |
|
25 | + /** |
|
26 | + * Recursive replace in arrays. |
|
27 | + * |
|
28 | + * @static |
|
29 | + * @access public |
|
30 | + * @param array $array The first array. |
|
31 | + * @param array $array1 The second array. |
|
32 | + * @return mixed |
|
33 | + */ |
|
34 | + public static function array_replace_recursive( $array, $array1 ) { |
|
35 | + if ( function_exists( 'array_replace_recursive' ) ) { |
|
36 | + return array_replace_recursive( $array, $array1 ); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Handle the arguments, merge one by one. |
|
41 | + * |
|
42 | + * In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case |
|
43 | + * since this method is only used when the array_replace_recursive() function doesn't exist |
|
44 | + * and that was introduced in PHP v5.3. |
|
45 | + * |
|
46 | + * Once WordPress-Core raises its minimum requirements we'll be able to remove this fallback completely. |
|
47 | + */ |
|
48 | + $args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue |
|
49 | + $array = $args[0]; |
|
50 | + if ( ! is_array( $array ) ) { |
|
51 | + return $array; |
|
52 | + } |
|
53 | + $count = count( $args ); |
|
54 | + for ( $i = 1; $i < $count; $i++ ) { |
|
55 | + if ( is_array( $args[ $i ] ) ) { |
|
56 | + $array = self::recurse( $array, $args[ $i ] ); |
|
57 | + } |
|
58 | + } |
|
59 | + return $array; |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * Helper method to be used from the array_replace_recursive method. |
|
64 | + * |
|
65 | + * @static |
|
66 | + * @access public |
|
67 | + * @param array $array The first array. |
|
68 | + * @param array $array1 The second array. |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public static function recurse( $array, $array1 ) { |
|
72 | + foreach ( $array1 as $key => $value ) { |
|
73 | + |
|
74 | + // Create new key in $array, if it is empty or not an array. |
|
75 | + if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) { |
|
76 | + $array[ $key ] = []; |
|
77 | + } |
|
78 | + |
|
79 | + // Overwrite the value in the base array. |
|
80 | + if ( is_array( $value ) ) { |
|
81 | + $value = self::recurse( $array[ $key ], $value ); |
|
82 | + } |
|
83 | + $array[ $key ] = $value; |
|
84 | + } |
|
85 | + return $array; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Initialize the WP_Filesystem. |
|
90 | + * |
|
91 | + * @static |
|
92 | + * @access public |
|
93 | + * @return object WP_Filesystem |
|
94 | + */ |
|
95 | + public static function init_filesystem() { |
|
96 | + $credentials = []; |
|
97 | + |
|
98 | + if ( ! defined( 'FS_METHOD' ) ) { |
|
99 | + define( 'FS_METHOD', 'direct' ); |
|
100 | + } |
|
101 | + |
|
102 | + $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; |
|
103 | + |
|
104 | + if ( 'ftpext' === $method ) { |
|
105 | + // If defined, set it to that, Else, set to NULL. |
|
106 | + $credentials['hostname'] = defined( 'FTP_HOST' ) ? preg_replace( '|\w+://|', '', FTP_HOST ) : null; |
|
107 | + $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : null; |
|
108 | + $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : null; |
|
109 | + |
|
110 | + // Set FTP port. |
|
111 | + if ( strpos( $credentials['hostname'], ':' ) && null !== $credentials['hostname'] ) { |
|
112 | + list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 ); |
|
113 | + if ( ! is_numeric( $credentials['port'] ) ) { |
|
114 | + unset( $credentials['port'] ); |
|
115 | + } |
|
116 | + } else { |
|
117 | + unset( $credentials['port'] ); |
|
118 | + } |
|
119 | + |
|
120 | + // Set connection type. |
|
121 | + if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $method ) { |
|
122 | + $credentials['connection_type'] = 'ftps'; |
|
123 | + } elseif ( ! array_filter( $credentials ) ) { |
|
124 | + $credentials['connection_type'] = null; |
|
125 | + } else { |
|
126 | + $credentials['connection_type'] = 'ftp'; |
|
127 | + } |
|
128 | + } |
|
129 | + |
|
130 | + // The WordPress filesystem. |
|
131 | + global $wp_filesystem; |
|
132 | + |
|
133 | + if ( empty( $wp_filesystem ) ) { |
|
134 | + require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
135 | + WP_Filesystem( $credentials ); |
|
136 | + } |
|
137 | + |
|
138 | + return $wp_filesystem; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Returns the attachment object. |
|
143 | + * |
|
144 | + * @static |
|
145 | + * @access public |
|
146 | + * @see https://pippinsplugins.com/retrieve-attachment-id-from-image-url/ |
|
147 | + * @param string $url URL to the image. |
|
148 | + * @return int|string Numeric ID of the attachement. |
|
149 | + */ |
|
150 | + public static function get_image_id( $url ) { |
|
151 | + global $wpdb; |
|
152 | + if ( empty( $url ) ) { |
|
153 | + return 0; |
|
154 | + } |
|
155 | + |
|
156 | + $attachment = wp_cache_get( 'kirki_image_id_' . md5( $url ), null ); |
|
157 | + if ( false === $attachment ) { |
|
158 | + $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = %s;", $url ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
|
159 | + wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null ); |
|
160 | + } |
|
161 | + |
|
162 | + if ( ! empty( $attachment ) ) { |
|
163 | + return $attachment[0]; |
|
164 | + } |
|
165 | + return 0; |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Returns an array of the attachment's properties. |
|
170 | + * |
|
171 | + * @param string $url URL to the image. |
|
172 | + * @return array |
|
173 | + */ |
|
174 | + public static function get_image_from_url( $url ) { |
|
175 | + $image_id = self::get_image_id( $url ); |
|
176 | + $image = wp_get_attachment_image_src( $image_id, 'full' ); |
|
177 | + |
|
178 | + return [ |
|
179 | + 'url' => $image[0], |
|
180 | + 'width' => $image[1], |
|
181 | + 'height' => $image[2], |
|
182 | + 'thumbnail' => $image[3], |
|
183 | + ]; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Get an array of posts. |
|
188 | + * |
|
189 | + * @static |
|
190 | + * @access public |
|
191 | + * @param array $args Define arguments for the get_posts function. |
|
192 | + * @return array |
|
193 | + */ |
|
194 | + public static function get_posts( $args ) { |
|
195 | + if ( is_string( $args ) ) { |
|
196 | + $args = add_query_arg( |
|
197 | + [ |
|
198 | + 'suppress_filters' => false, |
|
199 | + ] |
|
200 | + ); |
|
201 | + } elseif ( is_array( $args ) && ! isset( $args['suppress_filters'] ) ) { |
|
202 | + $args['suppress_filters'] = false; |
|
203 | + } |
|
204 | + |
|
205 | + // Get the posts. |
|
206 | + // TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts. |
|
207 | + $posts = get_posts( $args ); |
|
208 | + |
|
209 | + // Properly format the array. |
|
210 | + $items = []; |
|
211 | + foreach ( $posts as $post ) { |
|
212 | + $items[ $post->ID ] = $post->post_title; |
|
213 | + } |
|
214 | + wp_reset_postdata(); |
|
215 | + |
|
216 | + return $items; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Get an array of publicly-querable taxonomies. |
|
221 | + * |
|
222 | + * @static |
|
223 | + * @access public |
|
224 | + * @return array |
|
225 | + */ |
|
226 | + public static function get_taxonomies() { |
|
227 | + $items = []; |
|
228 | + |
|
229 | + // Get the taxonomies. |
|
230 | + $taxonomies = get_taxonomies( |
|
231 | + [ |
|
232 | + 'public' => true, |
|
233 | + ] |
|
234 | + ); |
|
235 | + |
|
236 | + // Build the array. |
|
237 | + foreach ( $taxonomies as $taxonomy ) { |
|
238 | + $id = $taxonomy; |
|
239 | + $taxonomy = get_taxonomy( $taxonomy ); |
|
240 | + $items[ $id ] = $taxonomy->labels->name; |
|
241 | + } |
|
242 | + |
|
243 | + return $items; |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Get an array of publicly-querable post-types. |
|
248 | + * |
|
249 | + * @static |
|
250 | + * @access public |
|
251 | + * @return array |
|
252 | + */ |
|
253 | + public static function get_post_types() { |
|
254 | + $items = []; |
|
255 | + |
|
256 | + // Get the post types. |
|
257 | + $post_types = get_post_types( |
|
258 | + [ |
|
259 | + 'public' => true, |
|
260 | + ], |
|
261 | + 'objects' |
|
262 | + ); |
|
263 | + |
|
264 | + // Build the array. |
|
265 | + foreach ( $post_types as $post_type ) { |
|
266 | + $items[ $post_type->name ] = $post_type->labels->name; |
|
267 | + } |
|
268 | + |
|
269 | + return $items; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Get an array of terms from a taxonomy. |
|
274 | + * |
|
275 | + * @static |
|
276 | + * @access public |
|
277 | + * @param string|array $taxonomies See https://developer.wordpress.org/reference/functions/get_terms/ for details. |
|
278 | + * @return array |
|
279 | + */ |
|
280 | + public static function get_terms( $taxonomies ) { |
|
281 | + $items = []; |
|
282 | + |
|
283 | + // Get the post types. |
|
284 | + $terms = get_terms( $taxonomies ); |
|
285 | + |
|
286 | + // Build the array. |
|
287 | + foreach ( $terms as $term ) { |
|
288 | + $items[ $term->term_id ] = $term->name; |
|
289 | + } |
|
290 | + |
|
291 | + return $items; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Returns an array of navigation menus. |
|
296 | + * |
|
297 | + * @access public |
|
298 | + * @param string $value_field The value to be stored in options. Accepted values: id|slug. |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public static function get_nav_menus( $value_field = 'id' ) { |
|
302 | + $choices = []; |
|
303 | + $nav_menus = wp_get_nav_menus(); |
|
304 | + |
|
305 | + foreach ( $nav_menus as $term ) { |
|
306 | + $choices[ 'slug' === $value_field ? $term->slug : $term->term_id ] = $term->name; |
|
307 | + } |
|
308 | + |
|
309 | + return $choices; |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Gets an array of material-design colors. |
|
314 | + * |
|
315 | + * @static |
|
316 | + * @access public |
|
317 | + * @param string $context Allows us to get subsets of the palette. |
|
318 | + * @return array |
|
319 | + */ |
|
320 | + public static function get_material_design_colors( $context = 'primary' ) { |
|
321 | + return \Kirki\Util\MaterialColors::get_colors( $context ); |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get an array of all available dashicons. |
|
326 | + * |
|
327 | + * @static |
|
328 | + * @access public |
|
329 | + * @return array |
|
330 | + */ |
|
331 | + public static function get_dashicons() { |
|
332 | + if ( class_exists( '\Kirki\Util\Dashicons' ) ) { |
|
333 | + return \Kirki\Util\Dashicons::get_icons(); |
|
334 | + } |
|
335 | + return []; |
|
336 | + } |
|
337 | + |
|
338 | + /** |
|
339 | + * Compares the 2 values given the condition |
|
340 | + * |
|
341 | + * @param mixed $value1 The 1st value in the comparison. |
|
342 | + * @param mixed $value2 The 2nd value in the comparison. |
|
343 | + * @param string $operator The operator we'll use for the comparison. |
|
344 | + * @return boolean whether The comparison has succeded (true) or failed (false). |
|
345 | + */ |
|
346 | + public static function compare_values( $value1, $value2, $operator ) { |
|
347 | + if ( '===' === $operator ) { |
|
348 | + return $value1 === $value2; |
|
349 | + } |
|
350 | + if ( '!==' === $operator ) { |
|
351 | + return $value1 !== $value2; |
|
352 | + } |
|
353 | + if ( ( '!=' === $operator || 'not equal' === $operator ) ) { |
|
354 | + return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
|
355 | + } |
|
356 | + if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) { |
|
357 | + return $value2 >= $value1; |
|
358 | + } |
|
359 | + if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) { |
|
360 | + return $value2 <= $value1; |
|
361 | + } |
|
362 | + if ( ( '>' === $operator || 'greater' === $operator ) ) { |
|
363 | + return $value2 > $value1; |
|
364 | + } |
|
365 | + if ( ( '<' === $operator || 'smaller' === $operator ) ) { |
|
366 | + return $value2 < $value1; |
|
367 | + } |
|
368 | + if ( 'contains' === $operator || 'in' === $operator ) { |
|
369 | + if ( is_array( $value1 ) && is_array( $value2 ) ) { |
|
370 | + foreach ( $value2 as $val ) { |
|
371 | + if ( in_array( $val, $value1 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray |
|
372 | + return true; |
|
373 | + } |
|
374 | + } |
|
375 | + return false; |
|
376 | + } |
|
377 | + if ( is_array( $value1 ) && ! is_array( $value2 ) ) { |
|
378 | + return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
379 | + } |
|
380 | + if ( is_array( $value2 ) && ! is_array( $value1 ) ) { |
|
381 | + return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
382 | + } |
|
383 | + return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) ); |
|
384 | + } |
|
385 | + if ( 'does not contain' === $operator || 'not in' === $operator ) { |
|
386 | + return ! self::compare_values( $value1, $value2, $operator ); |
|
387 | + } |
|
388 | + return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Prepare PHP array to be used as JS object. |
|
393 | + * |
|
394 | + * @see See https://developer.wordpress.org/reference/classes/wp_scripts/localize/ |
|
395 | + * |
|
396 | + * @param array $values The data which can be either a single or multi-dimensional array. |
|
397 | + * @return array |
|
398 | + */ |
|
399 | + public static function prepare_php_array_for_js( $values ) { |
|
400 | + |
|
401 | + foreach ( $values as $key => $value ) { |
|
402 | + if ( ! is_scalar( $value ) ) { |
|
403 | + continue; |
|
404 | + } |
|
405 | + |
|
406 | + $values[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
407 | + } |
|
408 | + |
|
409 | + return $values; |
|
410 | + |
|
411 | + } |
|
412 | 412 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | namespace Kirki\Util; |
14 | 14 | |
15 | 15 | // Exit if accessed directly. |
16 | -if ( ! defined( 'ABSPATH' ) ) { |
|
16 | +if (!defined('ABSPATH')) { |
|
17 | 17 | exit; |
18 | 18 | } |
19 | 19 | |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | * @param array $array1 The second array. |
32 | 32 | * @return mixed |
33 | 33 | */ |
34 | - public static function array_replace_recursive( $array, $array1 ) { |
|
35 | - if ( function_exists( 'array_replace_recursive' ) ) { |
|
36 | - return array_replace_recursive( $array, $array1 ); |
|
34 | + public static function array_replace_recursive($array, $array1) { |
|
35 | + if (function_exists('array_replace_recursive')) { |
|
36 | + return array_replace_recursive($array, $array1); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | */ |
48 | 48 | $args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue |
49 | 49 | $array = $args[0]; |
50 | - if ( ! is_array( $array ) ) { |
|
50 | + if (!is_array($array)) { |
|
51 | 51 | return $array; |
52 | 52 | } |
53 | - $count = count( $args ); |
|
54 | - for ( $i = 1; $i < $count; $i++ ) { |
|
55 | - if ( is_array( $args[ $i ] ) ) { |
|
56 | - $array = self::recurse( $array, $args[ $i ] ); |
|
53 | + $count = count($args); |
|
54 | + for ($i = 1; $i < $count; $i++) { |
|
55 | + if (is_array($args[$i])) { |
|
56 | + $array = self::recurse($array, $args[$i]); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | return $array; |
@@ -68,19 +68,19 @@ discard block |
||
68 | 68 | * @param array $array1 The second array. |
69 | 69 | * @return array |
70 | 70 | */ |
71 | - public static function recurse( $array, $array1 ) { |
|
72 | - foreach ( $array1 as $key => $value ) { |
|
71 | + public static function recurse($array, $array1) { |
|
72 | + foreach ($array1 as $key => $value) { |
|
73 | 73 | |
74 | 74 | // Create new key in $array, if it is empty or not an array. |
75 | - if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) { |
|
76 | - $array[ $key ] = []; |
|
75 | + if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key]))) { |
|
76 | + $array[$key] = []; |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | // Overwrite the value in the base array. |
80 | - if ( is_array( $value ) ) { |
|
81 | - $value = self::recurse( $array[ $key ], $value ); |
|
80 | + if (is_array($value)) { |
|
81 | + $value = self::recurse($array[$key], $value); |
|
82 | 82 | } |
83 | - $array[ $key ] = $value; |
|
83 | + $array[$key] = $value; |
|
84 | 84 | } |
85 | 85 | return $array; |
86 | 86 | } |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | public static function init_filesystem() { |
96 | 96 | $credentials = []; |
97 | 97 | |
98 | - if ( ! defined( 'FS_METHOD' ) ) { |
|
99 | - define( 'FS_METHOD', 'direct' ); |
|
98 | + if (!defined('FS_METHOD')) { |
|
99 | + define('FS_METHOD', 'direct'); |
|
100 | 100 | } |
101 | 101 | |
102 | - $method = defined( 'FS_METHOD' ) ? FS_METHOD : false; |
|
102 | + $method = defined('FS_METHOD') ? FS_METHOD : false; |
|
103 | 103 | |
104 | - if ( 'ftpext' === $method ) { |
|
104 | + if ('ftpext' === $method) { |
|
105 | 105 | // If defined, set it to that, Else, set to NULL. |
106 | - $credentials['hostname'] = defined( 'FTP_HOST' ) ? preg_replace( '|\w+://|', '', FTP_HOST ) : null; |
|
107 | - $credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : null; |
|
108 | - $credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : null; |
|
106 | + $credentials['hostname'] = defined('FTP_HOST') ? preg_replace('|\w+://|', '', FTP_HOST) : null; |
|
107 | + $credentials['username'] = defined('FTP_USER') ? FTP_USER : null; |
|
108 | + $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : null; |
|
109 | 109 | |
110 | 110 | // Set FTP port. |
111 | - if ( strpos( $credentials['hostname'], ':' ) && null !== $credentials['hostname'] ) { |
|
112 | - list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 ); |
|
113 | - if ( ! is_numeric( $credentials['port'] ) ) { |
|
114 | - unset( $credentials['port'] ); |
|
111 | + if (strpos($credentials['hostname'], ':') && null !== $credentials['hostname']) { |
|
112 | + list($credentials['hostname'], $credentials['port']) = explode(':', $credentials['hostname'], 2); |
|
113 | + if (!is_numeric($credentials['port'])) { |
|
114 | + unset($credentials['port']); |
|
115 | 115 | } |
116 | 116 | } else { |
117 | - unset( $credentials['port'] ); |
|
117 | + unset($credentials['port']); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | // Set connection type. |
121 | - if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $method ) { |
|
121 | + if ((defined('FTP_SSL') && FTP_SSL) && 'ftpext' === $method) { |
|
122 | 122 | $credentials['connection_type'] = 'ftps'; |
123 | - } elseif ( ! array_filter( $credentials ) ) { |
|
123 | + } elseif (!array_filter($credentials)) { |
|
124 | 124 | $credentials['connection_type'] = null; |
125 | 125 | } else { |
126 | 126 | $credentials['connection_type'] = 'ftp'; |
@@ -130,9 +130,9 @@ discard block |
||
130 | 130 | // The WordPress filesystem. |
131 | 131 | global $wp_filesystem; |
132 | 132 | |
133 | - if ( empty( $wp_filesystem ) ) { |
|
134 | - require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
135 | - WP_Filesystem( $credentials ); |
|
133 | + if (empty($wp_filesystem)) { |
|
134 | + require_once wp_normalize_path(ABSPATH . '/wp-admin/includes/file.php'); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
135 | + WP_Filesystem($credentials); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | return $wp_filesystem; |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | * @param string $url URL to the image. |
148 | 148 | * @return int|string Numeric ID of the attachement. |
149 | 149 | */ |
150 | - public static function get_image_id( $url ) { |
|
150 | + public static function get_image_id($url) { |
|
151 | 151 | global $wpdb; |
152 | - if ( empty( $url ) ) { |
|
152 | + if (empty($url)) { |
|
153 | 153 | return 0; |
154 | 154 | } |
155 | 155 | |
156 | - $attachment = wp_cache_get( 'kirki_image_id_' . md5( $url ), null ); |
|
157 | - if ( false === $attachment ) { |
|
158 | - $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = %s;", $url ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
|
159 | - wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null ); |
|
156 | + $attachment = wp_cache_get('kirki_image_id_' . md5($url), null); |
|
157 | + if (false === $attachment) { |
|
158 | + $attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE guid = %s;", $url)); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery |
|
159 | + wp_cache_add('kirki_image_id_' . md5($url), $attachment, null); |
|
160 | 160 | } |
161 | 161 | |
162 | - if ( ! empty( $attachment ) ) { |
|
162 | + if (!empty($attachment)) { |
|
163 | 163 | return $attachment[0]; |
164 | 164 | } |
165 | 165 | return 0; |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | * @param string $url URL to the image. |
172 | 172 | * @return array |
173 | 173 | */ |
174 | - public static function get_image_from_url( $url ) { |
|
175 | - $image_id = self::get_image_id( $url ); |
|
176 | - $image = wp_get_attachment_image_src( $image_id, 'full' ); |
|
174 | + public static function get_image_from_url($url) { |
|
175 | + $image_id = self::get_image_id($url); |
|
176 | + $image = wp_get_attachment_image_src($image_id, 'full'); |
|
177 | 177 | |
178 | 178 | return [ |
179 | 179 | 'url' => $image[0], |
@@ -191,25 +191,25 @@ discard block |
||
191 | 191 | * @param array $args Define arguments for the get_posts function. |
192 | 192 | * @return array |
193 | 193 | */ |
194 | - public static function get_posts( $args ) { |
|
195 | - if ( is_string( $args ) ) { |
|
194 | + public static function get_posts($args) { |
|
195 | + if (is_string($args)) { |
|
196 | 196 | $args = add_query_arg( |
197 | 197 | [ |
198 | 198 | 'suppress_filters' => false, |
199 | 199 | ] |
200 | 200 | ); |
201 | - } elseif ( is_array( $args ) && ! isset( $args['suppress_filters'] ) ) { |
|
201 | + } elseif (is_array($args) && !isset($args['suppress_filters'])) { |
|
202 | 202 | $args['suppress_filters'] = false; |
203 | 203 | } |
204 | 204 | |
205 | 205 | // Get the posts. |
206 | 206 | // TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts. |
207 | - $posts = get_posts( $args ); |
|
207 | + $posts = get_posts($args); |
|
208 | 208 | |
209 | 209 | // Properly format the array. |
210 | 210 | $items = []; |
211 | - foreach ( $posts as $post ) { |
|
212 | - $items[ $post->ID ] = $post->post_title; |
|
211 | + foreach ($posts as $post) { |
|
212 | + $items[$post->ID] = $post->post_title; |
|
213 | 213 | } |
214 | 214 | wp_reset_postdata(); |
215 | 215 | |
@@ -234,10 +234,10 @@ discard block |
||
234 | 234 | ); |
235 | 235 | |
236 | 236 | // Build the array. |
237 | - foreach ( $taxonomies as $taxonomy ) { |
|
237 | + foreach ($taxonomies as $taxonomy) { |
|
238 | 238 | $id = $taxonomy; |
239 | - $taxonomy = get_taxonomy( $taxonomy ); |
|
240 | - $items[ $id ] = $taxonomy->labels->name; |
|
239 | + $taxonomy = get_taxonomy($taxonomy); |
|
240 | + $items[$id] = $taxonomy->labels->name; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | return $items; |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | ); |
263 | 263 | |
264 | 264 | // Build the array. |
265 | - foreach ( $post_types as $post_type ) { |
|
266 | - $items[ $post_type->name ] = $post_type->labels->name; |
|
265 | + foreach ($post_types as $post_type) { |
|
266 | + $items[$post_type->name] = $post_type->labels->name; |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | return $items; |
@@ -277,15 +277,15 @@ discard block |
||
277 | 277 | * @param string|array $taxonomies See https://developer.wordpress.org/reference/functions/get_terms/ for details. |
278 | 278 | * @return array |
279 | 279 | */ |
280 | - public static function get_terms( $taxonomies ) { |
|
280 | + public static function get_terms($taxonomies) { |
|
281 | 281 | $items = []; |
282 | 282 | |
283 | 283 | // Get the post types. |
284 | - $terms = get_terms( $taxonomies ); |
|
284 | + $terms = get_terms($taxonomies); |
|
285 | 285 | |
286 | 286 | // Build the array. |
287 | - foreach ( $terms as $term ) { |
|
288 | - $items[ $term->term_id ] = $term->name; |
|
287 | + foreach ($terms as $term) { |
|
288 | + $items[$term->term_id] = $term->name; |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | return $items; |
@@ -298,12 +298,12 @@ discard block |
||
298 | 298 | * @param string $value_field The value to be stored in options. Accepted values: id|slug. |
299 | 299 | * @return array |
300 | 300 | */ |
301 | - public static function get_nav_menus( $value_field = 'id' ) { |
|
301 | + public static function get_nav_menus($value_field = 'id') { |
|
302 | 302 | $choices = []; |
303 | 303 | $nav_menus = wp_get_nav_menus(); |
304 | 304 | |
305 | - foreach ( $nav_menus as $term ) { |
|
306 | - $choices[ 'slug' === $value_field ? $term->slug : $term->term_id ] = $term->name; |
|
305 | + foreach ($nav_menus as $term) { |
|
306 | + $choices['slug' === $value_field ? $term->slug : $term->term_id] = $term->name; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | return $choices; |
@@ -317,8 +317,8 @@ discard block |
||
317 | 317 | * @param string $context Allows us to get subsets of the palette. |
318 | 318 | * @return array |
319 | 319 | */ |
320 | - public static function get_material_design_colors( $context = 'primary' ) { |
|
321 | - return \Kirki\Util\MaterialColors::get_colors( $context ); |
|
320 | + public static function get_material_design_colors($context = 'primary') { |
|
321 | + return \Kirki\Util\MaterialColors::get_colors($context); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | * @return array |
330 | 330 | */ |
331 | 331 | public static function get_dashicons() { |
332 | - if ( class_exists( '\Kirki\Util\Dashicons' ) ) { |
|
332 | + if (class_exists('\Kirki\Util\Dashicons')) { |
|
333 | 333 | return \Kirki\Util\Dashicons::get_icons(); |
334 | 334 | } |
335 | 335 | return []; |
@@ -343,47 +343,47 @@ discard block |
||
343 | 343 | * @param string $operator The operator we'll use for the comparison. |
344 | 344 | * @return boolean whether The comparison has succeded (true) or failed (false). |
345 | 345 | */ |
346 | - public static function compare_values( $value1, $value2, $operator ) { |
|
347 | - if ( '===' === $operator ) { |
|
346 | + public static function compare_values($value1, $value2, $operator) { |
|
347 | + if ('===' === $operator) { |
|
348 | 348 | return $value1 === $value2; |
349 | 349 | } |
350 | - if ( '!==' === $operator ) { |
|
350 | + if ('!==' === $operator) { |
|
351 | 351 | return $value1 !== $value2; |
352 | 352 | } |
353 | - if ( ( '!=' === $operator || 'not equal' === $operator ) ) { |
|
353 | + if (('!=' === $operator || 'not equal' === $operator)) { |
|
354 | 354 | return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
355 | 355 | } |
356 | - if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) { |
|
356 | + if (('>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator)) { |
|
357 | 357 | return $value2 >= $value1; |
358 | 358 | } |
359 | - if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) { |
|
359 | + if (('<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator)) { |
|
360 | 360 | return $value2 <= $value1; |
361 | 361 | } |
362 | - if ( ( '>' === $operator || 'greater' === $operator ) ) { |
|
362 | + if (('>' === $operator || 'greater' === $operator)) { |
|
363 | 363 | return $value2 > $value1; |
364 | 364 | } |
365 | - if ( ( '<' === $operator || 'smaller' === $operator ) ) { |
|
365 | + if (('<' === $operator || 'smaller' === $operator)) { |
|
366 | 366 | return $value2 < $value1; |
367 | 367 | } |
368 | - if ( 'contains' === $operator || 'in' === $operator ) { |
|
369 | - if ( is_array( $value1 ) && is_array( $value2 ) ) { |
|
370 | - foreach ( $value2 as $val ) { |
|
371 | - if ( in_array( $val, $value1 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray |
|
368 | + if ('contains' === $operator || 'in' === $operator) { |
|
369 | + if (is_array($value1) && is_array($value2)) { |
|
370 | + foreach ($value2 as $val) { |
|
371 | + if (in_array($val, $value1)) { // phpcs:ignore WordPress.PHP.StrictInArray |
|
372 | 372 | return true; |
373 | 373 | } |
374 | 374 | } |
375 | 375 | return false; |
376 | 376 | } |
377 | - if ( is_array( $value1 ) && ! is_array( $value2 ) ) { |
|
378 | - return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
377 | + if (is_array($value1) && !is_array($value2)) { |
|
378 | + return in_array($value2, $value1); // phpcs:ignore WordPress.PHP.StrictInArray |
|
379 | 379 | } |
380 | - if ( is_array( $value2 ) && ! is_array( $value1 ) ) { |
|
381 | - return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray |
|
380 | + if (is_array($value2) && !is_array($value1)) { |
|
381 | + return in_array($value1, $value2); // phpcs:ignore WordPress.PHP.StrictInArray |
|
382 | 382 | } |
383 | - return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) ); |
|
383 | + return (false !== strrpos($value1, $value2) || false !== strpos($value2, $value1)); |
|
384 | 384 | } |
385 | - if ( 'does not contain' === $operator || 'not in' === $operator ) { |
|
386 | - return ! self::compare_values( $value1, $value2, $operator ); |
|
385 | + if ('does not contain' === $operator || 'not in' === $operator) { |
|
386 | + return !self::compare_values($value1, $value2, $operator); |
|
387 | 387 | } |
388 | 388 | return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons |
389 | 389 | } |
@@ -396,14 +396,14 @@ discard block |
||
396 | 396 | * @param array $values The data which can be either a single or multi-dimensional array. |
397 | 397 | * @return array |
398 | 398 | */ |
399 | - public static function prepare_php_array_for_js( $values ) { |
|
399 | + public static function prepare_php_array_for_js($values) { |
|
400 | 400 | |
401 | - foreach ( $values as $key => $value ) { |
|
402 | - if ( ! is_scalar( $value ) ) { |
|
401 | + foreach ($values as $key => $value) { |
|
402 | + if (!is_scalar($value)) { |
|
403 | 403 | continue; |
404 | 404 | } |
405 | 405 | |
406 | - $values[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
406 | + $values[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | return $values; |
@@ -17,59 +17,59 @@ |
||
17 | 17 | */ |
18 | 18 | class Site_Option extends \WP_Customize_Setting { |
19 | 19 | |
20 | - /** |
|
21 | - * Type of customize settings. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 3.0.0 |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $type = 'site_option'; |
|
20 | + /** |
|
21 | + * Type of customize settings. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 3.0.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $type = 'site_option'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Get the root value for a setting, especially for multidimensional ones. |
|
31 | - * |
|
32 | - * @access protected |
|
33 | - * @since 3.0.0 |
|
34 | - * @param mixed $default Value to return if root does not exist. |
|
35 | - * @return mixed |
|
36 | - */ |
|
37 | - protected function get_root_value( $default = null ) { |
|
38 | - return get_site_option( $this->id_data['base'], $default ); |
|
39 | - } |
|
29 | + /** |
|
30 | + * Get the root value for a setting, especially for multidimensional ones. |
|
31 | + * |
|
32 | + * @access protected |
|
33 | + * @since 3.0.0 |
|
34 | + * @param mixed $default Value to return if root does not exist. |
|
35 | + * @return mixed |
|
36 | + */ |
|
37 | + protected function get_root_value( $default = null ) { |
|
38 | + return get_site_option( $this->id_data['base'], $default ); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Set the root value for a setting, especially for multidimensional ones. |
|
43 | - * |
|
44 | - * @access protected |
|
45 | - * @since 3.0.0 |
|
46 | - * @param mixed $value Value to set as root of multidimensional setting. |
|
47 | - * @return bool Whether the multidimensional root was updated successfully. |
|
48 | - */ |
|
49 | - protected function set_root_value( $value ) { |
|
50 | - return update_site_option( $this->id_data['base'], $value ); |
|
51 | - } |
|
41 | + /** |
|
42 | + * Set the root value for a setting, especially for multidimensional ones. |
|
43 | + * |
|
44 | + * @access protected |
|
45 | + * @since 3.0.0 |
|
46 | + * @param mixed $value Value to set as root of multidimensional setting. |
|
47 | + * @return bool Whether the multidimensional root was updated successfully. |
|
48 | + */ |
|
49 | + protected function set_root_value( $value ) { |
|
50 | + return update_site_option( $this->id_data['base'], $value ); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Save the value of the setting, using the related API. |
|
55 | - * |
|
56 | - * @access protected |
|
57 | - * @since 3.0.0 |
|
58 | - * @param mixed $value The value to update. |
|
59 | - * @return bool The result of saving the value. |
|
60 | - */ |
|
61 | - protected function update( $value ) { |
|
62 | - return $this->set_root_value( $value ); |
|
63 | - } |
|
53 | + /** |
|
54 | + * Save the value of the setting, using the related API. |
|
55 | + * |
|
56 | + * @access protected |
|
57 | + * @since 3.0.0 |
|
58 | + * @param mixed $value The value to update. |
|
59 | + * @return bool The result of saving the value. |
|
60 | + */ |
|
61 | + protected function update( $value ) { |
|
62 | + return $this->set_root_value( $value ); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Fetch the value of the setting. |
|
67 | - * |
|
68 | - * @access protected |
|
69 | - * @since 3.0.0 |
|
70 | - * @return mixed The value. |
|
71 | - */ |
|
72 | - public function value() { |
|
73 | - return $this->get_root_value( $this->default ); |
|
74 | - } |
|
65 | + /** |
|
66 | + * Fetch the value of the setting. |
|
67 | + * |
|
68 | + * @access protected |
|
69 | + * @since 3.0.0 |
|
70 | + * @return mixed The value. |
|
71 | + */ |
|
72 | + public function value() { |
|
73 | + return $this->get_root_value( $this->default ); |
|
74 | + } |
|
75 | 75 | } |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @param mixed $default Value to return if root does not exist. |
35 | 35 | * @return mixed |
36 | 36 | */ |
37 | - protected function get_root_value( $default = null ) { |
|
38 | - return get_site_option( $this->id_data['base'], $default ); |
|
37 | + protected function get_root_value($default = null) { |
|
38 | + return get_site_option($this->id_data['base'], $default); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param mixed $value Value to set as root of multidimensional setting. |
47 | 47 | * @return bool Whether the multidimensional root was updated successfully. |
48 | 48 | */ |
49 | - protected function set_root_value( $value ) { |
|
50 | - return update_site_option( $this->id_data['base'], $value ); |
|
49 | + protected function set_root_value($value) { |
|
50 | + return update_site_option($this->id_data['base'], $value); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -58,8 +58,8 @@ discard block |
||
58 | 58 | * @param mixed $value The value to update. |
59 | 59 | * @return bool The result of saving the value. |
60 | 60 | */ |
61 | - protected function update( $value ) { |
|
62 | - return $this->set_root_value( $value ); |
|
61 | + protected function update($value) { |
|
62 | + return $this->set_root_value($value); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -70,6 +70,6 @@ discard block |
||
70 | 70 | * @return mixed The value. |
71 | 71 | */ |
72 | 72 | public function value() { |
73 | - return $this->get_root_value( $this->default ); |
|
73 | + return $this->get_root_value($this->default); |
|
74 | 74 | } |
75 | 75 | } |
@@ -17,79 +17,79 @@ |
||
17 | 17 | */ |
18 | 18 | class User_Meta extends \WP_Customize_Setting { |
19 | 19 | |
20 | - /** |
|
21 | - * Type of customize settings. |
|
22 | - * |
|
23 | - * @access public |
|
24 | - * @since 3.0.0 |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - public $type = 'user_meta'; |
|
20 | + /** |
|
21 | + * Type of customize settings. |
|
22 | + * |
|
23 | + * @access public |
|
24 | + * @since 3.0.0 |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + public $type = 'user_meta'; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Get the root value for a setting, especially for multidimensional ones. |
|
31 | - * |
|
32 | - * @access protected |
|
33 | - * @since 3.0.0 |
|
34 | - * @param mixed $default Value to return if root does not exist. |
|
35 | - * @return mixed |
|
36 | - */ |
|
37 | - protected function get_root_value( $default = null ) { |
|
38 | - $id_base = $this->id_data['base']; |
|
29 | + /** |
|
30 | + * Get the root value for a setting, especially for multidimensional ones. |
|
31 | + * |
|
32 | + * @access protected |
|
33 | + * @since 3.0.0 |
|
34 | + * @param mixed $default Value to return if root does not exist. |
|
35 | + * @return mixed |
|
36 | + */ |
|
37 | + protected function get_root_value( $default = null ) { |
|
38 | + $id_base = $this->id_data['base']; |
|
39 | 39 | |
40 | - // Get all user-meta. |
|
41 | - // We'll use this to check if the value is set or not, |
|
42 | - // in order to figure out if we need to return the default value. |
|
43 | - $user_meta = get_user_meta( get_current_user_id() ); |
|
40 | + // Get all user-meta. |
|
41 | + // We'll use this to check if the value is set or not, |
|
42 | + // in order to figure out if we need to return the default value. |
|
43 | + $user_meta = get_user_meta( get_current_user_id() ); |
|
44 | 44 | |
45 | - // Get the single meta. |
|
46 | - $single_meta = get_user_meta( get_current_user_id(), $id_base, true ); |
|
45 | + // Get the single meta. |
|
46 | + $single_meta = get_user_meta( get_current_user_id(), $id_base, true ); |
|
47 | 47 | |
48 | - if ( isset( $user_meta[ $id_base ] ) ) { |
|
49 | - return $single_meta; |
|
50 | - } |
|
51 | - return $default; |
|
52 | - } |
|
48 | + if ( isset( $user_meta[ $id_base ] ) ) { |
|
49 | + return $single_meta; |
|
50 | + } |
|
51 | + return $default; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Set the root value for a setting, especially for multidimensional ones. |
|
56 | - * |
|
57 | - * @access protected |
|
58 | - * @since 3.0.0 |
|
59 | - * @param mixed $value Value to set as root of multidimensional setting. |
|
60 | - * @return bool Whether the multidimensional root was updated successfully. |
|
61 | - */ |
|
62 | - protected function set_root_value( $value ) { |
|
63 | - $id_base = $this->id_data['base']; |
|
54 | + /** |
|
55 | + * Set the root value for a setting, especially for multidimensional ones. |
|
56 | + * |
|
57 | + * @access protected |
|
58 | + * @since 3.0.0 |
|
59 | + * @param mixed $value Value to set as root of multidimensional setting. |
|
60 | + * @return bool Whether the multidimensional root was updated successfully. |
|
61 | + */ |
|
62 | + protected function set_root_value( $value ) { |
|
63 | + $id_base = $this->id_data['base']; |
|
64 | 64 | |
65 | - // First delete the current user-meta. |
|
66 | - // We're doing this to avoid duplicate entries. |
|
67 | - delete_user_meta( get_current_user_id(), $id_base ); |
|
65 | + // First delete the current user-meta. |
|
66 | + // We're doing this to avoid duplicate entries. |
|
67 | + delete_user_meta( get_current_user_id(), $id_base ); |
|
68 | 68 | |
69 | - // Update the user-meta. |
|
70 | - return update_user_meta( get_current_user_id(), $id_base, $value ); |
|
71 | - } |
|
69 | + // Update the user-meta. |
|
70 | + return update_user_meta( get_current_user_id(), $id_base, $value ); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Save the value of the setting, using the related API. |
|
75 | - * |
|
76 | - * @access protected |
|
77 | - * @since 3.0.0 |
|
78 | - * @param mixed $value The value to update. |
|
79 | - * @return bool The result of saving the value. |
|
80 | - */ |
|
81 | - protected function update( $value ) { |
|
82 | - return $this->set_root_value( $value ); |
|
83 | - } |
|
73 | + /** |
|
74 | + * Save the value of the setting, using the related API. |
|
75 | + * |
|
76 | + * @access protected |
|
77 | + * @since 3.0.0 |
|
78 | + * @param mixed $value The value to update. |
|
79 | + * @return bool The result of saving the value. |
|
80 | + */ |
|
81 | + protected function update( $value ) { |
|
82 | + return $this->set_root_value( $value ); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Fetch the value of the setting. |
|
87 | - * |
|
88 | - * @access protected |
|
89 | - * @since 3.0.0 |
|
90 | - * @return mixed The value. |
|
91 | - */ |
|
92 | - public function value() { |
|
93 | - return $this->get_root_value( $this->default ); |
|
94 | - } |
|
85 | + /** |
|
86 | + * Fetch the value of the setting. |
|
87 | + * |
|
88 | + * @access protected |
|
89 | + * @since 3.0.0 |
|
90 | + * @return mixed The value. |
|
91 | + */ |
|
92 | + public function value() { |
|
93 | + return $this->get_root_value( $this->default ); |
|
94 | + } |
|
95 | 95 | } |
@@ -34,18 +34,18 @@ discard block |
||
34 | 34 | * @param mixed $default Value to return if root does not exist. |
35 | 35 | * @return mixed |
36 | 36 | */ |
37 | - protected function get_root_value( $default = null ) { |
|
37 | + protected function get_root_value($default = null) { |
|
38 | 38 | $id_base = $this->id_data['base']; |
39 | 39 | |
40 | 40 | // Get all user-meta. |
41 | 41 | // We'll use this to check if the value is set or not, |
42 | 42 | // in order to figure out if we need to return the default value. |
43 | - $user_meta = get_user_meta( get_current_user_id() ); |
|
43 | + $user_meta = get_user_meta(get_current_user_id()); |
|
44 | 44 | |
45 | 45 | // Get the single meta. |
46 | - $single_meta = get_user_meta( get_current_user_id(), $id_base, true ); |
|
46 | + $single_meta = get_user_meta(get_current_user_id(), $id_base, true); |
|
47 | 47 | |
48 | - if ( isset( $user_meta[ $id_base ] ) ) { |
|
48 | + if (isset($user_meta[$id_base])) { |
|
49 | 49 | return $single_meta; |
50 | 50 | } |
51 | 51 | return $default; |
@@ -59,15 +59,15 @@ discard block |
||
59 | 59 | * @param mixed $value Value to set as root of multidimensional setting. |
60 | 60 | * @return bool Whether the multidimensional root was updated successfully. |
61 | 61 | */ |
62 | - protected function set_root_value( $value ) { |
|
62 | + protected function set_root_value($value) { |
|
63 | 63 | $id_base = $this->id_data['base']; |
64 | 64 | |
65 | 65 | // First delete the current user-meta. |
66 | 66 | // We're doing this to avoid duplicate entries. |
67 | - delete_user_meta( get_current_user_id(), $id_base ); |
|
67 | + delete_user_meta(get_current_user_id(), $id_base); |
|
68 | 68 | |
69 | 69 | // Update the user-meta. |
70 | - return update_user_meta( get_current_user_id(), $id_base, $value ); |
|
70 | + return update_user_meta(get_current_user_id(), $id_base, $value); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | * @param mixed $value The value to update. |
79 | 79 | * @return bool The result of saving the value. |
80 | 80 | */ |
81 | - protected function update( $value ) { |
|
82 | - return $this->set_root_value( $value ); |
|
81 | + protected function update($value) { |
|
82 | + return $this->set_root_value($value); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -90,6 +90,6 @@ discard block |
||
90 | 90 | * @return mixed The value. |
91 | 91 | */ |
92 | 92 | public function value() { |
93 | - return $this->get_root_value( $this->default ); |
|
93 | + return $this->get_root_value($this->default); |
|
94 | 94 | } |
95 | 95 | } |
@@ -17,204 +17,204 @@ |
||
17 | 17 | */ |
18 | 18 | class Util { |
19 | 19 | |
20 | - /** |
|
21 | - * Fields containing variables. |
|
22 | - * |
|
23 | - * @static |
|
24 | - * @access private |
|
25 | - * @since 4.0 |
|
26 | - * @var array |
|
27 | - */ |
|
28 | - private $variables_fields = []; |
|
29 | - |
|
30 | - /** |
|
31 | - * Constructor. |
|
32 | - * |
|
33 | - * @since 3.0.9 |
|
34 | - * @access public |
|
35 | - */ |
|
36 | - public function __construct() { |
|
37 | - add_filter( 'http_request_args', [ $this, 'http_request' ], 10, 2 ); |
|
38 | - add_action( 'kirki_field_init', [ $this, 'field_init_variables' ], 10, 2 ); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Determine if Kirki is installed as a plugin. |
|
43 | - * |
|
44 | - * @static |
|
45 | - * @access public |
|
46 | - * @since 3.0.0 |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - public static function is_plugin() { |
|
50 | - $is_plugin = false; |
|
51 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
52 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
53 | - } |
|
54 | - |
|
55 | - // Get all plugins. |
|
56 | - $plugins = get_plugins(); |
|
57 | - $_plugin = ''; |
|
58 | - foreach ( $plugins as $plugin => $args ) { |
|
59 | - if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { |
|
60 | - $is_plugin = true; |
|
61 | - $_plugin = $plugin; |
|
62 | - } |
|
63 | - } |
|
64 | - |
|
65 | - // No need to proceed any further if Kirki wasn't found in the list of plugins. |
|
66 | - if ( ! $is_plugin ) { |
|
67 | - return false; |
|
68 | - } |
|
69 | - |
|
70 | - // Make sure the is_plugins_loaded function is loaded. |
|
71 | - include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
72 | - |
|
73 | - // Extra logic in case the plugin is installed but not activated. |
|
74 | - if ( $_plugin && is_plugin_inactive( $_plugin ) ) { |
|
75 | - return false; |
|
76 | - } |
|
77 | - return $is_plugin; |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Add fields with variables to self::$variables_fields. |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @since 4.0 |
|
85 | - * @param array $args The field args. |
|
86 | - * @param Object $object The field object. |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public function field_init_variables( $args, $object ) { |
|
90 | - if ( isset( $args['variables'] ) ) { |
|
91 | - self::$variables_fields[] = $args; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Build the variables. |
|
97 | - * |
|
98 | - * @static |
|
99 | - * @access public |
|
100 | - * @since 3.0.9 |
|
101 | - * @return array Formatted as array( 'variable-name' => value ). |
|
102 | - */ |
|
103 | - public static function get_variables() { |
|
104 | - |
|
105 | - $variables = []; |
|
106 | - $fields = self::$variables_fields; |
|
107 | - |
|
108 | - /** |
|
109 | - * Compatibility with Kirki v3.x API. |
|
110 | - * If the Kirki class exists, check for fields inside it |
|
111 | - * and add them to our fields array. |
|
112 | - */ |
|
113 | - if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
114 | - $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
115 | - } |
|
116 | - |
|
117 | - // Loop through all fields. |
|
118 | - foreach ( $fields as $field ) { |
|
119 | - |
|
120 | - // Skip if this field doesn't have variables. |
|
121 | - if ( ! isset( $field['variables'] ) || ! $field['variables'] || empty( $field['variables'] ) ) { |
|
122 | - continue; |
|
123 | - } |
|
124 | - |
|
125 | - $option_type = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod'; |
|
126 | - $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; |
|
127 | - $value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $field['settings'], $default, $option_type ); |
|
128 | - |
|
129 | - // Loop through the array of variables. |
|
130 | - foreach ( $field['variables'] as $field_variable ) { |
|
131 | - |
|
132 | - // Is the variable ['name'] defined? If yes, then we can proceed. |
|
133 | - if ( isset( $field_variable['name'] ) ) { |
|
134 | - |
|
135 | - // Do we have a callback function defined? If not then set $variable_callback to false. |
|
136 | - $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; |
|
137 | - |
|
138 | - /** |
|
139 | - * If we have a variable_callback defined then get the value of the option |
|
140 | - * and run it through the callback function. |
|
141 | - * If no callback is defined (false) then just get the value. |
|
142 | - */ |
|
143 | - $variables[ $field_variable['name'] ] = $value; |
|
144 | - if ( $variable_callback ) { |
|
145 | - $variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], $value ); |
|
146 | - } |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - |
|
151 | - // Pass the variables through a filter ('kirki_variable') and return the array of variables. |
|
152 | - return apply_filters( 'kirki_variable', $variables ); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * HTTP Request injection. |
|
157 | - * |
|
158 | - * @access public |
|
159 | - * @since 3.0.0 |
|
160 | - * @param array $request The request params. |
|
161 | - * @param string $url The request URL. |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function http_request( $request = [], $url = '' ) { |
|
165 | - |
|
166 | - // Early exit if installed as a plugin or not a request to wordpress.org, |
|
167 | - // or finally if we don't have everything we need. |
|
168 | - if ( |
|
169 | - self::is_plugin() || |
|
170 | - false === strpos( $url, 'wordpress.org' ) || ( |
|
171 | - ! isset( $request['body'] ) || |
|
172 | - ! isset( $request['body']['plugins'] ) || |
|
173 | - ! isset( $request['body']['translations'] ) || |
|
174 | - ! isset( $request['body']['locale'] ) || |
|
175 | - ! isset( $request['body']['all'] ) |
|
176 | - ) |
|
177 | - ) { |
|
178 | - return $request; |
|
179 | - } |
|
180 | - |
|
181 | - $plugins = json_decode( $request['body']['plugins'], true ); |
|
182 | - if ( ! isset( $plugins['plugins'] ) ) { |
|
183 | - return $request; |
|
184 | - } |
|
185 | - $exists = false; |
|
186 | - foreach ( $plugins['plugins'] as $plugin ) { |
|
187 | - if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) { |
|
188 | - $exists = true; |
|
189 | - } |
|
190 | - } |
|
191 | - // Inject data. |
|
192 | - if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) { |
|
193 | - $plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE ); |
|
194 | - } |
|
195 | - $request['body']['plugins'] = wp_json_encode( $plugins ); |
|
196 | - return $request; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns the $wp_version. |
|
201 | - * |
|
202 | - * @static |
|
203 | - * @access public |
|
204 | - * @since 3.0.12 |
|
205 | - * @param string $context Use 'minor' or 'major'. |
|
206 | - * @return int|string Returns integer when getting the 'major' version. |
|
207 | - * Returns string when getting the 'minor' version. |
|
208 | - */ |
|
209 | - public static function get_wp_version( $context = 'minor' ) { |
|
210 | - global $wp_version; |
|
211 | - |
|
212 | - // We only need the major version. |
|
213 | - if ( 'major' === $context ) { |
|
214 | - $version_parts = explode( '.', $wp_version ); |
|
215 | - return $version_parts[0]; |
|
216 | - } |
|
217 | - |
|
218 | - return $wp_version; |
|
219 | - } |
|
20 | + /** |
|
21 | + * Fields containing variables. |
|
22 | + * |
|
23 | + * @static |
|
24 | + * @access private |
|
25 | + * @since 4.0 |
|
26 | + * @var array |
|
27 | + */ |
|
28 | + private $variables_fields = []; |
|
29 | + |
|
30 | + /** |
|
31 | + * Constructor. |
|
32 | + * |
|
33 | + * @since 3.0.9 |
|
34 | + * @access public |
|
35 | + */ |
|
36 | + public function __construct() { |
|
37 | + add_filter( 'http_request_args', [ $this, 'http_request' ], 10, 2 ); |
|
38 | + add_action( 'kirki_field_init', [ $this, 'field_init_variables' ], 10, 2 ); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Determine if Kirki is installed as a plugin. |
|
43 | + * |
|
44 | + * @static |
|
45 | + * @access public |
|
46 | + * @since 3.0.0 |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + public static function is_plugin() { |
|
50 | + $is_plugin = false; |
|
51 | + if ( ! function_exists( 'get_plugins' ) ) { |
|
52 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
53 | + } |
|
54 | + |
|
55 | + // Get all plugins. |
|
56 | + $plugins = get_plugins(); |
|
57 | + $_plugin = ''; |
|
58 | + foreach ( $plugins as $plugin => $args ) { |
|
59 | + if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { |
|
60 | + $is_plugin = true; |
|
61 | + $_plugin = $plugin; |
|
62 | + } |
|
63 | + } |
|
64 | + |
|
65 | + // No need to proceed any further if Kirki wasn't found in the list of plugins. |
|
66 | + if ( ! $is_plugin ) { |
|
67 | + return false; |
|
68 | + } |
|
69 | + |
|
70 | + // Make sure the is_plugins_loaded function is loaded. |
|
71 | + include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
|
72 | + |
|
73 | + // Extra logic in case the plugin is installed but not activated. |
|
74 | + if ( $_plugin && is_plugin_inactive( $_plugin ) ) { |
|
75 | + return false; |
|
76 | + } |
|
77 | + return $is_plugin; |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Add fields with variables to self::$variables_fields. |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @since 4.0 |
|
85 | + * @param array $args The field args. |
|
86 | + * @param Object $object The field object. |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public function field_init_variables( $args, $object ) { |
|
90 | + if ( isset( $args['variables'] ) ) { |
|
91 | + self::$variables_fields[] = $args; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Build the variables. |
|
97 | + * |
|
98 | + * @static |
|
99 | + * @access public |
|
100 | + * @since 3.0.9 |
|
101 | + * @return array Formatted as array( 'variable-name' => value ). |
|
102 | + */ |
|
103 | + public static function get_variables() { |
|
104 | + |
|
105 | + $variables = []; |
|
106 | + $fields = self::$variables_fields; |
|
107 | + |
|
108 | + /** |
|
109 | + * Compatibility with Kirki v3.x API. |
|
110 | + * If the Kirki class exists, check for fields inside it |
|
111 | + * and add them to our fields array. |
|
112 | + */ |
|
113 | + if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
114 | + $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
115 | + } |
|
116 | + |
|
117 | + // Loop through all fields. |
|
118 | + foreach ( $fields as $field ) { |
|
119 | + |
|
120 | + // Skip if this field doesn't have variables. |
|
121 | + if ( ! isset( $field['variables'] ) || ! $field['variables'] || empty( $field['variables'] ) ) { |
|
122 | + continue; |
|
123 | + } |
|
124 | + |
|
125 | + $option_type = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod'; |
|
126 | + $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; |
|
127 | + $value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $field['settings'], $default, $option_type ); |
|
128 | + |
|
129 | + // Loop through the array of variables. |
|
130 | + foreach ( $field['variables'] as $field_variable ) { |
|
131 | + |
|
132 | + // Is the variable ['name'] defined? If yes, then we can proceed. |
|
133 | + if ( isset( $field_variable['name'] ) ) { |
|
134 | + |
|
135 | + // Do we have a callback function defined? If not then set $variable_callback to false. |
|
136 | + $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; |
|
137 | + |
|
138 | + /** |
|
139 | + * If we have a variable_callback defined then get the value of the option |
|
140 | + * and run it through the callback function. |
|
141 | + * If no callback is defined (false) then just get the value. |
|
142 | + */ |
|
143 | + $variables[ $field_variable['name'] ] = $value; |
|
144 | + if ( $variable_callback ) { |
|
145 | + $variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], $value ); |
|
146 | + } |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + |
|
151 | + // Pass the variables through a filter ('kirki_variable') and return the array of variables. |
|
152 | + return apply_filters( 'kirki_variable', $variables ); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * HTTP Request injection. |
|
157 | + * |
|
158 | + * @access public |
|
159 | + * @since 3.0.0 |
|
160 | + * @param array $request The request params. |
|
161 | + * @param string $url The request URL. |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function http_request( $request = [], $url = '' ) { |
|
165 | + |
|
166 | + // Early exit if installed as a plugin or not a request to wordpress.org, |
|
167 | + // or finally if we don't have everything we need. |
|
168 | + if ( |
|
169 | + self::is_plugin() || |
|
170 | + false === strpos( $url, 'wordpress.org' ) || ( |
|
171 | + ! isset( $request['body'] ) || |
|
172 | + ! isset( $request['body']['plugins'] ) || |
|
173 | + ! isset( $request['body']['translations'] ) || |
|
174 | + ! isset( $request['body']['locale'] ) || |
|
175 | + ! isset( $request['body']['all'] ) |
|
176 | + ) |
|
177 | + ) { |
|
178 | + return $request; |
|
179 | + } |
|
180 | + |
|
181 | + $plugins = json_decode( $request['body']['plugins'], true ); |
|
182 | + if ( ! isset( $plugins['plugins'] ) ) { |
|
183 | + return $request; |
|
184 | + } |
|
185 | + $exists = false; |
|
186 | + foreach ( $plugins['plugins'] as $plugin ) { |
|
187 | + if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) { |
|
188 | + $exists = true; |
|
189 | + } |
|
190 | + } |
|
191 | + // Inject data. |
|
192 | + if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) { |
|
193 | + $plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE ); |
|
194 | + } |
|
195 | + $request['body']['plugins'] = wp_json_encode( $plugins ); |
|
196 | + return $request; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns the $wp_version. |
|
201 | + * |
|
202 | + * @static |
|
203 | + * @access public |
|
204 | + * @since 3.0.12 |
|
205 | + * @param string $context Use 'minor' or 'major'. |
|
206 | + * @return int|string Returns integer when getting the 'major' version. |
|
207 | + * Returns string when getting the 'minor' version. |
|
208 | + */ |
|
209 | + public static function get_wp_version( $context = 'minor' ) { |
|
210 | + global $wp_version; |
|
211 | + |
|
212 | + // We only need the major version. |
|
213 | + if ( 'major' === $context ) { |
|
214 | + $version_parts = explode( '.', $wp_version ); |
|
215 | + return $version_parts[0]; |
|
216 | + } |
|
217 | + |
|
218 | + return $wp_version; |
|
219 | + } |
|
220 | 220 | } |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | * @access public |
35 | 35 | */ |
36 | 36 | public function __construct() { |
37 | - add_filter( 'http_request_args', [ $this, 'http_request' ], 10, 2 ); |
|
38 | - add_action( 'kirki_field_init', [ $this, 'field_init_variables' ], 10, 2 ); |
|
37 | + add_filter('http_request_args', [$this, 'http_request'], 10, 2); |
|
38 | + add_action('kirki_field_init', [$this, 'field_init_variables'], 10, 2); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -48,22 +48,22 @@ discard block |
||
48 | 48 | */ |
49 | 49 | public static function is_plugin() { |
50 | 50 | $is_plugin = false; |
51 | - if ( ! function_exists( 'get_plugins' ) ) { |
|
51 | + if (!function_exists('get_plugins')) { |
|
52 | 52 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
53 | 53 | } |
54 | 54 | |
55 | 55 | // Get all plugins. |
56 | 56 | $plugins = get_plugins(); |
57 | 57 | $_plugin = ''; |
58 | - foreach ( $plugins as $plugin => $args ) { |
|
59 | - if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) { |
|
58 | + foreach ($plugins as $plugin => $args) { |
|
59 | + if (!$is_plugin && isset($args['Name']) && ('Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'])) { |
|
60 | 60 | $is_plugin = true; |
61 | 61 | $_plugin = $plugin; |
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | 65 | // No need to proceed any further if Kirki wasn't found in the list of plugins. |
66 | - if ( ! $is_plugin ) { |
|
66 | + if (!$is_plugin) { |
|
67 | 67 | return false; |
68 | 68 | } |
69 | 69 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude |
72 | 72 | |
73 | 73 | // Extra logic in case the plugin is installed but not activated. |
74 | - if ( $_plugin && is_plugin_inactive( $_plugin ) ) { |
|
74 | + if ($_plugin && is_plugin_inactive($_plugin)) { |
|
75 | 75 | return false; |
76 | 76 | } |
77 | 77 | return $is_plugin; |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @param Object $object The field object. |
87 | 87 | * @return void |
88 | 88 | */ |
89 | - public function field_init_variables( $args, $object ) { |
|
90 | - if ( isset( $args['variables'] ) ) { |
|
89 | + public function field_init_variables($args, $object) { |
|
90 | + if (isset($args['variables'])) { |
|
91 | 91 | self::$variables_fields[] = $args; |
92 | 92 | } |
93 | 93 | } |
@@ -110,46 +110,46 @@ discard block |
||
110 | 110 | * If the Kirki class exists, check for fields inside it |
111 | 111 | * and add them to our fields array. |
112 | 112 | */ |
113 | - if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) { |
|
114 | - $fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields ); |
|
113 | + if (class_exists('\Kirki\Compatibility\Kirki')) { |
|
114 | + $fields = array_merge(\Kirki\Compatibility\Kirki::$fields, $fields); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Loop through all fields. |
118 | - foreach ( $fields as $field ) { |
|
118 | + foreach ($fields as $field) { |
|
119 | 119 | |
120 | 120 | // Skip if this field doesn't have variables. |
121 | - if ( ! isset( $field['variables'] ) || ! $field['variables'] || empty( $field['variables'] ) ) { |
|
121 | + if (!isset($field['variables']) || !$field['variables'] || empty($field['variables'])) { |
|
122 | 122 | continue; |
123 | 123 | } |
124 | 124 | |
125 | - $option_type = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod'; |
|
126 | - $default = ( isset( $field['default'] ) ) ? $field['default'] : ''; |
|
127 | - $value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $field['settings'], $default, $option_type ); |
|
125 | + $option_type = (isset($field['option_type'])) ? $field['option_type'] : 'theme_mod'; |
|
126 | + $default = (isset($field['default'])) ? $field['default'] : ''; |
|
127 | + $value = apply_filters('kirki_get_value', get_theme_mod($field['settings'], $default), $field['settings'], $default, $option_type); |
|
128 | 128 | |
129 | 129 | // Loop through the array of variables. |
130 | - foreach ( $field['variables'] as $field_variable ) { |
|
130 | + foreach ($field['variables'] as $field_variable) { |
|
131 | 131 | |
132 | 132 | // Is the variable ['name'] defined? If yes, then we can proceed. |
133 | - if ( isset( $field_variable['name'] ) ) { |
|
133 | + if (isset($field_variable['name'])) { |
|
134 | 134 | |
135 | 135 | // Do we have a callback function defined? If not then set $variable_callback to false. |
136 | - $variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false; |
|
136 | + $variable_callback = (isset($field_variable['callback']) && is_callable($field_variable['callback'])) ? $field_variable['callback'] : false; |
|
137 | 137 | |
138 | 138 | /** |
139 | 139 | * If we have a variable_callback defined then get the value of the option |
140 | 140 | * and run it through the callback function. |
141 | 141 | * If no callback is defined (false) then just get the value. |
142 | 142 | */ |
143 | - $variables[ $field_variable['name'] ] = $value; |
|
144 | - if ( $variable_callback ) { |
|
145 | - $variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], $value ); |
|
143 | + $variables[$field_variable['name']] = $value; |
|
144 | + if ($variable_callback) { |
|
145 | + $variables[$field_variable['name']] = call_user_func($field_variable['callback'], $value); |
|
146 | 146 | } |
147 | 147 | } |
148 | 148 | } |
149 | 149 | } |
150 | 150 | |
151 | 151 | // Pass the variables through a filter ('kirki_variable') and return the array of variables. |
152 | - return apply_filters( 'kirki_variable', $variables ); |
|
152 | + return apply_filters('kirki_variable', $variables); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -161,38 +161,38 @@ discard block |
||
161 | 161 | * @param string $url The request URL. |
162 | 162 | * @return array |
163 | 163 | */ |
164 | - public function http_request( $request = [], $url = '' ) { |
|
164 | + public function http_request($request = [], $url = '') { |
|
165 | 165 | |
166 | 166 | // Early exit if installed as a plugin or not a request to wordpress.org, |
167 | 167 | // or finally if we don't have everything we need. |
168 | 168 | if ( |
169 | 169 | self::is_plugin() || |
170 | - false === strpos( $url, 'wordpress.org' ) || ( |
|
171 | - ! isset( $request['body'] ) || |
|
172 | - ! isset( $request['body']['plugins'] ) || |
|
173 | - ! isset( $request['body']['translations'] ) || |
|
174 | - ! isset( $request['body']['locale'] ) || |
|
175 | - ! isset( $request['body']['all'] ) |
|
170 | + false === strpos($url, 'wordpress.org') || ( |
|
171 | + !isset($request['body']) || |
|
172 | + !isset($request['body']['plugins']) || |
|
173 | + !isset($request['body']['translations']) || |
|
174 | + !isset($request['body']['locale']) || |
|
175 | + !isset($request['body']['all']) |
|
176 | 176 | ) |
177 | 177 | ) { |
178 | 178 | return $request; |
179 | 179 | } |
180 | 180 | |
181 | - $plugins = json_decode( $request['body']['plugins'], true ); |
|
182 | - if ( ! isset( $plugins['plugins'] ) ) { |
|
181 | + $plugins = json_decode($request['body']['plugins'], true); |
|
182 | + if (!isset($plugins['plugins'])) { |
|
183 | 183 | return $request; |
184 | 184 | } |
185 | 185 | $exists = false; |
186 | - foreach ( $plugins['plugins'] as $plugin ) { |
|
187 | - if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) { |
|
186 | + foreach ($plugins['plugins'] as $plugin) { |
|
187 | + if (isset($plugin['Name']) && 'Kirki Toolkit' === $plugin['Name']) { |
|
188 | 188 | $exists = true; |
189 | 189 | } |
190 | 190 | } |
191 | 191 | // Inject data. |
192 | - if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) { |
|
193 | - $plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE ); |
|
192 | + if (!$exists && defined('KIRKI_PLUGIN_FILE')) { |
|
193 | + $plugins['plugins']['kirki/kirki.php'] = get_plugin_data(KIRKI_PLUGIN_FILE); |
|
194 | 194 | } |
195 | - $request['body']['plugins'] = wp_json_encode( $plugins ); |
|
195 | + $request['body']['plugins'] = wp_json_encode($plugins); |
|
196 | 196 | return $request; |
197 | 197 | } |
198 | 198 | |
@@ -206,12 +206,12 @@ discard block |
||
206 | 206 | * @return int|string Returns integer when getting the 'major' version. |
207 | 207 | * Returns string when getting the 'minor' version. |
208 | 208 | */ |
209 | - public static function get_wp_version( $context = 'minor' ) { |
|
209 | + public static function get_wp_version($context = 'minor') { |
|
210 | 210 | global $wp_version; |
211 | 211 | |
212 | 212 | // We only need the major version. |
213 | - if ( 'major' === $context ) { |
|
214 | - $version_parts = explode( '.', $wp_version ); |
|
213 | + if ('major' === $context) { |
|
214 | + $version_parts = explode('.', $wp_version); |
|
215 | 215 | return $version_parts[0]; |
216 | 216 | } |
217 | 217 |
@@ -18,92 +18,92 @@ |
||
18 | 18 | */ |
19 | 19 | class MaterialColors { |
20 | 20 | |
21 | - /** |
|
22 | - * Gets an array of material-design colors. |
|
23 | - * |
|
24 | - * @static |
|
25 | - * @access public |
|
26 | - * @since 1.0 |
|
27 | - * @param string $context Allows us to get subsets of the palette. |
|
28 | - * @return array |
|
29 | - */ |
|
30 | - public static function get_colors( $context = 'primary' ) { |
|
31 | - $colors = [ |
|
32 | - 'primary' => [ '#ffffff', '#000000', '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b' ], |
|
33 | - 'red' => [ '#ffebee', '#ffcdd2', '#ef9a9a', '#e57373', '#ef5350', '#f44336', '#e53935', '#d32f2f', '#c62828', '#b71c1c', '#ff8a80', '#ff5252', '#ff1744', '#d50000' ], |
|
34 | - 'pink' => [ '#fce4ec', '#f8bbd0', '#f48fb1', '#f06292', '#ec407a', '#e91e63', '#d81b60', '#c2185b', '#ad1457', '#880e4f', '#ff80ab', '#ff4081', '#f50057', '#c51162' ], |
|
35 | - 'purple' => [ '#f3e5f5', '#e1bee7', '#ce93d8', '#ba68c8', '#ab47bc', '#9c27b0', '#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#ea80fc', '#e040fb', '#d500f9', '#aa00ff' ], |
|
36 | - 'deep-purple' => [ '#ede7f6', '#d1c4e9', '#b39ddb', '#9575cd', '#7e57c2', '#673ab7', '#5e35b1', '#512da8', '#4527a0', '#311b92', '#b388ff', '#7c4dff', '#651fff', '#6200ea' ], |
|
37 | - 'indigo' => [ '#e8eaf6', '#c5cae9', '#9fa8da', '#7986cb', '#5c6bc0', '#3f51b5', '#3949ab', '#303f9f', '#283593', '#1a237e', '#8c9eff', '#536dfe', '#3d5afe', '#304ffe' ], |
|
38 | - 'blue' => [ '#e3f2fd', '#bbdefb', '#90caf9', '#64b5f6', '#42a5f5', '#2196f3', '#1e88e5', '#1976d2', '#1565c0', '#0d47a1', '#82b1ff', '#448aff', '#2979ff', '#2962ff' ], |
|
39 | - 'light-blue' => [ '#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6fc', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b', '#80d8ff', '#40c4ff', '#00b0ff', '#0091ea' ], |
|
40 | - 'cyan' => [ '#e0f7fa', '#b2ebf2', '#80deea', '#4dd0e1', '#26c6da', '#00bcd4', '#00acc1', '#0097a7', '#00838f', '#006064', '#84ffff', '#18ffff', '#00e5ff', '#00b8d4' ], |
|
41 | - 'teal' => [ '#e0f2f1', '#b2dfdb', '#80cbc4', '#4db6ac', '#26a69a', '#009688', '#00897b', '#00796b', '#00695c', '#004d40', '#a7ffeb', '#64ffda', '#1de9b6', '#00bfa5' ], |
|
42 | - 'green' => [ '#e8f5e9', '#c8e6c9', '#a5d6a7', '#81c784', '#66bb6a', '#4caf50', '#43a047', '#388e3c', '#2e7d32', '#1b5e20', '#b9f6ca', '#69f0ae', '#00e676', '#00c853' ], |
|
43 | - 'light-green' => [ '#f1f8e9', '#dcedc8', '#c5e1a5', '#aed581', '#9ccc65', '#8bc34a', '#7cb342', '#689f38', '#558b2f', '#33691e', '#ccff90', '#b2ff59', '#76ff03', '#64dd17' ], |
|
44 | - 'lime' => [ '#f9fbe7', '#f0f4c3', '#e6ee9c', '#dce775', '#d4e157', '#cddc39', '#c0ca33', '#a4b42b', '#9e9d24', '#827717', '#f4ff81', '#eeff41', '#c6ff00', '#aeea00' ], |
|
45 | - 'yellow' => [ '#fffde7', '#fff9c4', '#fff590', '#fff176', '#ffee58', '#ffeb3b', '#fdd835', '#fbc02d', '#f9a825', '#f57f17', '#ffff82', '#ffff00', '#ffea00', '#ffd600' ], |
|
46 | - 'amber' => [ '#fff8e1', '#ffecb3', '#ffe082', '#ffd54f', '#ffca28', '#ffc107', '#ffb300', '#ffa000', '#ff8f00', '#ff6f00', '#ffe57f', '#ffd740', '#ffc400', '#ffab00' ], |
|
47 | - 'orange' => [ '#fff3e0', '#ffe0b2', '#ffcc80', '#ffb74d', '#ffa726', '#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100', '#ffd180', '#ffab40', '#ff9100', '#ff6d00' ], |
|
48 | - 'deep-orange' => [ '#fbe9a7', '#ffccbc', '#ffab91', '#ff8a65', '#ff7043', '#ff5722', '#f4511e', '#e64a19', '#d84315', '#bf360c', '#ff9e80', '#ff6e40', '#ff3d00', '#dd2600' ], |
|
49 | - 'brown' => [ '#efebe9', '#d7ccc8', '#bcaaa4', '#a1887f', '#8d6e63', '#795548', '#6d4c41', '#5d4037', '#4e342e', '#3e2723' ], |
|
50 | - 'grey' => [ '#fafafa', '#f5f5f5', '#eeeeee', '#e0e0e0', '#bdbdbd', '#9e9e9e', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ], |
|
51 | - 'blue-grey' => [ '#eceff1', '#cfd8dc', '#b0bbc5', '#90a4ae', '#78909c', '#607d8b', '#546e7a', '#455a64', '#37474f', '#263238' ], |
|
52 | - ]; |
|
21 | + /** |
|
22 | + * Gets an array of material-design colors. |
|
23 | + * |
|
24 | + * @static |
|
25 | + * @access public |
|
26 | + * @since 1.0 |
|
27 | + * @param string $context Allows us to get subsets of the palette. |
|
28 | + * @return array |
|
29 | + */ |
|
30 | + public static function get_colors( $context = 'primary' ) { |
|
31 | + $colors = [ |
|
32 | + 'primary' => [ '#ffffff', '#000000', '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b' ], |
|
33 | + 'red' => [ '#ffebee', '#ffcdd2', '#ef9a9a', '#e57373', '#ef5350', '#f44336', '#e53935', '#d32f2f', '#c62828', '#b71c1c', '#ff8a80', '#ff5252', '#ff1744', '#d50000' ], |
|
34 | + 'pink' => [ '#fce4ec', '#f8bbd0', '#f48fb1', '#f06292', '#ec407a', '#e91e63', '#d81b60', '#c2185b', '#ad1457', '#880e4f', '#ff80ab', '#ff4081', '#f50057', '#c51162' ], |
|
35 | + 'purple' => [ '#f3e5f5', '#e1bee7', '#ce93d8', '#ba68c8', '#ab47bc', '#9c27b0', '#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#ea80fc', '#e040fb', '#d500f9', '#aa00ff' ], |
|
36 | + 'deep-purple' => [ '#ede7f6', '#d1c4e9', '#b39ddb', '#9575cd', '#7e57c2', '#673ab7', '#5e35b1', '#512da8', '#4527a0', '#311b92', '#b388ff', '#7c4dff', '#651fff', '#6200ea' ], |
|
37 | + 'indigo' => [ '#e8eaf6', '#c5cae9', '#9fa8da', '#7986cb', '#5c6bc0', '#3f51b5', '#3949ab', '#303f9f', '#283593', '#1a237e', '#8c9eff', '#536dfe', '#3d5afe', '#304ffe' ], |
|
38 | + 'blue' => [ '#e3f2fd', '#bbdefb', '#90caf9', '#64b5f6', '#42a5f5', '#2196f3', '#1e88e5', '#1976d2', '#1565c0', '#0d47a1', '#82b1ff', '#448aff', '#2979ff', '#2962ff' ], |
|
39 | + 'light-blue' => [ '#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6fc', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b', '#80d8ff', '#40c4ff', '#00b0ff', '#0091ea' ], |
|
40 | + 'cyan' => [ '#e0f7fa', '#b2ebf2', '#80deea', '#4dd0e1', '#26c6da', '#00bcd4', '#00acc1', '#0097a7', '#00838f', '#006064', '#84ffff', '#18ffff', '#00e5ff', '#00b8d4' ], |
|
41 | + 'teal' => [ '#e0f2f1', '#b2dfdb', '#80cbc4', '#4db6ac', '#26a69a', '#009688', '#00897b', '#00796b', '#00695c', '#004d40', '#a7ffeb', '#64ffda', '#1de9b6', '#00bfa5' ], |
|
42 | + 'green' => [ '#e8f5e9', '#c8e6c9', '#a5d6a7', '#81c784', '#66bb6a', '#4caf50', '#43a047', '#388e3c', '#2e7d32', '#1b5e20', '#b9f6ca', '#69f0ae', '#00e676', '#00c853' ], |
|
43 | + 'light-green' => [ '#f1f8e9', '#dcedc8', '#c5e1a5', '#aed581', '#9ccc65', '#8bc34a', '#7cb342', '#689f38', '#558b2f', '#33691e', '#ccff90', '#b2ff59', '#76ff03', '#64dd17' ], |
|
44 | + 'lime' => [ '#f9fbe7', '#f0f4c3', '#e6ee9c', '#dce775', '#d4e157', '#cddc39', '#c0ca33', '#a4b42b', '#9e9d24', '#827717', '#f4ff81', '#eeff41', '#c6ff00', '#aeea00' ], |
|
45 | + 'yellow' => [ '#fffde7', '#fff9c4', '#fff590', '#fff176', '#ffee58', '#ffeb3b', '#fdd835', '#fbc02d', '#f9a825', '#f57f17', '#ffff82', '#ffff00', '#ffea00', '#ffd600' ], |
|
46 | + 'amber' => [ '#fff8e1', '#ffecb3', '#ffe082', '#ffd54f', '#ffca28', '#ffc107', '#ffb300', '#ffa000', '#ff8f00', '#ff6f00', '#ffe57f', '#ffd740', '#ffc400', '#ffab00' ], |
|
47 | + 'orange' => [ '#fff3e0', '#ffe0b2', '#ffcc80', '#ffb74d', '#ffa726', '#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100', '#ffd180', '#ffab40', '#ff9100', '#ff6d00' ], |
|
48 | + 'deep-orange' => [ '#fbe9a7', '#ffccbc', '#ffab91', '#ff8a65', '#ff7043', '#ff5722', '#f4511e', '#e64a19', '#d84315', '#bf360c', '#ff9e80', '#ff6e40', '#ff3d00', '#dd2600' ], |
|
49 | + 'brown' => [ '#efebe9', '#d7ccc8', '#bcaaa4', '#a1887f', '#8d6e63', '#795548', '#6d4c41', '#5d4037', '#4e342e', '#3e2723' ], |
|
50 | + 'grey' => [ '#fafafa', '#f5f5f5', '#eeeeee', '#e0e0e0', '#bdbdbd', '#9e9e9e', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ], |
|
51 | + 'blue-grey' => [ '#eceff1', '#cfd8dc', '#b0bbc5', '#90a4ae', '#78909c', '#607d8b', '#546e7a', '#455a64', '#37474f', '#263238' ], |
|
52 | + ]; |
|
53 | 53 | |
54 | - switch ( $context ) { |
|
55 | - case '50': |
|
56 | - case '100': |
|
57 | - case '200': |
|
58 | - case '300': |
|
59 | - case '400': |
|
60 | - case '500': |
|
61 | - case '600': |
|
62 | - case '700': |
|
63 | - case '800': |
|
64 | - case '900': |
|
65 | - case 'A100': |
|
66 | - case 'A200': |
|
67 | - case 'A400': |
|
68 | - case 'A700': |
|
69 | - $key = absint( $context ) / 100; |
|
70 | - if ( 'A100' === $context ) { |
|
71 | - $key = 10; |
|
72 | - unset( $colors['grey'] ); |
|
73 | - } elseif ( 'A200' === $context ) { |
|
74 | - $key = 11; |
|
75 | - unset( $colors['grey'] ); |
|
76 | - } elseif ( 'A400' === $context ) { |
|
77 | - $key = 12; |
|
78 | - unset( $colors['grey'] ); |
|
79 | - } elseif ( 'A700' === $context ) { |
|
80 | - $key = 13; |
|
81 | - unset( $colors['grey'] ); |
|
82 | - } |
|
83 | - unset( $colors['primary'] ); |
|
84 | - $position_colors = []; |
|
85 | - foreach ( $colors as $color_family ) { |
|
86 | - if ( isset( $color_family[ $key ] ) ) { |
|
87 | - $position_colors[] = $color_family[ $key ]; |
|
88 | - } |
|
89 | - } |
|
90 | - return $position_colors; |
|
91 | - case 'all': |
|
92 | - unset( $colors['primary'] ); |
|
93 | - $all_colors = []; |
|
94 | - foreach ( $colors as $color_family ) { |
|
95 | - foreach ( $color_family as $color ) { |
|
96 | - $all_colors[] = $color; |
|
97 | - } |
|
98 | - } |
|
99 | - return $all_colors; |
|
100 | - case 'primary': |
|
101 | - return $colors['primary']; |
|
102 | - default: |
|
103 | - if ( isset( $colors[ $context ] ) ) { |
|
104 | - return $colors[ $context ]; |
|
105 | - } |
|
106 | - return $colors['primary']; |
|
107 | - } |
|
108 | - } |
|
54 | + switch ( $context ) { |
|
55 | + case '50': |
|
56 | + case '100': |
|
57 | + case '200': |
|
58 | + case '300': |
|
59 | + case '400': |
|
60 | + case '500': |
|
61 | + case '600': |
|
62 | + case '700': |
|
63 | + case '800': |
|
64 | + case '900': |
|
65 | + case 'A100': |
|
66 | + case 'A200': |
|
67 | + case 'A400': |
|
68 | + case 'A700': |
|
69 | + $key = absint( $context ) / 100; |
|
70 | + if ( 'A100' === $context ) { |
|
71 | + $key = 10; |
|
72 | + unset( $colors['grey'] ); |
|
73 | + } elseif ( 'A200' === $context ) { |
|
74 | + $key = 11; |
|
75 | + unset( $colors['grey'] ); |
|
76 | + } elseif ( 'A400' === $context ) { |
|
77 | + $key = 12; |
|
78 | + unset( $colors['grey'] ); |
|
79 | + } elseif ( 'A700' === $context ) { |
|
80 | + $key = 13; |
|
81 | + unset( $colors['grey'] ); |
|
82 | + } |
|
83 | + unset( $colors['primary'] ); |
|
84 | + $position_colors = []; |
|
85 | + foreach ( $colors as $color_family ) { |
|
86 | + if ( isset( $color_family[ $key ] ) ) { |
|
87 | + $position_colors[] = $color_family[ $key ]; |
|
88 | + } |
|
89 | + } |
|
90 | + return $position_colors; |
|
91 | + case 'all': |
|
92 | + unset( $colors['primary'] ); |
|
93 | + $all_colors = []; |
|
94 | + foreach ( $colors as $color_family ) { |
|
95 | + foreach ( $color_family as $color ) { |
|
96 | + $all_colors[] = $color; |
|
97 | + } |
|
98 | + } |
|
99 | + return $all_colors; |
|
100 | + case 'primary': |
|
101 | + return $colors['primary']; |
|
102 | + default: |
|
103 | + if ( isset( $colors[ $context ] ) ) { |
|
104 | + return $colors[ $context ]; |
|
105 | + } |
|
106 | + return $colors['primary']; |
|
107 | + } |
|
108 | + } |
|
109 | 109 | } |
@@ -27,31 +27,31 @@ discard block |
||
27 | 27 | * @param string $context Allows us to get subsets of the palette. |
28 | 28 | * @return array |
29 | 29 | */ |
30 | - public static function get_colors( $context = 'primary' ) { |
|
30 | + public static function get_colors($context = 'primary') { |
|
31 | 31 | $colors = [ |
32 | - 'primary' => [ '#ffffff', '#000000', '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b' ], |
|
33 | - 'red' => [ '#ffebee', '#ffcdd2', '#ef9a9a', '#e57373', '#ef5350', '#f44336', '#e53935', '#d32f2f', '#c62828', '#b71c1c', '#ff8a80', '#ff5252', '#ff1744', '#d50000' ], |
|
34 | - 'pink' => [ '#fce4ec', '#f8bbd0', '#f48fb1', '#f06292', '#ec407a', '#e91e63', '#d81b60', '#c2185b', '#ad1457', '#880e4f', '#ff80ab', '#ff4081', '#f50057', '#c51162' ], |
|
35 | - 'purple' => [ '#f3e5f5', '#e1bee7', '#ce93d8', '#ba68c8', '#ab47bc', '#9c27b0', '#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#ea80fc', '#e040fb', '#d500f9', '#aa00ff' ], |
|
36 | - 'deep-purple' => [ '#ede7f6', '#d1c4e9', '#b39ddb', '#9575cd', '#7e57c2', '#673ab7', '#5e35b1', '#512da8', '#4527a0', '#311b92', '#b388ff', '#7c4dff', '#651fff', '#6200ea' ], |
|
37 | - 'indigo' => [ '#e8eaf6', '#c5cae9', '#9fa8da', '#7986cb', '#5c6bc0', '#3f51b5', '#3949ab', '#303f9f', '#283593', '#1a237e', '#8c9eff', '#536dfe', '#3d5afe', '#304ffe' ], |
|
38 | - 'blue' => [ '#e3f2fd', '#bbdefb', '#90caf9', '#64b5f6', '#42a5f5', '#2196f3', '#1e88e5', '#1976d2', '#1565c0', '#0d47a1', '#82b1ff', '#448aff', '#2979ff', '#2962ff' ], |
|
39 | - 'light-blue' => [ '#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6fc', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b', '#80d8ff', '#40c4ff', '#00b0ff', '#0091ea' ], |
|
40 | - 'cyan' => [ '#e0f7fa', '#b2ebf2', '#80deea', '#4dd0e1', '#26c6da', '#00bcd4', '#00acc1', '#0097a7', '#00838f', '#006064', '#84ffff', '#18ffff', '#00e5ff', '#00b8d4' ], |
|
41 | - 'teal' => [ '#e0f2f1', '#b2dfdb', '#80cbc4', '#4db6ac', '#26a69a', '#009688', '#00897b', '#00796b', '#00695c', '#004d40', '#a7ffeb', '#64ffda', '#1de9b6', '#00bfa5' ], |
|
42 | - 'green' => [ '#e8f5e9', '#c8e6c9', '#a5d6a7', '#81c784', '#66bb6a', '#4caf50', '#43a047', '#388e3c', '#2e7d32', '#1b5e20', '#b9f6ca', '#69f0ae', '#00e676', '#00c853' ], |
|
43 | - 'light-green' => [ '#f1f8e9', '#dcedc8', '#c5e1a5', '#aed581', '#9ccc65', '#8bc34a', '#7cb342', '#689f38', '#558b2f', '#33691e', '#ccff90', '#b2ff59', '#76ff03', '#64dd17' ], |
|
44 | - 'lime' => [ '#f9fbe7', '#f0f4c3', '#e6ee9c', '#dce775', '#d4e157', '#cddc39', '#c0ca33', '#a4b42b', '#9e9d24', '#827717', '#f4ff81', '#eeff41', '#c6ff00', '#aeea00' ], |
|
45 | - 'yellow' => [ '#fffde7', '#fff9c4', '#fff590', '#fff176', '#ffee58', '#ffeb3b', '#fdd835', '#fbc02d', '#f9a825', '#f57f17', '#ffff82', '#ffff00', '#ffea00', '#ffd600' ], |
|
46 | - 'amber' => [ '#fff8e1', '#ffecb3', '#ffe082', '#ffd54f', '#ffca28', '#ffc107', '#ffb300', '#ffa000', '#ff8f00', '#ff6f00', '#ffe57f', '#ffd740', '#ffc400', '#ffab00' ], |
|
47 | - 'orange' => [ '#fff3e0', '#ffe0b2', '#ffcc80', '#ffb74d', '#ffa726', '#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100', '#ffd180', '#ffab40', '#ff9100', '#ff6d00' ], |
|
48 | - 'deep-orange' => [ '#fbe9a7', '#ffccbc', '#ffab91', '#ff8a65', '#ff7043', '#ff5722', '#f4511e', '#e64a19', '#d84315', '#bf360c', '#ff9e80', '#ff6e40', '#ff3d00', '#dd2600' ], |
|
49 | - 'brown' => [ '#efebe9', '#d7ccc8', '#bcaaa4', '#a1887f', '#8d6e63', '#795548', '#6d4c41', '#5d4037', '#4e342e', '#3e2723' ], |
|
50 | - 'grey' => [ '#fafafa', '#f5f5f5', '#eeeeee', '#e0e0e0', '#bdbdbd', '#9e9e9e', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ], |
|
51 | - 'blue-grey' => [ '#eceff1', '#cfd8dc', '#b0bbc5', '#90a4ae', '#78909c', '#607d8b', '#546e7a', '#455a64', '#37474f', '#263238' ], |
|
32 | + 'primary' => ['#ffffff', '#000000', '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b'], |
|
33 | + 'red' => ['#ffebee', '#ffcdd2', '#ef9a9a', '#e57373', '#ef5350', '#f44336', '#e53935', '#d32f2f', '#c62828', '#b71c1c', '#ff8a80', '#ff5252', '#ff1744', '#d50000'], |
|
34 | + 'pink' => ['#fce4ec', '#f8bbd0', '#f48fb1', '#f06292', '#ec407a', '#e91e63', '#d81b60', '#c2185b', '#ad1457', '#880e4f', '#ff80ab', '#ff4081', '#f50057', '#c51162'], |
|
35 | + 'purple' => ['#f3e5f5', '#e1bee7', '#ce93d8', '#ba68c8', '#ab47bc', '#9c27b0', '#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#ea80fc', '#e040fb', '#d500f9', '#aa00ff'], |
|
36 | + 'deep-purple' => ['#ede7f6', '#d1c4e9', '#b39ddb', '#9575cd', '#7e57c2', '#673ab7', '#5e35b1', '#512da8', '#4527a0', '#311b92', '#b388ff', '#7c4dff', '#651fff', '#6200ea'], |
|
37 | + 'indigo' => ['#e8eaf6', '#c5cae9', '#9fa8da', '#7986cb', '#5c6bc0', '#3f51b5', '#3949ab', '#303f9f', '#283593', '#1a237e', '#8c9eff', '#536dfe', '#3d5afe', '#304ffe'], |
|
38 | + 'blue' => ['#e3f2fd', '#bbdefb', '#90caf9', '#64b5f6', '#42a5f5', '#2196f3', '#1e88e5', '#1976d2', '#1565c0', '#0d47a1', '#82b1ff', '#448aff', '#2979ff', '#2962ff'], |
|
39 | + 'light-blue' => ['#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6fc', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b', '#80d8ff', '#40c4ff', '#00b0ff', '#0091ea'], |
|
40 | + 'cyan' => ['#e0f7fa', '#b2ebf2', '#80deea', '#4dd0e1', '#26c6da', '#00bcd4', '#00acc1', '#0097a7', '#00838f', '#006064', '#84ffff', '#18ffff', '#00e5ff', '#00b8d4'], |
|
41 | + 'teal' => ['#e0f2f1', '#b2dfdb', '#80cbc4', '#4db6ac', '#26a69a', '#009688', '#00897b', '#00796b', '#00695c', '#004d40', '#a7ffeb', '#64ffda', '#1de9b6', '#00bfa5'], |
|
42 | + 'green' => ['#e8f5e9', '#c8e6c9', '#a5d6a7', '#81c784', '#66bb6a', '#4caf50', '#43a047', '#388e3c', '#2e7d32', '#1b5e20', '#b9f6ca', '#69f0ae', '#00e676', '#00c853'], |
|
43 | + 'light-green' => ['#f1f8e9', '#dcedc8', '#c5e1a5', '#aed581', '#9ccc65', '#8bc34a', '#7cb342', '#689f38', '#558b2f', '#33691e', '#ccff90', '#b2ff59', '#76ff03', '#64dd17'], |
|
44 | + 'lime' => ['#f9fbe7', '#f0f4c3', '#e6ee9c', '#dce775', '#d4e157', '#cddc39', '#c0ca33', '#a4b42b', '#9e9d24', '#827717', '#f4ff81', '#eeff41', '#c6ff00', '#aeea00'], |
|
45 | + 'yellow' => ['#fffde7', '#fff9c4', '#fff590', '#fff176', '#ffee58', '#ffeb3b', '#fdd835', '#fbc02d', '#f9a825', '#f57f17', '#ffff82', '#ffff00', '#ffea00', '#ffd600'], |
|
46 | + 'amber' => ['#fff8e1', '#ffecb3', '#ffe082', '#ffd54f', '#ffca28', '#ffc107', '#ffb300', '#ffa000', '#ff8f00', '#ff6f00', '#ffe57f', '#ffd740', '#ffc400', '#ffab00'], |
|
47 | + 'orange' => ['#fff3e0', '#ffe0b2', '#ffcc80', '#ffb74d', '#ffa726', '#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100', '#ffd180', '#ffab40', '#ff9100', '#ff6d00'], |
|
48 | + 'deep-orange' => ['#fbe9a7', '#ffccbc', '#ffab91', '#ff8a65', '#ff7043', '#ff5722', '#f4511e', '#e64a19', '#d84315', '#bf360c', '#ff9e80', '#ff6e40', '#ff3d00', '#dd2600'], |
|
49 | + 'brown' => ['#efebe9', '#d7ccc8', '#bcaaa4', '#a1887f', '#8d6e63', '#795548', '#6d4c41', '#5d4037', '#4e342e', '#3e2723'], |
|
50 | + 'grey' => ['#fafafa', '#f5f5f5', '#eeeeee', '#e0e0e0', '#bdbdbd', '#9e9e9e', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff'], |
|
51 | + 'blue-grey' => ['#eceff1', '#cfd8dc', '#b0bbc5', '#90a4ae', '#78909c', '#607d8b', '#546e7a', '#455a64', '#37474f', '#263238'], |
|
52 | 52 | ]; |
53 | 53 | |
54 | - switch ( $context ) { |
|
54 | + switch ($context) { |
|
55 | 55 | case '50': |
56 | 56 | case '100': |
57 | 57 | case '200': |
@@ -66,33 +66,33 @@ discard block |
||
66 | 66 | case 'A200': |
67 | 67 | case 'A400': |
68 | 68 | case 'A700': |
69 | - $key = absint( $context ) / 100; |
|
70 | - if ( 'A100' === $context ) { |
|
69 | + $key = absint($context) / 100; |
|
70 | + if ('A100' === $context) { |
|
71 | 71 | $key = 10; |
72 | - unset( $colors['grey'] ); |
|
73 | - } elseif ( 'A200' === $context ) { |
|
72 | + unset($colors['grey']); |
|
73 | + } elseif ('A200' === $context) { |
|
74 | 74 | $key = 11; |
75 | - unset( $colors['grey'] ); |
|
76 | - } elseif ( 'A400' === $context ) { |
|
75 | + unset($colors['grey']); |
|
76 | + } elseif ('A400' === $context) { |
|
77 | 77 | $key = 12; |
78 | - unset( $colors['grey'] ); |
|
79 | - } elseif ( 'A700' === $context ) { |
|
78 | + unset($colors['grey']); |
|
79 | + } elseif ('A700' === $context) { |
|
80 | 80 | $key = 13; |
81 | - unset( $colors['grey'] ); |
|
81 | + unset($colors['grey']); |
|
82 | 82 | } |
83 | - unset( $colors['primary'] ); |
|
83 | + unset($colors['primary']); |
|
84 | 84 | $position_colors = []; |
85 | - foreach ( $colors as $color_family ) { |
|
86 | - if ( isset( $color_family[ $key ] ) ) { |
|
87 | - $position_colors[] = $color_family[ $key ]; |
|
85 | + foreach ($colors as $color_family) { |
|
86 | + if (isset($color_family[$key])) { |
|
87 | + $position_colors[] = $color_family[$key]; |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 | return $position_colors; |
91 | 91 | case 'all': |
92 | - unset( $colors['primary'] ); |
|
92 | + unset($colors['primary']); |
|
93 | 93 | $all_colors = []; |
94 | - foreach ( $colors as $color_family ) { |
|
95 | - foreach ( $color_family as $color ) { |
|
94 | + foreach ($colors as $color_family) { |
|
95 | + foreach ($color_family as $color) { |
|
96 | 96 | $all_colors[] = $color; |
97 | 97 | } |
98 | 98 | } |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | case 'primary': |
101 | 101 | return $colors['primary']; |
102 | 102 | default: |
103 | - if ( isset( $colors[ $context ] ) ) { |
|
104 | - return $colors[ $context ]; |
|
103 | + if (isset($colors[$context])) { |
|
104 | + return $colors[$context]; |
|
105 | 105 | } |
106 | 106 | return $colors['primary']; |
107 | 107 | } |
@@ -18,34 +18,34 @@ |
||
18 | 18 | */ |
19 | 19 | class Background extends Output { |
20 | 20 | |
21 | - /** |
|
22 | - * Processes a single item from the `output` array. |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @param array $output The `output` item. |
|
26 | - * @param array $value The field's value. |
|
27 | - */ |
|
28 | - protected function process_output( $output, $value ) { |
|
29 | - $output = wp_parse_args( |
|
30 | - $output, |
|
31 | - [ |
|
32 | - 'media_query' => 'global', |
|
33 | - 'element' => 'body', |
|
34 | - 'prefix' => '', |
|
35 | - 'suffix' => '', |
|
36 | - ] |
|
37 | - ); |
|
21 | + /** |
|
22 | + * Processes a single item from the `output` array. |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @param array $output The `output` item. |
|
26 | + * @param array $value The field's value. |
|
27 | + */ |
|
28 | + protected function process_output( $output, $value ) { |
|
29 | + $output = wp_parse_args( |
|
30 | + $output, |
|
31 | + [ |
|
32 | + 'media_query' => 'global', |
|
33 | + 'element' => 'body', |
|
34 | + 'prefix' => '', |
|
35 | + 'suffix' => '', |
|
36 | + ] |
|
37 | + ); |
|
38 | 38 | |
39 | - foreach ( [ 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ] as $property ) { |
|
39 | + foreach ( [ 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ] as $property ) { |
|
40 | 40 | |
41 | - // See https://github.com/aristath/kirki/issues/1808. |
|
42 | - if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) { |
|
43 | - $this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
44 | - } |
|
41 | + // See https://github.com/aristath/kirki/issues/1808. |
|
42 | + if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) { |
|
43 | + $this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
44 | + } |
|
45 | 45 | |
46 | - if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) { |
|
47 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
48 | - } |
|
49 | - } |
|
50 | - } |
|
46 | + if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) { |
|
47 | + $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
48 | + } |
|
49 | + } |
|
50 | + } |
|
51 | 51 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param array $output The `output` item. |
26 | 26 | * @param array $value The field's value. |
27 | 27 | */ |
28 | - protected function process_output( $output, $value ) { |
|
28 | + protected function process_output($output, $value) { |
|
29 | 29 | $output = wp_parse_args( |
30 | 30 | $output, |
31 | 31 | [ |
@@ -36,15 +36,15 @@ discard block |
||
36 | 36 | ] |
37 | 37 | ); |
38 | 38 | |
39 | - foreach ( [ 'background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment' ] as $property ) { |
|
39 | + foreach (['background-image', 'background-color', 'background-repeat', 'background-position', 'background-size', 'background-attachment'] as $property) { |
|
40 | 40 | |
41 | 41 | // See https://github.com/aristath/kirki/issues/1808. |
42 | - if ( 'background-color' === $property && isset( $value['background-color'] ) && $value['background-color'] && ( ! isset( $value['background-image'] ) || empty( $value['background-image'] ) ) ) { |
|
43 | - $this->styles[ $output['media_query'] ][ $output['element'] ]['background'] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
42 | + if ('background-color' === $property && isset($value['background-color']) && $value['background-color'] && (!isset($value['background-image']) || empty($value['background-image']))) { |
|
43 | + $this->styles[$output['media_query']][$output['element']]['background'] = $output['prefix'] . $this->process_property_value($property, $value[$property]) . $output['suffix']; |
|
44 | 44 | } |
45 | 45 | |
46 | - if ( isset( $value[ $property ] ) && ! empty( $value[ $property ] ) ) { |
|
47 | - $this->styles[ $output['media_query'] ][ $output['element'] ][ $property ] = $output['prefix'] . $this->process_property_value( $property, $value[ $property ] ) . $output['suffix']; |
|
46 | + if (isset($value[$property]) && !empty($value[$property])) { |
|
47 | + $this->styles[$output['media_query']][$output['element']][$property] = $output['prefix'] . $this->process_property_value($property, $value[$property]) . $output['suffix']; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | } |
@@ -21,447 +21,447 @@ |
||
21 | 21 | */ |
22 | 22 | class Background extends Field { |
23 | 23 | |
24 | - /** |
|
25 | - * The field type. |
|
26 | - * |
|
27 | - * @access public |
|
28 | - * @since 1.0 |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - public $type = 'kirki-background'; |
|
32 | - |
|
33 | - /** |
|
34 | - * Extra logic for the field. |
|
35 | - * |
|
36 | - * Adds all sub-fields. |
|
37 | - * |
|
38 | - * @access public |
|
39 | - * @param array $args The arguments of the field. |
|
40 | - */ |
|
41 | - public function init( $args ) { |
|
42 | - |
|
43 | - $args['required'] = isset( $args['required'] ) ? (array) $args['required'] : []; |
|
44 | - $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global'; |
|
45 | - |
|
46 | - /** |
|
47 | - * Add a hidden field, the label & description. |
|
48 | - */ |
|
49 | - new \Kirki\Field\Generic( |
|
50 | - wp_parse_args( |
|
51 | - [ |
|
52 | - 'type' => 'kirki-generic', |
|
53 | - 'default' => '', |
|
54 | - 'choices' => [ |
|
55 | - 'type' => 'hidden', |
|
56 | - 'parent_type' => 'kirki-background', |
|
57 | - ], |
|
58 | - 'sanitize_callback' => [ '\Kirki\Field\Background', 'sanitize' ], |
|
59 | - ], |
|
60 | - $args |
|
61 | - ) |
|
62 | - ); |
|
63 | - |
|
64 | - $args['parent_setting'] = $args['settings']; |
|
65 | - $args['output'] = []; |
|
66 | - $args['wrapper_attrs'] = [ |
|
67 | - 'data-kirki-parent-control-type' => 'kirki-background', |
|
68 | - ]; |
|
69 | - |
|
70 | - if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) { |
|
71 | - $args['transport'] = 'postMessage'; |
|
72 | - } |
|
73 | - |
|
74 | - $default_bg_color = isset( $args['default']['background-color'] ) ? $args['default']['background-color'] : ''; |
|
75 | - |
|
76 | - /** |
|
77 | - * Background Color. |
|
78 | - */ |
|
79 | - new \Kirki\Field\Color( |
|
80 | - wp_parse_args( |
|
81 | - [ |
|
82 | - 'settings' => $args['settings'] . '[background-color]', |
|
83 | - 'label' => '', |
|
84 | - 'description' => esc_html__( 'Background Color', 'kirki' ), |
|
85 | - 'default' => $default_bg_color, |
|
86 | - 'section' => $args['section'], |
|
87 | - 'choices' => [ |
|
88 | - 'alpha' => true, |
|
89 | - ], |
|
90 | - ], |
|
91 | - $args |
|
92 | - ) |
|
93 | - ); |
|
94 | - |
|
95 | - /** |
|
96 | - * Background Image. |
|
97 | - */ |
|
98 | - new \Kirki\Field\Image( |
|
99 | - wp_parse_args( |
|
100 | - [ |
|
101 | - 'settings' => $args['settings'] . '[background-image]', |
|
102 | - 'label' => '', |
|
103 | - 'description' => esc_html__( 'Background Image', 'kirki' ), |
|
104 | - 'default' => isset( $args['default']['background-image'] ) ? $args['default']['background-image'] : '', |
|
105 | - 'section' => $args['section'], |
|
106 | - ], |
|
107 | - $args |
|
108 | - ) |
|
109 | - ); |
|
110 | - |
|
111 | - /** |
|
112 | - * Background Repeat. |
|
113 | - */ |
|
114 | - new Kirki\Field\Select( |
|
115 | - wp_parse_args( |
|
116 | - [ |
|
117 | - 'settings' => $args['settings'] . '[background-repeat]', |
|
118 | - 'label' => '', |
|
119 | - 'description' => esc_html__( 'Background Repeat', 'kirki' ), |
|
120 | - 'section' => $args['section'], |
|
121 | - 'default' => isset( $args['default']['background-repeat'] ) ? $args['default']['background-repeat'] : '', |
|
122 | - 'choices' => [ |
|
123 | - 'no-repeat' => esc_html__( 'No Repeat', 'kirki' ), |
|
124 | - 'repeat' => esc_html__( 'Repeat All', 'kirki' ), |
|
125 | - 'repeat-x' => esc_html__( 'Repeat Horizontally', 'kirki' ), |
|
126 | - 'repeat-y' => esc_html__( 'Repeat Vertically', 'kirki' ), |
|
127 | - ], |
|
128 | - 'required' => array_merge( |
|
129 | - $args['required'], |
|
130 | - [ |
|
131 | - [ |
|
132 | - 'setting' => $args['settings'], |
|
133 | - 'operator' => '!=', |
|
134 | - 'value' => '', |
|
135 | - 'choice' => 'background-image', |
|
136 | - ], |
|
137 | - ] |
|
138 | - ), |
|
139 | - ], |
|
140 | - $args |
|
141 | - ) |
|
142 | - ); |
|
143 | - |
|
144 | - /** |
|
145 | - * Background Position. |
|
146 | - */ |
|
147 | - new Kirki\Field\Select( |
|
148 | - wp_parse_args( |
|
149 | - [ |
|
150 | - 'settings' => $args['settings'] . '[background-position]', |
|
151 | - 'label' => '', |
|
152 | - 'description' => esc_html__( 'Background Position', 'kirki' ), |
|
153 | - 'default' => isset( $args['default']['background-position'] ) ? $args['default']['background-position'] : '', |
|
154 | - 'section' => $args['section'], |
|
155 | - 'choices' => [ |
|
156 | - 'left top' => esc_html__( 'Left Top', 'kirki' ), |
|
157 | - 'left center' => esc_html__( 'Left Center', 'kirki' ), |
|
158 | - 'left bottom' => esc_html__( 'Left Bottom', 'kirki' ), |
|
159 | - 'center top' => esc_html__( 'Center Top', 'kirki' ), |
|
160 | - 'center center' => esc_html__( 'Center Center', 'kirki' ), |
|
161 | - 'center bottom' => esc_html__( 'Center Bottom', 'kirki' ), |
|
162 | - 'right top' => esc_html__( 'Right Top', 'kirki' ), |
|
163 | - 'right center' => esc_html__( 'Right Center', 'kirki' ), |
|
164 | - 'right bottom' => esc_html__( 'Right Bottom', 'kirki' ), |
|
165 | - ], |
|
166 | - 'required' => array_merge( |
|
167 | - $args['required'], |
|
168 | - [ |
|
169 | - [ |
|
170 | - 'setting' => $args['settings'], |
|
171 | - 'operator' => '!=', |
|
172 | - 'value' => '', |
|
173 | - 'choice' => 'background-image', |
|
174 | - ], |
|
175 | - ] |
|
176 | - ), |
|
177 | - ], |
|
178 | - $args |
|
179 | - ) |
|
180 | - ); |
|
181 | - |
|
182 | - /** |
|
183 | - * Background size. |
|
184 | - */ |
|
185 | - new Kirki\Field\Radio_Buttonset( |
|
186 | - wp_parse_args( |
|
187 | - [ |
|
188 | - 'settings' => $args['settings'] . '[background-size]', |
|
189 | - 'label' => '', |
|
190 | - 'description' => esc_html__( 'Background Size', 'kirki' ), |
|
191 | - 'default' => isset( $args['default']['background-size'] ) ? $args['default']['background-size'] : '', |
|
192 | - 'section' => $args['section'], |
|
193 | - 'choices' => [ |
|
194 | - 'cover' => esc_html__( 'Cover', 'kirki' ), |
|
195 | - 'contain' => esc_html__( 'Contain', 'kirki' ), |
|
196 | - 'auto' => esc_html__( 'Auto', 'kirki' ), |
|
197 | - ], |
|
198 | - 'required' => array_merge( |
|
199 | - $args['required'], |
|
200 | - [ |
|
201 | - [ |
|
202 | - 'setting' => $args['settings'], |
|
203 | - 'operator' => '!=', |
|
204 | - 'value' => '', |
|
205 | - 'choice' => 'background-image', |
|
206 | - ], |
|
207 | - ] |
|
208 | - ), |
|
209 | - ], |
|
210 | - $args |
|
211 | - ) |
|
212 | - ); |
|
213 | - |
|
214 | - /** |
|
215 | - * Background attachment. |
|
216 | - */ |
|
217 | - new Kirki\Field\Radio_Buttonset( |
|
218 | - wp_parse_args( |
|
219 | - [ |
|
220 | - 'type' => 'kirki-radio-buttonset', |
|
221 | - 'settings' => $args['settings'] . '[background-attachment]', |
|
222 | - 'description' => esc_html__( 'Background Attachment', 'kirki' ), |
|
223 | - 'label' => '', |
|
224 | - 'default' => isset( $args['default']['background-attachment'] ) ? $args['default']['background-attachment'] : '', |
|
225 | - 'section' => $args['section'], |
|
226 | - 'choices' => [ |
|
227 | - 'scroll' => esc_html__( 'Scroll', 'kirki' ), |
|
228 | - 'fixed' => esc_html__( 'Fixed', 'kirki' ), |
|
229 | - ], |
|
230 | - 'required' => array_merge( |
|
231 | - $args['required'], |
|
232 | - [ |
|
233 | - [ |
|
234 | - 'setting' => $args['settings'], |
|
235 | - 'operator' => '!=', |
|
236 | - 'value' => '', |
|
237 | - 'choice' => 'background-image', |
|
238 | - ], |
|
239 | - ] |
|
240 | - ), |
|
241 | - ], |
|
242 | - $args |
|
243 | - ) |
|
244 | - ); |
|
245 | - |
|
246 | - add_action( 'customize_preview_init', [ $this, 'enqueue_scripts' ] ); |
|
247 | - add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
248 | - |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Sets the $sanitize_callback |
|
253 | - * |
|
254 | - * @access protected |
|
255 | - * @since 1.0 |
|
256 | - * @return void |
|
257 | - */ |
|
258 | - protected function set_sanitize_callback() { |
|
259 | - |
|
260 | - // If a custom sanitize_callback has been defined, |
|
261 | - // then we don't need to proceed any further. |
|
262 | - if ( ! empty( $this->sanitize_callback ) ) { |
|
263 | - return; |
|
264 | - } |
|
265 | - |
|
266 | - $this->sanitize_callback = [ '\Kirki\Field\Background', 'sanitize' ]; |
|
267 | - |
|
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Sanitizes background controls |
|
272 | - * |
|
273 | - * @static |
|
274 | - * @access public |
|
275 | - * @since 1.0 |
|
276 | - * @param array $value The value. |
|
277 | - * @return array |
|
278 | - */ |
|
279 | - public static function sanitize( $value ) { |
|
280 | - |
|
281 | - if ( ! is_array( $value ) ) { |
|
282 | - return []; |
|
283 | - } |
|
284 | - |
|
285 | - $sanitized_value = [ |
|
286 | - 'background-color' => '', |
|
287 | - 'background-image' => '', |
|
288 | - 'background-repeat' => '', |
|
289 | - 'background-position' => '', |
|
290 | - 'background-size' => '', |
|
291 | - 'background-attachment' => '', |
|
292 | - ]; |
|
293 | - |
|
294 | - if ( isset( $value['background-color'] ) ) { |
|
295 | - $sanitized_value['background-color'] = \Kirki\Field\Color::sanitize( $value['background-color'] ); |
|
296 | - } |
|
297 | - |
|
298 | - if ( isset( $value['background-image'] ) ) { |
|
299 | - $sanitized_value['background-image'] = esc_url_raw( $value['background-image'] ); |
|
300 | - } |
|
301 | - |
|
302 | - if ( isset( $value['background-repeat'] ) ) { |
|
303 | - $sanitized_value['background-repeat'] = in_array( |
|
304 | - $value['background-repeat'], |
|
305 | - [ |
|
306 | - 'no-repeat', |
|
307 | - 'repeat', |
|
308 | - 'repeat-x', |
|
309 | - 'repeat-y', |
|
310 | - ], |
|
311 | - true |
|
312 | - ) ? $value['background-repeat'] : ''; |
|
313 | - } |
|
314 | - |
|
315 | - if ( isset( $value['background-position'] ) ) { |
|
316 | - $sanitized_value['background-position'] = in_array( |
|
317 | - $value['background-position'], |
|
318 | - [ |
|
319 | - 'left top', |
|
320 | - 'left center', |
|
321 | - 'left bottom', |
|
322 | - 'center top', |
|
323 | - 'center center', |
|
324 | - 'center bottom', |
|
325 | - 'right top', |
|
326 | - 'right center', |
|
327 | - 'right bottom', |
|
328 | - ], |
|
329 | - true |
|
330 | - ) ? $value['background-position'] : ''; |
|
331 | - } |
|
332 | - |
|
333 | - if ( isset( $value['background-size'] ) ) { |
|
334 | - $sanitized_value['background-size'] = in_array( |
|
335 | - $value['background-size'], |
|
336 | - [ |
|
337 | - 'cover', |
|
338 | - 'contain', |
|
339 | - 'auto', |
|
340 | - ], |
|
341 | - true |
|
342 | - ) ? $value['background-size'] : ''; |
|
343 | - } |
|
344 | - |
|
345 | - if ( isset( $value['background-attachment'] ) ) { |
|
346 | - $sanitized_value['background-attachment'] = in_array( |
|
347 | - $value['background-attachment'], |
|
348 | - [ |
|
349 | - 'scroll', |
|
350 | - 'fixed', |
|
351 | - ], |
|
352 | - true |
|
353 | - ) ? $value['background-attachment'] : ''; |
|
354 | - } |
|
355 | - |
|
356 | - return $sanitized_value; |
|
357 | - |
|
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Sets the $js_vars |
|
362 | - * |
|
363 | - * @access protected |
|
364 | - * @since 1.0 |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - protected function set_js_vars() { |
|
368 | - |
|
369 | - // Typecast to array. |
|
370 | - $this->js_vars = (array) $this->js_vars; |
|
371 | - |
|
372 | - // Check if transport is set to auto. |
|
373 | - // If not, then skip the auto-calculations and exit early. |
|
374 | - if ( 'auto' !== $this->transport ) { |
|
375 | - return; |
|
376 | - } |
|
377 | - |
|
378 | - // Set transport to refresh initially. |
|
379 | - // Serves as a fallback in case we failt to auto-calculate js_vars. |
|
380 | - $this->transport = 'refresh'; |
|
381 | - |
|
382 | - $js_vars = []; |
|
383 | - |
|
384 | - // Try to auto-generate js_vars. |
|
385 | - // First we need to check if js_vars are empty, and that output is not empty. |
|
386 | - if ( empty( $this->js_vars ) && ! empty( $this->output ) ) { |
|
387 | - |
|
388 | - // Start going through each item in the $output array. |
|
389 | - foreach ( $this->output as $output ) { |
|
390 | - |
|
391 | - // If 'element' is not defined, skip this. |
|
392 | - if ( ! isset( $output['element'] ) ) { |
|
393 | - continue; |
|
394 | - } |
|
395 | - if ( is_array( $output['element'] ) ) { |
|
396 | - $output['element'] = implode( ',', $output['element'] ); |
|
397 | - } |
|
398 | - |
|
399 | - // If there's a sanitize_callback defined, skip this. |
|
400 | - if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) ) { |
|
401 | - continue; |
|
402 | - } |
|
403 | - |
|
404 | - // If we got this far, it's safe to add this. |
|
405 | - $js_vars[] = $output; |
|
406 | - } |
|
407 | - |
|
408 | - // Did we manage to get all the items from 'output'? |
|
409 | - // If not, then we're missing something so don't add this. |
|
410 | - if ( count( $js_vars ) !== count( $this->output ) ) { |
|
411 | - return; |
|
412 | - } |
|
413 | - $this->js_vars = $js_vars; |
|
414 | - $this->transport = 'postMessage'; |
|
415 | - } |
|
416 | - |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Override parent method. No need to register any setting. |
|
421 | - * |
|
422 | - * @access public |
|
423 | - * @since 0.1 |
|
424 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
425 | - * @return void |
|
426 | - */ |
|
427 | - public function add_setting( $wp_customize ) {} |
|
428 | - |
|
429 | - /** |
|
430 | - * Override the parent method. No need for a control. |
|
431 | - * |
|
432 | - * @access public |
|
433 | - * @since 0.1 |
|
434 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
435 | - * @return void |
|
436 | - */ |
|
437 | - public function add_control( $wp_customize ) {} |
|
438 | - |
|
439 | - /** |
|
440 | - * Enqueue scripts & styles. |
|
441 | - * |
|
442 | - * @access public |
|
443 | - * @since 1.0 |
|
444 | - * @return void |
|
445 | - */ |
|
446 | - public function enqueue_scripts() { |
|
447 | - |
|
448 | - wp_enqueue_script( 'kirki-typography', URL::get_from_path( __DIR__ ) . '/script.js', [ 'wp-hooks' ], '1.0', true ); |
|
449 | - |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Adds a custom output class for typography fields. |
|
454 | - * |
|
455 | - * @access public |
|
456 | - * @since 1.0 |
|
457 | - * @param array $classnames The array of classnames. |
|
458 | - * @return array |
|
459 | - */ |
|
460 | - public function output_control_classnames( $classnames ) { |
|
461 | - |
|
462 | - $classnames['kirki-background'] = '\Kirki\Field\CSS\Background'; |
|
463 | - return $classnames; |
|
464 | - |
|
465 | - } |
|
24 | + /** |
|
25 | + * The field type. |
|
26 | + * |
|
27 | + * @access public |
|
28 | + * @since 1.0 |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + public $type = 'kirki-background'; |
|
32 | + |
|
33 | + /** |
|
34 | + * Extra logic for the field. |
|
35 | + * |
|
36 | + * Adds all sub-fields. |
|
37 | + * |
|
38 | + * @access public |
|
39 | + * @param array $args The arguments of the field. |
|
40 | + */ |
|
41 | + public function init( $args ) { |
|
42 | + |
|
43 | + $args['required'] = isset( $args['required'] ) ? (array) $args['required'] : []; |
|
44 | + $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global'; |
|
45 | + |
|
46 | + /** |
|
47 | + * Add a hidden field, the label & description. |
|
48 | + */ |
|
49 | + new \Kirki\Field\Generic( |
|
50 | + wp_parse_args( |
|
51 | + [ |
|
52 | + 'type' => 'kirki-generic', |
|
53 | + 'default' => '', |
|
54 | + 'choices' => [ |
|
55 | + 'type' => 'hidden', |
|
56 | + 'parent_type' => 'kirki-background', |
|
57 | + ], |
|
58 | + 'sanitize_callback' => [ '\Kirki\Field\Background', 'sanitize' ], |
|
59 | + ], |
|
60 | + $args |
|
61 | + ) |
|
62 | + ); |
|
63 | + |
|
64 | + $args['parent_setting'] = $args['settings']; |
|
65 | + $args['output'] = []; |
|
66 | + $args['wrapper_attrs'] = [ |
|
67 | + 'data-kirki-parent-control-type' => 'kirki-background', |
|
68 | + ]; |
|
69 | + |
|
70 | + if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) { |
|
71 | + $args['transport'] = 'postMessage'; |
|
72 | + } |
|
73 | + |
|
74 | + $default_bg_color = isset( $args['default']['background-color'] ) ? $args['default']['background-color'] : ''; |
|
75 | + |
|
76 | + /** |
|
77 | + * Background Color. |
|
78 | + */ |
|
79 | + new \Kirki\Field\Color( |
|
80 | + wp_parse_args( |
|
81 | + [ |
|
82 | + 'settings' => $args['settings'] . '[background-color]', |
|
83 | + 'label' => '', |
|
84 | + 'description' => esc_html__( 'Background Color', 'kirki' ), |
|
85 | + 'default' => $default_bg_color, |
|
86 | + 'section' => $args['section'], |
|
87 | + 'choices' => [ |
|
88 | + 'alpha' => true, |
|
89 | + ], |
|
90 | + ], |
|
91 | + $args |
|
92 | + ) |
|
93 | + ); |
|
94 | + |
|
95 | + /** |
|
96 | + * Background Image. |
|
97 | + */ |
|
98 | + new \Kirki\Field\Image( |
|
99 | + wp_parse_args( |
|
100 | + [ |
|
101 | + 'settings' => $args['settings'] . '[background-image]', |
|
102 | + 'label' => '', |
|
103 | + 'description' => esc_html__( 'Background Image', 'kirki' ), |
|
104 | + 'default' => isset( $args['default']['background-image'] ) ? $args['default']['background-image'] : '', |
|
105 | + 'section' => $args['section'], |
|
106 | + ], |
|
107 | + $args |
|
108 | + ) |
|
109 | + ); |
|
110 | + |
|
111 | + /** |
|
112 | + * Background Repeat. |
|
113 | + */ |
|
114 | + new Kirki\Field\Select( |
|
115 | + wp_parse_args( |
|
116 | + [ |
|
117 | + 'settings' => $args['settings'] . '[background-repeat]', |
|
118 | + 'label' => '', |
|
119 | + 'description' => esc_html__( 'Background Repeat', 'kirki' ), |
|
120 | + 'section' => $args['section'], |
|
121 | + 'default' => isset( $args['default']['background-repeat'] ) ? $args['default']['background-repeat'] : '', |
|
122 | + 'choices' => [ |
|
123 | + 'no-repeat' => esc_html__( 'No Repeat', 'kirki' ), |
|
124 | + 'repeat' => esc_html__( 'Repeat All', 'kirki' ), |
|
125 | + 'repeat-x' => esc_html__( 'Repeat Horizontally', 'kirki' ), |
|
126 | + 'repeat-y' => esc_html__( 'Repeat Vertically', 'kirki' ), |
|
127 | + ], |
|
128 | + 'required' => array_merge( |
|
129 | + $args['required'], |
|
130 | + [ |
|
131 | + [ |
|
132 | + 'setting' => $args['settings'], |
|
133 | + 'operator' => '!=', |
|
134 | + 'value' => '', |
|
135 | + 'choice' => 'background-image', |
|
136 | + ], |
|
137 | + ] |
|
138 | + ), |
|
139 | + ], |
|
140 | + $args |
|
141 | + ) |
|
142 | + ); |
|
143 | + |
|
144 | + /** |
|
145 | + * Background Position. |
|
146 | + */ |
|
147 | + new Kirki\Field\Select( |
|
148 | + wp_parse_args( |
|
149 | + [ |
|
150 | + 'settings' => $args['settings'] . '[background-position]', |
|
151 | + 'label' => '', |
|
152 | + 'description' => esc_html__( 'Background Position', 'kirki' ), |
|
153 | + 'default' => isset( $args['default']['background-position'] ) ? $args['default']['background-position'] : '', |
|
154 | + 'section' => $args['section'], |
|
155 | + 'choices' => [ |
|
156 | + 'left top' => esc_html__( 'Left Top', 'kirki' ), |
|
157 | + 'left center' => esc_html__( 'Left Center', 'kirki' ), |
|
158 | + 'left bottom' => esc_html__( 'Left Bottom', 'kirki' ), |
|
159 | + 'center top' => esc_html__( 'Center Top', 'kirki' ), |
|
160 | + 'center center' => esc_html__( 'Center Center', 'kirki' ), |
|
161 | + 'center bottom' => esc_html__( 'Center Bottom', 'kirki' ), |
|
162 | + 'right top' => esc_html__( 'Right Top', 'kirki' ), |
|
163 | + 'right center' => esc_html__( 'Right Center', 'kirki' ), |
|
164 | + 'right bottom' => esc_html__( 'Right Bottom', 'kirki' ), |
|
165 | + ], |
|
166 | + 'required' => array_merge( |
|
167 | + $args['required'], |
|
168 | + [ |
|
169 | + [ |
|
170 | + 'setting' => $args['settings'], |
|
171 | + 'operator' => '!=', |
|
172 | + 'value' => '', |
|
173 | + 'choice' => 'background-image', |
|
174 | + ], |
|
175 | + ] |
|
176 | + ), |
|
177 | + ], |
|
178 | + $args |
|
179 | + ) |
|
180 | + ); |
|
181 | + |
|
182 | + /** |
|
183 | + * Background size. |
|
184 | + */ |
|
185 | + new Kirki\Field\Radio_Buttonset( |
|
186 | + wp_parse_args( |
|
187 | + [ |
|
188 | + 'settings' => $args['settings'] . '[background-size]', |
|
189 | + 'label' => '', |
|
190 | + 'description' => esc_html__( 'Background Size', 'kirki' ), |
|
191 | + 'default' => isset( $args['default']['background-size'] ) ? $args['default']['background-size'] : '', |
|
192 | + 'section' => $args['section'], |
|
193 | + 'choices' => [ |
|
194 | + 'cover' => esc_html__( 'Cover', 'kirki' ), |
|
195 | + 'contain' => esc_html__( 'Contain', 'kirki' ), |
|
196 | + 'auto' => esc_html__( 'Auto', 'kirki' ), |
|
197 | + ], |
|
198 | + 'required' => array_merge( |
|
199 | + $args['required'], |
|
200 | + [ |
|
201 | + [ |
|
202 | + 'setting' => $args['settings'], |
|
203 | + 'operator' => '!=', |
|
204 | + 'value' => '', |
|
205 | + 'choice' => 'background-image', |
|
206 | + ], |
|
207 | + ] |
|
208 | + ), |
|
209 | + ], |
|
210 | + $args |
|
211 | + ) |
|
212 | + ); |
|
213 | + |
|
214 | + /** |
|
215 | + * Background attachment. |
|
216 | + */ |
|
217 | + new Kirki\Field\Radio_Buttonset( |
|
218 | + wp_parse_args( |
|
219 | + [ |
|
220 | + 'type' => 'kirki-radio-buttonset', |
|
221 | + 'settings' => $args['settings'] . '[background-attachment]', |
|
222 | + 'description' => esc_html__( 'Background Attachment', 'kirki' ), |
|
223 | + 'label' => '', |
|
224 | + 'default' => isset( $args['default']['background-attachment'] ) ? $args['default']['background-attachment'] : '', |
|
225 | + 'section' => $args['section'], |
|
226 | + 'choices' => [ |
|
227 | + 'scroll' => esc_html__( 'Scroll', 'kirki' ), |
|
228 | + 'fixed' => esc_html__( 'Fixed', 'kirki' ), |
|
229 | + ], |
|
230 | + 'required' => array_merge( |
|
231 | + $args['required'], |
|
232 | + [ |
|
233 | + [ |
|
234 | + 'setting' => $args['settings'], |
|
235 | + 'operator' => '!=', |
|
236 | + 'value' => '', |
|
237 | + 'choice' => 'background-image', |
|
238 | + ], |
|
239 | + ] |
|
240 | + ), |
|
241 | + ], |
|
242 | + $args |
|
243 | + ) |
|
244 | + ); |
|
245 | + |
|
246 | + add_action( 'customize_preview_init', [ $this, 'enqueue_scripts' ] ); |
|
247 | + add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
248 | + |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Sets the $sanitize_callback |
|
253 | + * |
|
254 | + * @access protected |
|
255 | + * @since 1.0 |
|
256 | + * @return void |
|
257 | + */ |
|
258 | + protected function set_sanitize_callback() { |
|
259 | + |
|
260 | + // If a custom sanitize_callback has been defined, |
|
261 | + // then we don't need to proceed any further. |
|
262 | + if ( ! empty( $this->sanitize_callback ) ) { |
|
263 | + return; |
|
264 | + } |
|
265 | + |
|
266 | + $this->sanitize_callback = [ '\Kirki\Field\Background', 'sanitize' ]; |
|
267 | + |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Sanitizes background controls |
|
272 | + * |
|
273 | + * @static |
|
274 | + * @access public |
|
275 | + * @since 1.0 |
|
276 | + * @param array $value The value. |
|
277 | + * @return array |
|
278 | + */ |
|
279 | + public static function sanitize( $value ) { |
|
280 | + |
|
281 | + if ( ! is_array( $value ) ) { |
|
282 | + return []; |
|
283 | + } |
|
284 | + |
|
285 | + $sanitized_value = [ |
|
286 | + 'background-color' => '', |
|
287 | + 'background-image' => '', |
|
288 | + 'background-repeat' => '', |
|
289 | + 'background-position' => '', |
|
290 | + 'background-size' => '', |
|
291 | + 'background-attachment' => '', |
|
292 | + ]; |
|
293 | + |
|
294 | + if ( isset( $value['background-color'] ) ) { |
|
295 | + $sanitized_value['background-color'] = \Kirki\Field\Color::sanitize( $value['background-color'] ); |
|
296 | + } |
|
297 | + |
|
298 | + if ( isset( $value['background-image'] ) ) { |
|
299 | + $sanitized_value['background-image'] = esc_url_raw( $value['background-image'] ); |
|
300 | + } |
|
301 | + |
|
302 | + if ( isset( $value['background-repeat'] ) ) { |
|
303 | + $sanitized_value['background-repeat'] = in_array( |
|
304 | + $value['background-repeat'], |
|
305 | + [ |
|
306 | + 'no-repeat', |
|
307 | + 'repeat', |
|
308 | + 'repeat-x', |
|
309 | + 'repeat-y', |
|
310 | + ], |
|
311 | + true |
|
312 | + ) ? $value['background-repeat'] : ''; |
|
313 | + } |
|
314 | + |
|
315 | + if ( isset( $value['background-position'] ) ) { |
|
316 | + $sanitized_value['background-position'] = in_array( |
|
317 | + $value['background-position'], |
|
318 | + [ |
|
319 | + 'left top', |
|
320 | + 'left center', |
|
321 | + 'left bottom', |
|
322 | + 'center top', |
|
323 | + 'center center', |
|
324 | + 'center bottom', |
|
325 | + 'right top', |
|
326 | + 'right center', |
|
327 | + 'right bottom', |
|
328 | + ], |
|
329 | + true |
|
330 | + ) ? $value['background-position'] : ''; |
|
331 | + } |
|
332 | + |
|
333 | + if ( isset( $value['background-size'] ) ) { |
|
334 | + $sanitized_value['background-size'] = in_array( |
|
335 | + $value['background-size'], |
|
336 | + [ |
|
337 | + 'cover', |
|
338 | + 'contain', |
|
339 | + 'auto', |
|
340 | + ], |
|
341 | + true |
|
342 | + ) ? $value['background-size'] : ''; |
|
343 | + } |
|
344 | + |
|
345 | + if ( isset( $value['background-attachment'] ) ) { |
|
346 | + $sanitized_value['background-attachment'] = in_array( |
|
347 | + $value['background-attachment'], |
|
348 | + [ |
|
349 | + 'scroll', |
|
350 | + 'fixed', |
|
351 | + ], |
|
352 | + true |
|
353 | + ) ? $value['background-attachment'] : ''; |
|
354 | + } |
|
355 | + |
|
356 | + return $sanitized_value; |
|
357 | + |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Sets the $js_vars |
|
362 | + * |
|
363 | + * @access protected |
|
364 | + * @since 1.0 |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + protected function set_js_vars() { |
|
368 | + |
|
369 | + // Typecast to array. |
|
370 | + $this->js_vars = (array) $this->js_vars; |
|
371 | + |
|
372 | + // Check if transport is set to auto. |
|
373 | + // If not, then skip the auto-calculations and exit early. |
|
374 | + if ( 'auto' !== $this->transport ) { |
|
375 | + return; |
|
376 | + } |
|
377 | + |
|
378 | + // Set transport to refresh initially. |
|
379 | + // Serves as a fallback in case we failt to auto-calculate js_vars. |
|
380 | + $this->transport = 'refresh'; |
|
381 | + |
|
382 | + $js_vars = []; |
|
383 | + |
|
384 | + // Try to auto-generate js_vars. |
|
385 | + // First we need to check if js_vars are empty, and that output is not empty. |
|
386 | + if ( empty( $this->js_vars ) && ! empty( $this->output ) ) { |
|
387 | + |
|
388 | + // Start going through each item in the $output array. |
|
389 | + foreach ( $this->output as $output ) { |
|
390 | + |
|
391 | + // If 'element' is not defined, skip this. |
|
392 | + if ( ! isset( $output['element'] ) ) { |
|
393 | + continue; |
|
394 | + } |
|
395 | + if ( is_array( $output['element'] ) ) { |
|
396 | + $output['element'] = implode( ',', $output['element'] ); |
|
397 | + } |
|
398 | + |
|
399 | + // If there's a sanitize_callback defined, skip this. |
|
400 | + if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) ) { |
|
401 | + continue; |
|
402 | + } |
|
403 | + |
|
404 | + // If we got this far, it's safe to add this. |
|
405 | + $js_vars[] = $output; |
|
406 | + } |
|
407 | + |
|
408 | + // Did we manage to get all the items from 'output'? |
|
409 | + // If not, then we're missing something so don't add this. |
|
410 | + if ( count( $js_vars ) !== count( $this->output ) ) { |
|
411 | + return; |
|
412 | + } |
|
413 | + $this->js_vars = $js_vars; |
|
414 | + $this->transport = 'postMessage'; |
|
415 | + } |
|
416 | + |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Override parent method. No need to register any setting. |
|
421 | + * |
|
422 | + * @access public |
|
423 | + * @since 0.1 |
|
424 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
425 | + * @return void |
|
426 | + */ |
|
427 | + public function add_setting( $wp_customize ) {} |
|
428 | + |
|
429 | + /** |
|
430 | + * Override the parent method. No need for a control. |
|
431 | + * |
|
432 | + * @access public |
|
433 | + * @since 0.1 |
|
434 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
435 | + * @return void |
|
436 | + */ |
|
437 | + public function add_control( $wp_customize ) {} |
|
438 | + |
|
439 | + /** |
|
440 | + * Enqueue scripts & styles. |
|
441 | + * |
|
442 | + * @access public |
|
443 | + * @since 1.0 |
|
444 | + * @return void |
|
445 | + */ |
|
446 | + public function enqueue_scripts() { |
|
447 | + |
|
448 | + wp_enqueue_script( 'kirki-typography', URL::get_from_path( __DIR__ ) . '/script.js', [ 'wp-hooks' ], '1.0', true ); |
|
449 | + |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Adds a custom output class for typography fields. |
|
454 | + * |
|
455 | + * @access public |
|
456 | + * @since 1.0 |
|
457 | + * @param array $classnames The array of classnames. |
|
458 | + * @return array |
|
459 | + */ |
|
460 | + public function output_control_classnames( $classnames ) { |
|
461 | + |
|
462 | + $classnames['kirki-background'] = '\Kirki\Field\CSS\Background'; |
|
463 | + return $classnames; |
|
464 | + |
|
465 | + } |
|
466 | 466 | |
467 | 467 | } |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | * @access public |
39 | 39 | * @param array $args The arguments of the field. |
40 | 40 | */ |
41 | - public function init( $args ) { |
|
41 | + public function init($args) { |
|
42 | 42 | |
43 | - $args['required'] = isset( $args['required'] ) ? (array) $args['required'] : []; |
|
44 | - $args['kirki_config'] = isset( $args['kirki_config'] ) ? $args['kirki_config'] : 'global'; |
|
43 | + $args['required'] = isset($args['required']) ? (array) $args['required'] : []; |
|
44 | + $args['kirki_config'] = isset($args['kirki_config']) ? $args['kirki_config'] : 'global'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * Add a hidden field, the label & description. |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | 'type' => 'hidden', |
56 | 56 | 'parent_type' => 'kirki-background', |
57 | 57 | ], |
58 | - 'sanitize_callback' => [ '\Kirki\Field\Background', 'sanitize' ], |
|
58 | + 'sanitize_callback' => ['\Kirki\Field\Background', 'sanitize'], |
|
59 | 59 | ], |
60 | 60 | $args |
61 | 61 | ) |
@@ -67,11 +67,11 @@ discard block |
||
67 | 67 | 'data-kirki-parent-control-type' => 'kirki-background', |
68 | 68 | ]; |
69 | 69 | |
70 | - if ( isset( $args['transport'] ) && 'auto' === $args['transport'] ) { |
|
70 | + if (isset($args['transport']) && 'auto' === $args['transport']) { |
|
71 | 71 | $args['transport'] = 'postMessage'; |
72 | 72 | } |
73 | 73 | |
74 | - $default_bg_color = isset( $args['default']['background-color'] ) ? $args['default']['background-color'] : ''; |
|
74 | + $default_bg_color = isset($args['default']['background-color']) ? $args['default']['background-color'] : ''; |
|
75 | 75 | |
76 | 76 | /** |
77 | 77 | * Background Color. |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | [ |
82 | 82 | 'settings' => $args['settings'] . '[background-color]', |
83 | 83 | 'label' => '', |
84 | - 'description' => esc_html__( 'Background Color', 'kirki' ), |
|
84 | + 'description' => esc_html__('Background Color', 'kirki'), |
|
85 | 85 | 'default' => $default_bg_color, |
86 | 86 | 'section' => $args['section'], |
87 | 87 | 'choices' => [ |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | [ |
101 | 101 | 'settings' => $args['settings'] . '[background-image]', |
102 | 102 | 'label' => '', |
103 | - 'description' => esc_html__( 'Background Image', 'kirki' ), |
|
104 | - 'default' => isset( $args['default']['background-image'] ) ? $args['default']['background-image'] : '', |
|
103 | + 'description' => esc_html__('Background Image', 'kirki'), |
|
104 | + 'default' => isset($args['default']['background-image']) ? $args['default']['background-image'] : '', |
|
105 | 105 | 'section' => $args['section'], |
106 | 106 | ], |
107 | 107 | $args |
@@ -116,14 +116,14 @@ discard block |
||
116 | 116 | [ |
117 | 117 | 'settings' => $args['settings'] . '[background-repeat]', |
118 | 118 | 'label' => '', |
119 | - 'description' => esc_html__( 'Background Repeat', 'kirki' ), |
|
119 | + 'description' => esc_html__('Background Repeat', 'kirki'), |
|
120 | 120 | 'section' => $args['section'], |
121 | - 'default' => isset( $args['default']['background-repeat'] ) ? $args['default']['background-repeat'] : '', |
|
121 | + 'default' => isset($args['default']['background-repeat']) ? $args['default']['background-repeat'] : '', |
|
122 | 122 | 'choices' => [ |
123 | - 'no-repeat' => esc_html__( 'No Repeat', 'kirki' ), |
|
124 | - 'repeat' => esc_html__( 'Repeat All', 'kirki' ), |
|
125 | - 'repeat-x' => esc_html__( 'Repeat Horizontally', 'kirki' ), |
|
126 | - 'repeat-y' => esc_html__( 'Repeat Vertically', 'kirki' ), |
|
123 | + 'no-repeat' => esc_html__('No Repeat', 'kirki'), |
|
124 | + 'repeat' => esc_html__('Repeat All', 'kirki'), |
|
125 | + 'repeat-x' => esc_html__('Repeat Horizontally', 'kirki'), |
|
126 | + 'repeat-y' => esc_html__('Repeat Vertically', 'kirki'), |
|
127 | 127 | ], |
128 | 128 | 'required' => array_merge( |
129 | 129 | $args['required'], |
@@ -149,19 +149,19 @@ discard block |
||
149 | 149 | [ |
150 | 150 | 'settings' => $args['settings'] . '[background-position]', |
151 | 151 | 'label' => '', |
152 | - 'description' => esc_html__( 'Background Position', 'kirki' ), |
|
153 | - 'default' => isset( $args['default']['background-position'] ) ? $args['default']['background-position'] : '', |
|
152 | + 'description' => esc_html__('Background Position', 'kirki'), |
|
153 | + 'default' => isset($args['default']['background-position']) ? $args['default']['background-position'] : '', |
|
154 | 154 | 'section' => $args['section'], |
155 | 155 | 'choices' => [ |
156 | - 'left top' => esc_html__( 'Left Top', 'kirki' ), |
|
157 | - 'left center' => esc_html__( 'Left Center', 'kirki' ), |
|
158 | - 'left bottom' => esc_html__( 'Left Bottom', 'kirki' ), |
|
159 | - 'center top' => esc_html__( 'Center Top', 'kirki' ), |
|
160 | - 'center center' => esc_html__( 'Center Center', 'kirki' ), |
|
161 | - 'center bottom' => esc_html__( 'Center Bottom', 'kirki' ), |
|
162 | - 'right top' => esc_html__( 'Right Top', 'kirki' ), |
|
163 | - 'right center' => esc_html__( 'Right Center', 'kirki' ), |
|
164 | - 'right bottom' => esc_html__( 'Right Bottom', 'kirki' ), |
|
156 | + 'left top' => esc_html__('Left Top', 'kirki'), |
|
157 | + 'left center' => esc_html__('Left Center', 'kirki'), |
|
158 | + 'left bottom' => esc_html__('Left Bottom', 'kirki'), |
|
159 | + 'center top' => esc_html__('Center Top', 'kirki'), |
|
160 | + 'center center' => esc_html__('Center Center', 'kirki'), |
|
161 | + 'center bottom' => esc_html__('Center Bottom', 'kirki'), |
|
162 | + 'right top' => esc_html__('Right Top', 'kirki'), |
|
163 | + 'right center' => esc_html__('Right Center', 'kirki'), |
|
164 | + 'right bottom' => esc_html__('Right Bottom', 'kirki'), |
|
165 | 165 | ], |
166 | 166 | 'required' => array_merge( |
167 | 167 | $args['required'], |
@@ -187,13 +187,13 @@ discard block |
||
187 | 187 | [ |
188 | 188 | 'settings' => $args['settings'] . '[background-size]', |
189 | 189 | 'label' => '', |
190 | - 'description' => esc_html__( 'Background Size', 'kirki' ), |
|
191 | - 'default' => isset( $args['default']['background-size'] ) ? $args['default']['background-size'] : '', |
|
190 | + 'description' => esc_html__('Background Size', 'kirki'), |
|
191 | + 'default' => isset($args['default']['background-size']) ? $args['default']['background-size'] : '', |
|
192 | 192 | 'section' => $args['section'], |
193 | 193 | 'choices' => [ |
194 | - 'cover' => esc_html__( 'Cover', 'kirki' ), |
|
195 | - 'contain' => esc_html__( 'Contain', 'kirki' ), |
|
196 | - 'auto' => esc_html__( 'Auto', 'kirki' ), |
|
194 | + 'cover' => esc_html__('Cover', 'kirki'), |
|
195 | + 'contain' => esc_html__('Contain', 'kirki'), |
|
196 | + 'auto' => esc_html__('Auto', 'kirki'), |
|
197 | 197 | ], |
198 | 198 | 'required' => array_merge( |
199 | 199 | $args['required'], |
@@ -219,13 +219,13 @@ discard block |
||
219 | 219 | [ |
220 | 220 | 'type' => 'kirki-radio-buttonset', |
221 | 221 | 'settings' => $args['settings'] . '[background-attachment]', |
222 | - 'description' => esc_html__( 'Background Attachment', 'kirki' ), |
|
222 | + 'description' => esc_html__('Background Attachment', 'kirki'), |
|
223 | 223 | 'label' => '', |
224 | - 'default' => isset( $args['default']['background-attachment'] ) ? $args['default']['background-attachment'] : '', |
|
224 | + 'default' => isset($args['default']['background-attachment']) ? $args['default']['background-attachment'] : '', |
|
225 | 225 | 'section' => $args['section'], |
226 | 226 | 'choices' => [ |
227 | - 'scroll' => esc_html__( 'Scroll', 'kirki' ), |
|
228 | - 'fixed' => esc_html__( 'Fixed', 'kirki' ), |
|
227 | + 'scroll' => esc_html__('Scroll', 'kirki'), |
|
228 | + 'fixed' => esc_html__('Fixed', 'kirki'), |
|
229 | 229 | ], |
230 | 230 | 'required' => array_merge( |
231 | 231 | $args['required'], |
@@ -243,8 +243,8 @@ discard block |
||
243 | 243 | ) |
244 | 244 | ); |
245 | 245 | |
246 | - add_action( 'customize_preview_init', [ $this, 'enqueue_scripts' ] ); |
|
247 | - add_filter( 'kirki_output_control_classnames', [ $this, 'output_control_classnames' ] ); |
|
246 | + add_action('customize_preview_init', [$this, 'enqueue_scripts']); |
|
247 | + add_filter('kirki_output_control_classnames', [$this, 'output_control_classnames']); |
|
248 | 248 | |
249 | 249 | } |
250 | 250 | |
@@ -259,11 +259,11 @@ discard block |
||
259 | 259 | |
260 | 260 | // If a custom sanitize_callback has been defined, |
261 | 261 | // then we don't need to proceed any further. |
262 | - if ( ! empty( $this->sanitize_callback ) ) { |
|
262 | + if (!empty($this->sanitize_callback)) { |
|
263 | 263 | return; |
264 | 264 | } |
265 | 265 | |
266 | - $this->sanitize_callback = [ '\Kirki\Field\Background', 'sanitize' ]; |
|
266 | + $this->sanitize_callback = ['\Kirki\Field\Background', 'sanitize']; |
|
267 | 267 | |
268 | 268 | } |
269 | 269 | |
@@ -276,9 +276,9 @@ discard block |
||
276 | 276 | * @param array $value The value. |
277 | 277 | * @return array |
278 | 278 | */ |
279 | - public static function sanitize( $value ) { |
|
279 | + public static function sanitize($value) { |
|
280 | 280 | |
281 | - if ( ! is_array( $value ) ) { |
|
281 | + if (!is_array($value)) { |
|
282 | 282 | return []; |
283 | 283 | } |
284 | 284 | |
@@ -291,15 +291,15 @@ discard block |
||
291 | 291 | 'background-attachment' => '', |
292 | 292 | ]; |
293 | 293 | |
294 | - if ( isset( $value['background-color'] ) ) { |
|
295 | - $sanitized_value['background-color'] = \Kirki\Field\Color::sanitize( $value['background-color'] ); |
|
294 | + if (isset($value['background-color'])) { |
|
295 | + $sanitized_value['background-color'] = \Kirki\Field\Color::sanitize($value['background-color']); |
|
296 | 296 | } |
297 | 297 | |
298 | - if ( isset( $value['background-image'] ) ) { |
|
299 | - $sanitized_value['background-image'] = esc_url_raw( $value['background-image'] ); |
|
298 | + if (isset($value['background-image'])) { |
|
299 | + $sanitized_value['background-image'] = esc_url_raw($value['background-image']); |
|
300 | 300 | } |
301 | 301 | |
302 | - if ( isset( $value['background-repeat'] ) ) { |
|
302 | + if (isset($value['background-repeat'])) { |
|
303 | 303 | $sanitized_value['background-repeat'] = in_array( |
304 | 304 | $value['background-repeat'], |
305 | 305 | [ |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | ) ? $value['background-repeat'] : ''; |
313 | 313 | } |
314 | 314 | |
315 | - if ( isset( $value['background-position'] ) ) { |
|
315 | + if (isset($value['background-position'])) { |
|
316 | 316 | $sanitized_value['background-position'] = in_array( |
317 | 317 | $value['background-position'], |
318 | 318 | [ |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | ) ? $value['background-position'] : ''; |
331 | 331 | } |
332 | 332 | |
333 | - if ( isset( $value['background-size'] ) ) { |
|
333 | + if (isset($value['background-size'])) { |
|
334 | 334 | $sanitized_value['background-size'] = in_array( |
335 | 335 | $value['background-size'], |
336 | 336 | [ |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | ) ? $value['background-size'] : ''; |
343 | 343 | } |
344 | 344 | |
345 | - if ( isset( $value['background-attachment'] ) ) { |
|
345 | + if (isset($value['background-attachment'])) { |
|
346 | 346 | $sanitized_value['background-attachment'] = in_array( |
347 | 347 | $value['background-attachment'], |
348 | 348 | [ |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | |
372 | 372 | // Check if transport is set to auto. |
373 | 373 | // If not, then skip the auto-calculations and exit early. |
374 | - if ( 'auto' !== $this->transport ) { |
|
374 | + if ('auto' !== $this->transport) { |
|
375 | 375 | return; |
376 | 376 | } |
377 | 377 | |
@@ -383,21 +383,21 @@ discard block |
||
383 | 383 | |
384 | 384 | // Try to auto-generate js_vars. |
385 | 385 | // First we need to check if js_vars are empty, and that output is not empty. |
386 | - if ( empty( $this->js_vars ) && ! empty( $this->output ) ) { |
|
386 | + if (empty($this->js_vars) && !empty($this->output)) { |
|
387 | 387 | |
388 | 388 | // Start going through each item in the $output array. |
389 | - foreach ( $this->output as $output ) { |
|
389 | + foreach ($this->output as $output) { |
|
390 | 390 | |
391 | 391 | // If 'element' is not defined, skip this. |
392 | - if ( ! isset( $output['element'] ) ) { |
|
392 | + if (!isset($output['element'])) { |
|
393 | 393 | continue; |
394 | 394 | } |
395 | - if ( is_array( $output['element'] ) ) { |
|
396 | - $output['element'] = implode( ',', $output['element'] ); |
|
395 | + if (is_array($output['element'])) { |
|
396 | + $output['element'] = implode(',', $output['element']); |
|
397 | 397 | } |
398 | 398 | |
399 | 399 | // If there's a sanitize_callback defined, skip this. |
400 | - if ( isset( $output['sanitize_callback'] ) && ! empty( $output['sanitize_callback'] ) ) { |
|
400 | + if (isset($output['sanitize_callback']) && !empty($output['sanitize_callback'])) { |
|
401 | 401 | continue; |
402 | 402 | } |
403 | 403 | |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | |
408 | 408 | // Did we manage to get all the items from 'output'? |
409 | 409 | // If not, then we're missing something so don't add this. |
410 | - if ( count( $js_vars ) !== count( $this->output ) ) { |
|
410 | + if (count($js_vars) !== count($this->output)) { |
|
411 | 411 | return; |
412 | 412 | } |
413 | 413 | $this->js_vars = $js_vars; |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
425 | 425 | * @return void |
426 | 426 | */ |
427 | - public function add_setting( $wp_customize ) {} |
|
427 | + public function add_setting($wp_customize) {} |
|
428 | 428 | |
429 | 429 | /** |
430 | 430 | * Override the parent method. No need for a control. |
@@ -434,7 +434,7 @@ discard block |
||
434 | 434 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
435 | 435 | * @return void |
436 | 436 | */ |
437 | - public function add_control( $wp_customize ) {} |
|
437 | + public function add_control($wp_customize) {} |
|
438 | 438 | |
439 | 439 | /** |
440 | 440 | * Enqueue scripts & styles. |
@@ -445,7 +445,7 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function enqueue_scripts() { |
447 | 447 | |
448 | - wp_enqueue_script( 'kirki-typography', URL::get_from_path( __DIR__ ) . '/script.js', [ 'wp-hooks' ], '1.0', true ); |
|
448 | + wp_enqueue_script('kirki-typography', URL::get_from_path(__DIR__) . '/script.js', ['wp-hooks'], '1.0', true); |
|
449 | 449 | |
450 | 450 | } |
451 | 451 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | * @param array $classnames The array of classnames. |
458 | 458 | * @return array |
459 | 459 | */ |
460 | - public function output_control_classnames( $classnames ) { |
|
460 | + public function output_control_classnames($classnames) { |
|
461 | 461 | |
462 | 462 | $classnames['kirki-background'] = '\Kirki\Field\CSS\Background'; |
463 | 463 | return $classnames; |
@@ -21,327 +21,327 @@ |
||
21 | 21 | */ |
22 | 22 | class Base extends \WP_Customize_Control { |
23 | 23 | |
24 | - /** |
|
25 | - * Used to automatically generate all CSS output. |
|
26 | - * |
|
27 | - * Whitelisting property for use in Kirki modules. |
|
28 | - * |
|
29 | - * @access public |
|
30 | - * @since 1.0 |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - public $output = []; |
|
34 | - |
|
35 | - /** |
|
36 | - * Data type |
|
37 | - * |
|
38 | - * @access public |
|
39 | - * @since 1.0 |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - public $option_type = 'theme_mod'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Option name (if using options). |
|
46 | - * |
|
47 | - * Whitelisting property for use in Kirki modules. |
|
48 | - * |
|
49 | - * @access public |
|
50 | - * @since 1.0 |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - public $option_name = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * The kirki_config we're using for this control |
|
57 | - * |
|
58 | - * Whitelisting property for use in Kirki modules. |
|
59 | - * |
|
60 | - * @access public |
|
61 | - * @since 1.0 |
|
62 | - * @var string |
|
63 | - */ |
|
64 | - public $kirki_config = 'global'; |
|
65 | - |
|
66 | - /** |
|
67 | - * Whitelisting the "preset" argument for use in Kirki modules. |
|
68 | - * |
|
69 | - * @access public |
|
70 | - * @since 1.0 |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - public $preset = []; |
|
74 | - |
|
75 | - /** |
|
76 | - * Whitelisting the "css_vars" argument for use in Kirki modules. |
|
77 | - * |
|
78 | - * @access public |
|
79 | - * @since 1.0 |
|
80 | - * @var string |
|
81 | - */ |
|
82 | - public $css_vars = ''; |
|
83 | - |
|
84 | - /** |
|
85 | - * The version. Used in scripts & styles for cache-busting. |
|
86 | - * |
|
87 | - * @static |
|
88 | - * @access public |
|
89 | - * @since 1.0 |
|
90 | - * @var string |
|
91 | - */ |
|
92 | - public static $control_ver = '1.0.4'; |
|
93 | - |
|
94 | - /** |
|
95 | - * Parent setting. |
|
96 | - * |
|
97 | - * Used for composite controls to denote the setting that should be saved. |
|
98 | - * |
|
99 | - * @access public |
|
100 | - * @since 1.1 |
|
101 | - * @var string |
|
102 | - */ |
|
103 | - public $parent_setting; |
|
104 | - |
|
105 | - /** |
|
106 | - * Wrapper attributes. |
|
107 | - * |
|
108 | - * The value of this property will be rendered to the wrapper element. |
|
109 | - * Can be 'class', 'id', 'data-*', and other attributes. |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @since 1.1 |
|
113 | - * @var array |
|
114 | - */ |
|
115 | - public $wrapper_attrs = []; |
|
116 | - |
|
117 | - /** |
|
118 | - * Backwards compatibility support for `$wrapper_attrs`. |
|
119 | - * |
|
120 | - * Kirki v3 already has this `$wrapper_atts` property. |
|
121 | - * It was not published in the documentation, and more for internal use. |
|
122 | - * |
|
123 | - * The `WP_Customize_Control` is using `input_attrs` not `input_atts` (see, attrs vs atts). |
|
124 | - * So Kirki uses `$wrapper_attrs` for consistency and keep the old `$wrapper_atts` backwards compatibility. |
|
125 | - * |
|
126 | - * This property could be removed in the future. |
|
127 | - * Please use `$wrapper_attrs` instead. |
|
128 | - * |
|
129 | - * @since 1.1 |
|
130 | - * @deprecated 1.0.1 This variable could be removed in the future. Please use `$wrapper_attrs` instead. |
|
131 | - * @var array |
|
132 | - */ |
|
133 | - public $wrapper_atts = []; |
|
134 | - |
|
135 | - /** |
|
136 | - * Wrapper options. |
|
137 | - * |
|
138 | - * This won't be rendered automatically to the wrapper element. |
|
139 | - * The purpose is to allow us to have custom options so we can manage it when needed. |
|
140 | - * |
|
141 | - * @access public |
|
142 | - * @since 1.1 |
|
143 | - * @var array |
|
144 | - */ |
|
145 | - public $wrapper_opts = []; |
|
146 | - |
|
147 | - /** |
|
148 | - * Extra script dependencies. |
|
149 | - * |
|
150 | - * @access public |
|
151 | - * @since 1.0 |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function kirki_script_dependencies() { |
|
155 | - return []; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Enqueue control related scripts/styles. |
|
160 | - * |
|
161 | - * @access public |
|
162 | - * @since 1.0 |
|
163 | - * @return void |
|
164 | - */ |
|
165 | - public function enqueue() { |
|
166 | - |
|
167 | - // Enqueue the styles. |
|
168 | - wp_enqueue_style( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
169 | - |
|
170 | - // Enqueue the scripts. |
|
171 | - wp_enqueue_script( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls' ], self::$control_ver, false ); |
|
172 | - |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Renders the control wrapper and calls $this->render_content() for the internals. |
|
177 | - * |
|
178 | - * @since 1.0 |
|
179 | - */ |
|
180 | - protected function render() { |
|
181 | - |
|
182 | - $id = 'customize-control-' . str_replace( [ '[', ']' ], [ '-', '' ], $this->id ); |
|
183 | - $class = 'customize-control customize-control-kirki customize-control-' . $this->type; |
|
184 | - $gap = isset( $this->wrapper_opts['gap'] ) ? $this->wrapper_opts['gap'] : 'default'; |
|
185 | - $tag = isset( $this->wrapper_opts['tag'] ) ? $this->wrapper_opts['tag'] : 'li'; |
|
186 | - |
|
187 | - switch ( $gap ) { |
|
188 | - case 'small': |
|
189 | - $class .= ' customize-control-has-small-gap'; |
|
190 | - break; |
|
191 | - |
|
192 | - case 'none': |
|
193 | - $class .= ' customize-control-is-gapless'; |
|
194 | - break; |
|
195 | - |
|
196 | - default: |
|
197 | - break; |
|
198 | - } |
|
199 | - |
|
200 | - if ( empty( $this->wrapper_attrs ) && ! empty( $this->wrapper_atts ) ) { |
|
201 | - $this->wrapper_attrs = $this->wrapper_atts; |
|
202 | - } |
|
203 | - |
|
204 | - if ( isset( $this->wrapper_attrs['id'] ) ) { |
|
205 | - $id = $this->wrapper_attrs['id']; |
|
206 | - } |
|
207 | - |
|
208 | - if ( ! isset( $this->wrapper_attrs['data-kirki-setting'] ) ) { |
|
209 | - $this->wrapper_attrs['data-kirki-setting'] = $this->id; |
|
210 | - } |
|
211 | - |
|
212 | - if ( ! isset( $this->wrapper_attrs['data-kirki-setting-link'] ) ) { |
|
213 | - if ( isset( $this->settings['default'] ) ) { |
|
214 | - $this->wrapper_attrs['data-kirki-setting-link'] = $this->settings['default']->id; |
|
215 | - } |
|
216 | - } |
|
217 | - |
|
218 | - $data_attrs = ''; |
|
219 | - |
|
220 | - foreach ( $this->wrapper_attrs as $attr_key => $attr_value ) { |
|
221 | - if ( 0 === strpos( $attr_key, 'data-' ) ) { |
|
222 | - $data_attrs .= ' ' . esc_attr( $attr_key ) . '="' . esc_attr( $attr_value ) . '"'; |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - if ( isset( $this->wrapper_attrs['class'] ) ) { |
|
227 | - $class = str_ireplace( '{default_class}', $class, $this->wrapper_attrs['class'] ); |
|
228 | - } |
|
229 | - |
|
230 | - // ! Consider to esc $data_attrs. |
|
231 | - // ? What function we can use to escape string like data-xx="yy"? |
|
232 | - printf( '<' . esc_attr( $tag ) . ' id="%s" class="%s"%s>', esc_attr( $id ), esc_attr( $class ), $data_attrs ); |
|
233 | - $this->render_content(); |
|
234 | - echo '</' . esc_attr( $tag ) . '>'; |
|
235 | - |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Refresh the parameters passed to the JavaScript via JSON. |
|
240 | - * |
|
241 | - * @access public |
|
242 | - * @since 1.0 |
|
243 | - * @see WP_Customize_Control::to_json() |
|
244 | - * @return void |
|
245 | - */ |
|
246 | - public function to_json() { |
|
247 | - |
|
248 | - // Get the basics from the parent class. |
|
249 | - parent::to_json(); |
|
250 | - |
|
251 | - // Default value. |
|
252 | - $this->json['default'] = $this->setting->default; |
|
253 | - |
|
254 | - if ( isset( $this->default ) ) { |
|
255 | - $this->json['default'] = $this->default; |
|
256 | - } |
|
257 | - |
|
258 | - // Output. |
|
259 | - $this->json['output'] = $this->output; |
|
260 | - |
|
261 | - // Value. |
|
262 | - $this->json['value'] = $this->value(); |
|
263 | - |
|
264 | - // Choices. |
|
265 | - $this->json['choices'] = $this->choices; |
|
266 | - |
|
267 | - // The link. |
|
268 | - $this->json['link'] = $this->get_link(); |
|
269 | - |
|
270 | - // The ID. |
|
271 | - $this->json['id'] = $this->id; |
|
272 | - |
|
273 | - // Translation strings. |
|
274 | - $this->json['l10n'] = $this->l10n(); |
|
275 | - |
|
276 | - // The ajaxurl in case we need it. |
|
277 | - $this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
|
278 | - |
|
279 | - // Input attributes. |
|
280 | - $this->json['inputAttrs'] = ''; |
|
281 | - |
|
282 | - if ( is_array( $this->input_attrs ) ) { |
|
283 | - foreach ( $this->input_attrs as $attr => $value ) { |
|
284 | - $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
285 | - } |
|
286 | - } |
|
287 | - |
|
288 | - // The kirki-config. |
|
289 | - $this->json['kirkiConfig'] = $this->kirki_config; |
|
290 | - |
|
291 | - // The option-type. |
|
292 | - $this->json['kirkiOptionType'] = $this->option_type; |
|
293 | - |
|
294 | - // The option-name. |
|
295 | - $this->json['kirkiOptionName'] = $this->option_name; |
|
296 | - |
|
297 | - // The preset. |
|
298 | - $this->json['preset'] = $this->preset; |
|
299 | - |
|
300 | - // The CSS-Variables. |
|
301 | - $this->json['css-var'] = $this->css_vars; |
|
302 | - |
|
303 | - // Parent setting. |
|
304 | - $this->json['parent_setting'] = $this->parent_setting; |
|
305 | - |
|
306 | - // Wrapper Attributes. |
|
307 | - $this->json['wrapper_attrs'] = $this->wrapper_attrs; |
|
308 | - $this->json['wrapper_atts'] = $this->wrapper_attrs; // For backward compatibility - Could be removed in the future. |
|
309 | - |
|
310 | - } |
|
311 | - |
|
312 | - /** |
|
313 | - * Render the control's content. |
|
314 | - * |
|
315 | - * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
|
316 | - * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
|
317 | - * |
|
318 | - * @access protected |
|
319 | - * @since 1.0 |
|
320 | - * @return void |
|
321 | - */ |
|
322 | - protected function render_content() {} |
|
323 | - |
|
324 | - /** |
|
325 | - * An Underscore (JS) template for this control's content (but not its container). |
|
326 | - * |
|
327 | - * Class variables for this control class are available in the `data` JS object; |
|
328 | - * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
329 | - * |
|
330 | - * @access protected |
|
331 | - * @since 1.0 |
|
332 | - * @see WP_Customize_Control::print_template() |
|
333 | - * @return void |
|
334 | - */ |
|
335 | - protected function content_template() {} |
|
336 | - |
|
337 | - /** |
|
338 | - * Returns an array of translation strings. |
|
339 | - * |
|
340 | - * @access protected |
|
341 | - * @since 3.0.0 |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - protected function l10n() { |
|
345 | - return []; |
|
346 | - } |
|
24 | + /** |
|
25 | + * Used to automatically generate all CSS output. |
|
26 | + * |
|
27 | + * Whitelisting property for use in Kirki modules. |
|
28 | + * |
|
29 | + * @access public |
|
30 | + * @since 1.0 |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + public $output = []; |
|
34 | + |
|
35 | + /** |
|
36 | + * Data type |
|
37 | + * |
|
38 | + * @access public |
|
39 | + * @since 1.0 |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + public $option_type = 'theme_mod'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Option name (if using options). |
|
46 | + * |
|
47 | + * Whitelisting property for use in Kirki modules. |
|
48 | + * |
|
49 | + * @access public |
|
50 | + * @since 1.0 |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + public $option_name = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * The kirki_config we're using for this control |
|
57 | + * |
|
58 | + * Whitelisting property for use in Kirki modules. |
|
59 | + * |
|
60 | + * @access public |
|
61 | + * @since 1.0 |
|
62 | + * @var string |
|
63 | + */ |
|
64 | + public $kirki_config = 'global'; |
|
65 | + |
|
66 | + /** |
|
67 | + * Whitelisting the "preset" argument for use in Kirki modules. |
|
68 | + * |
|
69 | + * @access public |
|
70 | + * @since 1.0 |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + public $preset = []; |
|
74 | + |
|
75 | + /** |
|
76 | + * Whitelisting the "css_vars" argument for use in Kirki modules. |
|
77 | + * |
|
78 | + * @access public |
|
79 | + * @since 1.0 |
|
80 | + * @var string |
|
81 | + */ |
|
82 | + public $css_vars = ''; |
|
83 | + |
|
84 | + /** |
|
85 | + * The version. Used in scripts & styles for cache-busting. |
|
86 | + * |
|
87 | + * @static |
|
88 | + * @access public |
|
89 | + * @since 1.0 |
|
90 | + * @var string |
|
91 | + */ |
|
92 | + public static $control_ver = '1.0.4'; |
|
93 | + |
|
94 | + /** |
|
95 | + * Parent setting. |
|
96 | + * |
|
97 | + * Used for composite controls to denote the setting that should be saved. |
|
98 | + * |
|
99 | + * @access public |
|
100 | + * @since 1.1 |
|
101 | + * @var string |
|
102 | + */ |
|
103 | + public $parent_setting; |
|
104 | + |
|
105 | + /** |
|
106 | + * Wrapper attributes. |
|
107 | + * |
|
108 | + * The value of this property will be rendered to the wrapper element. |
|
109 | + * Can be 'class', 'id', 'data-*', and other attributes. |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @since 1.1 |
|
113 | + * @var array |
|
114 | + */ |
|
115 | + public $wrapper_attrs = []; |
|
116 | + |
|
117 | + /** |
|
118 | + * Backwards compatibility support for `$wrapper_attrs`. |
|
119 | + * |
|
120 | + * Kirki v3 already has this `$wrapper_atts` property. |
|
121 | + * It was not published in the documentation, and more for internal use. |
|
122 | + * |
|
123 | + * The `WP_Customize_Control` is using `input_attrs` not `input_atts` (see, attrs vs atts). |
|
124 | + * So Kirki uses `$wrapper_attrs` for consistency and keep the old `$wrapper_atts` backwards compatibility. |
|
125 | + * |
|
126 | + * This property could be removed in the future. |
|
127 | + * Please use `$wrapper_attrs` instead. |
|
128 | + * |
|
129 | + * @since 1.1 |
|
130 | + * @deprecated 1.0.1 This variable could be removed in the future. Please use `$wrapper_attrs` instead. |
|
131 | + * @var array |
|
132 | + */ |
|
133 | + public $wrapper_atts = []; |
|
134 | + |
|
135 | + /** |
|
136 | + * Wrapper options. |
|
137 | + * |
|
138 | + * This won't be rendered automatically to the wrapper element. |
|
139 | + * The purpose is to allow us to have custom options so we can manage it when needed. |
|
140 | + * |
|
141 | + * @access public |
|
142 | + * @since 1.1 |
|
143 | + * @var array |
|
144 | + */ |
|
145 | + public $wrapper_opts = []; |
|
146 | + |
|
147 | + /** |
|
148 | + * Extra script dependencies. |
|
149 | + * |
|
150 | + * @access public |
|
151 | + * @since 1.0 |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function kirki_script_dependencies() { |
|
155 | + return []; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Enqueue control related scripts/styles. |
|
160 | + * |
|
161 | + * @access public |
|
162 | + * @since 1.0 |
|
163 | + * @return void |
|
164 | + */ |
|
165 | + public function enqueue() { |
|
166 | + |
|
167 | + // Enqueue the styles. |
|
168 | + wp_enqueue_style( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
169 | + |
|
170 | + // Enqueue the scripts. |
|
171 | + wp_enqueue_script( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls' ], self::$control_ver, false ); |
|
172 | + |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Renders the control wrapper and calls $this->render_content() for the internals. |
|
177 | + * |
|
178 | + * @since 1.0 |
|
179 | + */ |
|
180 | + protected function render() { |
|
181 | + |
|
182 | + $id = 'customize-control-' . str_replace( [ '[', ']' ], [ '-', '' ], $this->id ); |
|
183 | + $class = 'customize-control customize-control-kirki customize-control-' . $this->type; |
|
184 | + $gap = isset( $this->wrapper_opts['gap'] ) ? $this->wrapper_opts['gap'] : 'default'; |
|
185 | + $tag = isset( $this->wrapper_opts['tag'] ) ? $this->wrapper_opts['tag'] : 'li'; |
|
186 | + |
|
187 | + switch ( $gap ) { |
|
188 | + case 'small': |
|
189 | + $class .= ' customize-control-has-small-gap'; |
|
190 | + break; |
|
191 | + |
|
192 | + case 'none': |
|
193 | + $class .= ' customize-control-is-gapless'; |
|
194 | + break; |
|
195 | + |
|
196 | + default: |
|
197 | + break; |
|
198 | + } |
|
199 | + |
|
200 | + if ( empty( $this->wrapper_attrs ) && ! empty( $this->wrapper_atts ) ) { |
|
201 | + $this->wrapper_attrs = $this->wrapper_atts; |
|
202 | + } |
|
203 | + |
|
204 | + if ( isset( $this->wrapper_attrs['id'] ) ) { |
|
205 | + $id = $this->wrapper_attrs['id']; |
|
206 | + } |
|
207 | + |
|
208 | + if ( ! isset( $this->wrapper_attrs['data-kirki-setting'] ) ) { |
|
209 | + $this->wrapper_attrs['data-kirki-setting'] = $this->id; |
|
210 | + } |
|
211 | + |
|
212 | + if ( ! isset( $this->wrapper_attrs['data-kirki-setting-link'] ) ) { |
|
213 | + if ( isset( $this->settings['default'] ) ) { |
|
214 | + $this->wrapper_attrs['data-kirki-setting-link'] = $this->settings['default']->id; |
|
215 | + } |
|
216 | + } |
|
217 | + |
|
218 | + $data_attrs = ''; |
|
219 | + |
|
220 | + foreach ( $this->wrapper_attrs as $attr_key => $attr_value ) { |
|
221 | + if ( 0 === strpos( $attr_key, 'data-' ) ) { |
|
222 | + $data_attrs .= ' ' . esc_attr( $attr_key ) . '="' . esc_attr( $attr_value ) . '"'; |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + if ( isset( $this->wrapper_attrs['class'] ) ) { |
|
227 | + $class = str_ireplace( '{default_class}', $class, $this->wrapper_attrs['class'] ); |
|
228 | + } |
|
229 | + |
|
230 | + // ! Consider to esc $data_attrs. |
|
231 | + // ? What function we can use to escape string like data-xx="yy"? |
|
232 | + printf( '<' . esc_attr( $tag ) . ' id="%s" class="%s"%s>', esc_attr( $id ), esc_attr( $class ), $data_attrs ); |
|
233 | + $this->render_content(); |
|
234 | + echo '</' . esc_attr( $tag ) . '>'; |
|
235 | + |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Refresh the parameters passed to the JavaScript via JSON. |
|
240 | + * |
|
241 | + * @access public |
|
242 | + * @since 1.0 |
|
243 | + * @see WP_Customize_Control::to_json() |
|
244 | + * @return void |
|
245 | + */ |
|
246 | + public function to_json() { |
|
247 | + |
|
248 | + // Get the basics from the parent class. |
|
249 | + parent::to_json(); |
|
250 | + |
|
251 | + // Default value. |
|
252 | + $this->json['default'] = $this->setting->default; |
|
253 | + |
|
254 | + if ( isset( $this->default ) ) { |
|
255 | + $this->json['default'] = $this->default; |
|
256 | + } |
|
257 | + |
|
258 | + // Output. |
|
259 | + $this->json['output'] = $this->output; |
|
260 | + |
|
261 | + // Value. |
|
262 | + $this->json['value'] = $this->value(); |
|
263 | + |
|
264 | + // Choices. |
|
265 | + $this->json['choices'] = $this->choices; |
|
266 | + |
|
267 | + // The link. |
|
268 | + $this->json['link'] = $this->get_link(); |
|
269 | + |
|
270 | + // The ID. |
|
271 | + $this->json['id'] = $this->id; |
|
272 | + |
|
273 | + // Translation strings. |
|
274 | + $this->json['l10n'] = $this->l10n(); |
|
275 | + |
|
276 | + // The ajaxurl in case we need it. |
|
277 | + $this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
|
278 | + |
|
279 | + // Input attributes. |
|
280 | + $this->json['inputAttrs'] = ''; |
|
281 | + |
|
282 | + if ( is_array( $this->input_attrs ) ) { |
|
283 | + foreach ( $this->input_attrs as $attr => $value ) { |
|
284 | + $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
285 | + } |
|
286 | + } |
|
287 | + |
|
288 | + // The kirki-config. |
|
289 | + $this->json['kirkiConfig'] = $this->kirki_config; |
|
290 | + |
|
291 | + // The option-type. |
|
292 | + $this->json['kirkiOptionType'] = $this->option_type; |
|
293 | + |
|
294 | + // The option-name. |
|
295 | + $this->json['kirkiOptionName'] = $this->option_name; |
|
296 | + |
|
297 | + // The preset. |
|
298 | + $this->json['preset'] = $this->preset; |
|
299 | + |
|
300 | + // The CSS-Variables. |
|
301 | + $this->json['css-var'] = $this->css_vars; |
|
302 | + |
|
303 | + // Parent setting. |
|
304 | + $this->json['parent_setting'] = $this->parent_setting; |
|
305 | + |
|
306 | + // Wrapper Attributes. |
|
307 | + $this->json['wrapper_attrs'] = $this->wrapper_attrs; |
|
308 | + $this->json['wrapper_atts'] = $this->wrapper_attrs; // For backward compatibility - Could be removed in the future. |
|
309 | + |
|
310 | + } |
|
311 | + |
|
312 | + /** |
|
313 | + * Render the control's content. |
|
314 | + * |
|
315 | + * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`. |
|
316 | + * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template(). |
|
317 | + * |
|
318 | + * @access protected |
|
319 | + * @since 1.0 |
|
320 | + * @return void |
|
321 | + */ |
|
322 | + protected function render_content() {} |
|
323 | + |
|
324 | + /** |
|
325 | + * An Underscore (JS) template for this control's content (but not its container). |
|
326 | + * |
|
327 | + * Class variables for this control class are available in the `data` JS object; |
|
328 | + * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
|
329 | + * |
|
330 | + * @access protected |
|
331 | + * @since 1.0 |
|
332 | + * @see WP_Customize_Control::print_template() |
|
333 | + * @return void |
|
334 | + */ |
|
335 | + protected function content_template() {} |
|
336 | + |
|
337 | + /** |
|
338 | + * Returns an array of translation strings. |
|
339 | + * |
|
340 | + * @access protected |
|
341 | + * @since 3.0.0 |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + protected function l10n() { |
|
345 | + return []; |
|
346 | + } |
|
347 | 347 | } |
@@ -165,10 +165,10 @@ discard block |
||
165 | 165 | public function enqueue() { |
166 | 166 | |
167 | 167 | // Enqueue the styles. |
168 | - wp_enqueue_style( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.css' ), [], self::$control_ver ); |
|
168 | + wp_enqueue_style('kirki-control-base', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.css'), [], self::$control_ver); |
|
169 | 169 | |
170 | 170 | // Enqueue the scripts. |
171 | - wp_enqueue_script( 'kirki-control-base', URL::get_from_path( dirname( dirname( __DIR__ ) ) . '/dist/control.js' ), [ 'customize-controls' ], self::$control_ver, false ); |
|
171 | + wp_enqueue_script('kirki-control-base', URL::get_from_path(dirname(dirname(__DIR__)) . '/dist/control.js'), ['customize-controls'], self::$control_ver, false); |
|
172 | 172 | |
173 | 173 | } |
174 | 174 | |
@@ -179,12 +179,12 @@ discard block |
||
179 | 179 | */ |
180 | 180 | protected function render() { |
181 | 181 | |
182 | - $id = 'customize-control-' . str_replace( [ '[', ']' ], [ '-', '' ], $this->id ); |
|
182 | + $id = 'customize-control-' . str_replace(['[', ']'], ['-', ''], $this->id); |
|
183 | 183 | $class = 'customize-control customize-control-kirki customize-control-' . $this->type; |
184 | - $gap = isset( $this->wrapper_opts['gap'] ) ? $this->wrapper_opts['gap'] : 'default'; |
|
185 | - $tag = isset( $this->wrapper_opts['tag'] ) ? $this->wrapper_opts['tag'] : 'li'; |
|
184 | + $gap = isset($this->wrapper_opts['gap']) ? $this->wrapper_opts['gap'] : 'default'; |
|
185 | + $tag = isset($this->wrapper_opts['tag']) ? $this->wrapper_opts['tag'] : 'li'; |
|
186 | 186 | |
187 | - switch ( $gap ) { |
|
187 | + switch ($gap) { |
|
188 | 188 | case 'small': |
189 | 189 | $class .= ' customize-control-has-small-gap'; |
190 | 190 | break; |
@@ -197,41 +197,41 @@ discard block |
||
197 | 197 | break; |
198 | 198 | } |
199 | 199 | |
200 | - if ( empty( $this->wrapper_attrs ) && ! empty( $this->wrapper_atts ) ) { |
|
200 | + if (empty($this->wrapper_attrs) && !empty($this->wrapper_atts)) { |
|
201 | 201 | $this->wrapper_attrs = $this->wrapper_atts; |
202 | 202 | } |
203 | 203 | |
204 | - if ( isset( $this->wrapper_attrs['id'] ) ) { |
|
204 | + if (isset($this->wrapper_attrs['id'])) { |
|
205 | 205 | $id = $this->wrapper_attrs['id']; |
206 | 206 | } |
207 | 207 | |
208 | - if ( ! isset( $this->wrapper_attrs['data-kirki-setting'] ) ) { |
|
208 | + if (!isset($this->wrapper_attrs['data-kirki-setting'])) { |
|
209 | 209 | $this->wrapper_attrs['data-kirki-setting'] = $this->id; |
210 | 210 | } |
211 | 211 | |
212 | - if ( ! isset( $this->wrapper_attrs['data-kirki-setting-link'] ) ) { |
|
213 | - if ( isset( $this->settings['default'] ) ) { |
|
212 | + if (!isset($this->wrapper_attrs['data-kirki-setting-link'])) { |
|
213 | + if (isset($this->settings['default'])) { |
|
214 | 214 | $this->wrapper_attrs['data-kirki-setting-link'] = $this->settings['default']->id; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | |
218 | 218 | $data_attrs = ''; |
219 | 219 | |
220 | - foreach ( $this->wrapper_attrs as $attr_key => $attr_value ) { |
|
221 | - if ( 0 === strpos( $attr_key, 'data-' ) ) { |
|
222 | - $data_attrs .= ' ' . esc_attr( $attr_key ) . '="' . esc_attr( $attr_value ) . '"'; |
|
220 | + foreach ($this->wrapper_attrs as $attr_key => $attr_value) { |
|
221 | + if (0 === strpos($attr_key, 'data-')) { |
|
222 | + $data_attrs .= ' ' . esc_attr($attr_key) . '="' . esc_attr($attr_value) . '"'; |
|
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
226 | - if ( isset( $this->wrapper_attrs['class'] ) ) { |
|
227 | - $class = str_ireplace( '{default_class}', $class, $this->wrapper_attrs['class'] ); |
|
226 | + if (isset($this->wrapper_attrs['class'])) { |
|
227 | + $class = str_ireplace('{default_class}', $class, $this->wrapper_attrs['class']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // ! Consider to esc $data_attrs. |
231 | 231 | // ? What function we can use to escape string like data-xx="yy"? |
232 | - printf( '<' . esc_attr( $tag ) . ' id="%s" class="%s"%s>', esc_attr( $id ), esc_attr( $class ), $data_attrs ); |
|
232 | + printf('<' . esc_attr($tag) . ' id="%s" class="%s"%s>', esc_attr($id), esc_attr($class), $data_attrs); |
|
233 | 233 | $this->render_content(); |
234 | - echo '</' . esc_attr( $tag ) . '>'; |
|
234 | + echo '</' . esc_attr($tag) . '>'; |
|
235 | 235 | |
236 | 236 | } |
237 | 237 | |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // Default value. |
252 | 252 | $this->json['default'] = $this->setting->default; |
253 | 253 | |
254 | - if ( isset( $this->default ) ) { |
|
254 | + if (isset($this->default)) { |
|
255 | 255 | $this->json['default'] = $this->default; |
256 | 256 | } |
257 | 257 | |
@@ -274,14 +274,14 @@ discard block |
||
274 | 274 | $this->json['l10n'] = $this->l10n(); |
275 | 275 | |
276 | 276 | // The ajaxurl in case we need it. |
277 | - $this->json['ajaxurl'] = admin_url( 'admin-ajax.php' ); |
|
277 | + $this->json['ajaxurl'] = admin_url('admin-ajax.php'); |
|
278 | 278 | |
279 | 279 | // Input attributes. |
280 | 280 | $this->json['inputAttrs'] = ''; |
281 | 281 | |
282 | - if ( is_array( $this->input_attrs ) ) { |
|
283 | - foreach ( $this->input_attrs as $attr => $value ) { |
|
284 | - $this->json['inputAttrs'] .= $attr . '="' . esc_attr( $value ) . '" '; |
|
282 | + if (is_array($this->input_attrs)) { |
|
283 | + foreach ($this->input_attrs as $attr => $value) { |
|
284 | + $this->json['inputAttrs'] .= $attr . '="' . esc_attr($value) . '" '; |
|
285 | 285 | } |
286 | 286 | } |
287 | 287 |
@@ -19,82 +19,82 @@ |
||
19 | 19 | */ |
20 | 20 | class Multicheck extends Field { |
21 | 21 | |
22 | - /** |
|
23 | - * The field type. |
|
24 | - * |
|
25 | - * @access public |
|
26 | - * @since 1.0 |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - public $type = 'kirki-multicheck'; |
|
22 | + /** |
|
23 | + * The field type. |
|
24 | + * |
|
25 | + * @access public |
|
26 | + * @since 1.0 |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + public $type = 'kirki-multicheck'; |
|
30 | 30 | |
31 | - /** |
|
32 | - * The control class-name. |
|
33 | - * |
|
34 | - * @access protected |
|
35 | - * @since 0.1 |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected $control_class = '\Kirki\Control\Multicheck'; |
|
31 | + /** |
|
32 | + * The control class-name. |
|
33 | + * |
|
34 | + * @access protected |
|
35 | + * @since 0.1 |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected $control_class = '\Kirki\Control\Multicheck'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Whether we should register the control class for JS-templating or not. |
|
42 | - * |
|
43 | - * @access protected |
|
44 | - * @since 0.1 |
|
45 | - * @var bool |
|
46 | - */ |
|
47 | - protected $control_has_js_template = true; |
|
40 | + /** |
|
41 | + * Whether we should register the control class for JS-templating or not. |
|
42 | + * |
|
43 | + * @access protected |
|
44 | + * @since 0.1 |
|
45 | + * @var bool |
|
46 | + */ |
|
47 | + protected $control_has_js_template = true; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Filter arguments before creating the setting. |
|
51 | - * |
|
52 | - * @access public |
|
53 | - * @since 0.1 |
|
54 | - * @param array $args The field arguments. |
|
55 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function filter_setting_args( $args, $wp_customize ) { |
|
59 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
60 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
49 | + /** |
|
50 | + * Filter arguments before creating the setting. |
|
51 | + * |
|
52 | + * @access public |
|
53 | + * @since 0.1 |
|
54 | + * @param array $args The field arguments. |
|
55 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function filter_setting_args( $args, $wp_customize ) { |
|
59 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
60 | + $args = parent::filter_setting_args( $args, $wp_customize ); |
|
61 | 61 | |
62 | - // Set the sanitize-callback if none is defined. |
|
63 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
64 | - $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
65 | - } |
|
66 | - } |
|
67 | - return $args; |
|
68 | - } |
|
62 | + // Set the sanitize-callback if none is defined. |
|
63 | + if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
64 | + $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
65 | + } |
|
66 | + } |
|
67 | + return $args; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Filter arguments before creating the control. |
|
72 | - * |
|
73 | - * @access public |
|
74 | - * @since 0.1 |
|
75 | - * @param array $args The field arguments. |
|
76 | - * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
77 | - * @return array |
|
78 | - */ |
|
79 | - public function filter_control_args( $args, $wp_customize ) { |
|
80 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
81 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
82 | - $args['type'] = 'kirki-multicheck'; |
|
83 | - } |
|
84 | - return $args; |
|
85 | - } |
|
70 | + /** |
|
71 | + * Filter arguments before creating the control. |
|
72 | + * |
|
73 | + * @access public |
|
74 | + * @since 0.1 |
|
75 | + * @param array $args The field arguments. |
|
76 | + * @param WP_Customize_Manager $wp_customize The customizer instance. |
|
77 | + * @return array |
|
78 | + */ |
|
79 | + public function filter_control_args( $args, $wp_customize ) { |
|
80 | + if ( $args['settings'] === $this->args['settings'] ) { |
|
81 | + $args = parent::filter_control_args( $args, $wp_customize ); |
|
82 | + $args['type'] = 'kirki-multicheck'; |
|
83 | + } |
|
84 | + return $args; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * The sanitize method that will be used as a falback |
|
89 | - * |
|
90 | - * @static |
|
91 | - * @access public |
|
92 | - * @since 1.0 |
|
93 | - * @param string|array $value The control's value. |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public static function sanitize( $value ) { |
|
97 | - $value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value; |
|
98 | - return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : []; |
|
99 | - } |
|
87 | + /** |
|
88 | + * The sanitize method that will be used as a falback |
|
89 | + * |
|
90 | + * @static |
|
91 | + * @access public |
|
92 | + * @since 1.0 |
|
93 | + * @param string|array $value The control's value. |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public static function sanitize( $value ) { |
|
97 | + $value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value; |
|
98 | + return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : []; |
|
99 | + } |
|
100 | 100 | } |
@@ -55,13 +55,13 @@ discard block |
||
55 | 55 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
56 | 56 | * @return array |
57 | 57 | */ |
58 | - public function filter_setting_args( $args, $wp_customize ) { |
|
59 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
60 | - $args = parent::filter_setting_args( $args, $wp_customize ); |
|
58 | + public function filter_setting_args($args, $wp_customize) { |
|
59 | + if ($args['settings'] === $this->args['settings']) { |
|
60 | + $args = parent::filter_setting_args($args, $wp_customize); |
|
61 | 61 | |
62 | 62 | // Set the sanitize-callback if none is defined. |
63 | - if ( ! isset( $args['sanitize_callback'] ) || ! $args['sanitize_callback'] ) { |
|
64 | - $args['sanitize_callback'] = [ __CLASS__, 'sanitize' ]; |
|
63 | + if (!isset($args['sanitize_callback']) || !$args['sanitize_callback']) { |
|
64 | + $args['sanitize_callback'] = [__CLASS__, 'sanitize']; |
|
65 | 65 | } |
66 | 66 | } |
67 | 67 | return $args; |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | * @param WP_Customize_Manager $wp_customize The customizer instance. |
77 | 77 | * @return array |
78 | 78 | */ |
79 | - public function filter_control_args( $args, $wp_customize ) { |
|
80 | - if ( $args['settings'] === $this->args['settings'] ) { |
|
81 | - $args = parent::filter_control_args( $args, $wp_customize ); |
|
79 | + public function filter_control_args($args, $wp_customize) { |
|
80 | + if ($args['settings'] === $this->args['settings']) { |
|
81 | + $args = parent::filter_control_args($args, $wp_customize); |
|
82 | 82 | $args['type'] = 'kirki-multicheck'; |
83 | 83 | } |
84 | 84 | return $args; |
@@ -93,8 +93,8 @@ discard block |
||
93 | 93 | * @param string|array $value The control's value. |
94 | 94 | * @return array |
95 | 95 | */ |
96 | - public static function sanitize( $value ) { |
|
97 | - $value = ( ! is_array( $value ) ) ? explode( ',', $value ) : $value; |
|
98 | - return ( ! empty( $value ) ) ? array_map( 'sanitize_text_field', $value ) : []; |
|
96 | + public static function sanitize($value) { |
|
97 | + $value = (!is_array($value)) ? explode(',', $value) : $value; |
|
98 | + return (!empty($value)) ? array_map('sanitize_text_field', $value) : []; |
|
99 | 99 | } |
100 | 100 | } |