PluginProbe
QuadMenu – Mega Menu / trunk
QuadMenu – Mega Menu vtrunk
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / redux / ReduxCore / core / enqueue.php

enqueue.php in QuadMenu – Mega Menu trunk, at redux/ReduxCore/core/enqueue.php

521 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if ( ! class_exists( 'reduxLegacyCoreEnqueue' ) ) {
8 class reduxLegacyCoreEnqueue {
9 public $parent = null;
10
11 private $min = '';
12 private $timestamp = '';
13
14 public function __construct( $parent ) {
15 $this->parent = $parent;
16
17 ReduxLegacy_Functions::$_parent = $parent;
18 }
19
20 public function init() {
21 $this->min = ReduxLegacy_Functions::isMin();
22
23 $this->timestamp = ReduxFrameworkLegacy::$_version;
24 if ( $this->parent->args['dev_mode'] ) {
25 $this->timestamp .= '.' . time();
26 }
27
28 $this->register_styles();
29 $this->register_scripts();
30
31 add_thickbox();
32
33 $this->enqueue_fields();
34
35 add_filter( "redux/{$this->parent->args['opt_name']}/localize", array( 'ReduxLegacy_Helpers', 'localize' ) );
36
37 $this->set_localized_data();
38
39 /**
40 * action 'redux-enqueue-{opt_name}'
41 *
42 * @deprecated
43 *
44 * @param object $this ReduxFrameworkLegacy
45 */
46 do_action( "redux-enqueue-{$this->parent->args['opt_name']}", $this->parent ); // REMOVE
47
48 /**
49 * action 'redux/page/{opt_name}/enqueue'
50 */
51 do_action( "redux/page/{$this->parent->args['opt_name']}/enqueue" );
52 }
53
54 private function register_styles() {
55
56 // *****************************************************************
57 // Redux Admin CSS
58 // *****************************************************************
59 wp_enqueue_style(
60 'redux-admin-css',
61 ReduxFrameworkLegacy::$_url . 'assets/css/redux-admin.css',
62 array(),
63 $this->timestamp,
64 'all'
65 );
66
67 // *****************************************************************
68 // Redux Fields CSS
69 // *****************************************************************
70 if ( ! $this->parent->args['dev_mode'] ) {
71 wp_enqueue_style(
72 'redux-fields-css',
73 ReduxFrameworkLegacy::$_url . 'assets/css/redux-fields.css',
74 array(),
75 $this->timestamp,
76 'all'
77 );
78 }
79
80 // *****************************************************************
81 // Select2 CSS
82 // *****************************************************************
83 ReduxLegacy_CDN::register_style(
84 'select2-css',
85 '//cdn.jsdelivr.net/select2/3.5.2/select2.css',
86 array(),
87 '3.5.2', // $this->timestamp,
88 'all'
89 );
90
91 // *****************************************************************
92 // Spectrum CSS
93 // *****************************************************************
94 // $css_file = 'redux-spectrum.min.css';
95 // if ($this->parent->args['dev_mode']) {
96 $css_file = 'redux-spectrum.css';
97 // }
98
99 wp_register_style(
100 'redux-spectrum-css',
101 ReduxFrameworkLegacy::$_url . 'assets/css/vendor/spectrum/' . $css_file,
102 array(),
103 '1.3.3',
104 'all'
105 );
106
107 // *****************************************************************
108 // Elusive Icon CSS
109 // *****************************************************************
110 wp_enqueue_style(
111 'redux-elusive-icon',
112 ReduxFrameworkLegacy::$_url . 'assets/css/vendor/elusive-icons/elusive-icons.css',
113 array(),
114 $this->timestamp,
115 'all'
116 );
117
118 // *****************************************************************
119 // QTip CSS
120 // *****************************************************************
121 $css_file = 'jquery.qtip.min.css';
122 if ( $this->parent->args['dev_mode'] ) {
123 $css_file = 'jquery.qtip.css';
124 }
125
126 wp_enqueue_style(
127 'qtip-css',
128 ReduxFrameworkLegacy::$_url . 'assets/css/vendor/qtip/' . $css_file,
129 array(),
130 '2.2.0',
131 'all'
132 );
133
134 // *****************************************************************
135 // JQuery UI CSS
136 // *****************************************************************
137 wp_enqueue_style(
138 'jquery-ui-css',
139 apply_filters( "redux/page/{$this->parent->args['opt_name']}/enqueue/jquery-ui-css", ReduxFrameworkLegacy::$_url . 'assets/css/vendor/jquery-ui-bootstrap/jquery-ui-1.10.0.custom.css' ),
140 array(),
141 $this->timestamp,
142 'all'
143 );
144
145 // *****************************************************************
146 // Iris CSS
147 // *****************************************************************
148 wp_enqueue_style( 'wp-color-picker' );
149
150 if ( $this->parent->args['dev_mode'] ) {
151
152 // *****************************************************************
153 // Color Picker CSS
154 // *****************************************************************
155 wp_register_style(
156 'redux-color-picker-css',
157 ReduxFrameworkLegacy::$_url . 'assets/css/color-picker/color-picker.css',
158 array( 'wp-color-picker' ),
159 $this->timestamp,
160 'all'
161 );
162
163 // *****************************************************************
164 // Media CSS
165 // *****************************************************************
166 wp_enqueue_style(
167 'redux-field-media-css',
168 ReduxFrameworkLegacy::$_url . 'assets/css/media/media.css',
169 array(),
170 time(),
171 'all'
172 );
173 }
174
175 // *****************************************************************
176 // RTL CSS
177 // *****************************************************************
178 if ( is_rtl() ) {
179 wp_enqueue_style(
180 'redux-rtl-css',
181 ReduxFrameworkLegacy::$_url . 'assets/css/rtl.css',
182 array( 'redux-admin-css' ),
183 $this->timestamp,
184 'all'
185 );
186 }
187 }
188
189 private function register_scripts() {
190 // *****************************************************************
191 // JQuery / JQuery UI JS
192 // *****************************************************************
193 wp_enqueue_script( 'jquery' );
194 wp_enqueue_script( 'jquery-ui-core' );
195 wp_enqueue_script( 'jquery-ui-dialog' );
196
197 // *****************************************************************
198 // Select2 Sortable JS
199 // *****************************************************************
200 wp_register_script(
201 'redux-select2-sortable-js',
202 ReduxFrameworkLegacy::$_url . 'assets/js/vendor/redux.select2.sortable' . $this->min . '.js',
203 array( 'jquery', 'jquery-ui-sortable' ),
204 $this->timestamp,
205 true
206 );
207
208 // *****************************************************************
209 // Select2 JS
210 // *****************************************************************
211
212 // JWp6 plugin giving us problems. They need to update.
213 if ( wp_script_is( 'jquerySelect2' ) ) {
214 wp_deregister_script( 'jquerySelect2' );
215 wp_dequeue_script( 'jquerySelect2' );
216 wp_dequeue_style( 'jquerySelect2Style' );
217 }
218
219 ReduxLegacy_CDN::register_script(
220 'select2-js',
221 '//cdn.jsdelivr.net/select2/3.5.2/select2' . $this->min . '.js',
222 array( 'jquery', 'redux-select2-sortable-js' ),
223 '3.5.2',
224 true
225 );
226
227 // *****************************************************************
228 // QTip JS
229 // *****************************************************************
230 $js_file = 'jquery.qtip.min.js';
231 if ( $this->parent->args['dev_mode'] ) {
232 $js_file = 'jquery.qtip.js';
233 }
234
235 wp_enqueue_script(
236 'qtip-js',
237 ReduxFrameworkLegacy::$_url . 'assets/js/vendor/qtip/' . $js_file,
238 array( 'jquery' ),
239 '2.2.0',
240 true
241 );
242
243 // *****************************************************************
244 // Spectrum JS
245 // *****************************************************************
246 $js_file = 'redux-spectrum.min.js';
247 if ( $this->parent->args['dev_mode'] ) {
248 $js_file = 'redux-spectrum.js';
249 }
250
251 wp_register_script(
252 'redux-spectrum-js',
253 ReduxFrameworkLegacy::$_url . 'assets/js/vendor/spectrum/' . $js_file,
254 array( 'jquery' ),
255 '1.3.3',
256 true
257 );
258
259 $depArray = array( 'jquery' );
260
261 // *****************************************************************
262 // Vendor JS
263 // *****************************************************************
264 wp_register_script(
265 'redux-vendor',
266 ReduxFrameworkLegacy::$_url . 'assets/js/vendor.min.js',
267 array( 'jquery' ),
268 $this->timestamp,
269 true
270 );
271
272 array_push( $depArray, 'redux-vendor' );
273
274 // *****************************************************************
275 // Redux JS
276 // *****************************************************************
277 wp_register_script(
278 'redux-js',
279 ReduxFrameworkLegacy::$_url . 'assets/js/redux' . $this->min . '.js',
280 $depArray,
281 $this->timestamp,
282 true
283 );
284
285 wp_enqueue_script(
286 'webfontloader',
287 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.0/webfont.js',
288 array( 'jquery' ),
289 '1.5.0',
290 true
291 );
292 }
293
294 public function _enqueue_field( $field ) {
295 // TODO AFTER GROUP WORKS - Revert IF below
296 // if( isset( $field['type'] ) && $field['type'] != 'callback' ) {
297 if ( isset( $field['type'] ) && $field['type'] != 'callback' ) {
298
299 $field_class = 'ReduxFrameworkLegacy_' . $field['type'];
300
301 /**
302 * Field class file
303 * filter 'redux/{opt_name}/field/class/{field.type}
304 *
305 * @param string field class file path
306 * @param array $field field config data
307 */
308 $class_file = apply_filters( "redux/{$this->parent->args['opt_name']}/field/class/{$field['type']}", ReduxFrameworkLegacy::$_dir . "inc/fields/{$field['type']}/field_{$field['type']}.php", $field );
309 if ( $class_file ) {
310 if ( ! class_exists( $field_class ) ) {
311 if ( file_exists( $class_file ) ) {
312 require_once $class_file;
313 }
314 }
315
316 if ( ( method_exists( $field_class, 'enqueue' ) ) || method_exists( $field_class, 'localize' ) ) {
317
318 if ( ! isset( $this->parent->options[ $field['id'] ] ) ) {
319 $this->parent->options[ $field['id'] ] = '';
320 }
321
322 $theField = new $field_class( $field, $this->parent->options[ $field['id'] ], $this->parent );
323
324 // Move dev_mode check to a new if/then block
325 if ( ! wp_script_is( 'redux-field-' . $field['type'] . '-js', 'enqueued' ) && class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
326 $theField->enqueue();
327 }
328
329 if ( method_exists( $field_class, 'localize' ) ) {
330 $params = $theField->localize( $field );
331 if ( ! isset( $this->parent->localize_data[ $field['type'] ] ) ) {
332 $this->parent->localize_data[ $field['type'] ] = array();
333 }
334 $this->parent->localize_data[ $field['type'] ][ $field['id'] ] = $theField->localize( $field );
335 }
336
337 unset( $theField );
338 }
339 }
340 }
341 }
342
343 private function enqueue_fields() {
344 foreach ( $this->parent->sections as $section ) {
345 if ( isset( $section['fields'] ) ) {
346 foreach ( $section['fields'] as $field ) {
347 $this->_enqueue_field( $field );
348 }
349 }
350 }
351 }
352
353 public function get_warnings_and_errors_array() {
354 // Construct the errors array.
355 if ( isset( $this->parent->transients['last_save_mode'] ) && ! empty( $this->parent->transients['notices']['errors'] ) ) {
356 $theTotal = 0;
357 $theErrors = array();
358
359 foreach ( $this->parent->transients['notices']['errors'] as $error ) {
360 $theErrors[ $error['section_id'] ]['errors'][] = $error;
361
362 if ( ! isset( $theErrors[ $error['section_id'] ]['total'] ) ) {
363 $theErrors[ $error['section_id'] ]['total'] = 0;
364 }
365
366 ++$theErrors[ $error['section_id'] ]['total'];
367 ++$theTotal;
368 }
369
370 $this->parent->localize_data['errors'] = array(
371 'total' => $theTotal,
372 'errors' => $theErrors,
373 );
374 unset( $this->parent->transients['notices']['errors'] );
375 }
376
377 // Construct the warnings array.
378 if ( isset( $this->parent->transients['last_save_mode'] ) && ! empty( $this->parent->transients['notices']['warnings'] ) ) {
379 $theTotal = 0;
380 $theWarnings = array();
381
382 foreach ( $this->parent->transients['notices']['warnings'] as $warning ) {
383 $theWarnings[ $warning['section_id'] ]['warnings'][] = $warning;
384
385 if ( ! isset( $theWarnings[ $warning['section_id'] ]['total'] ) ) {
386 $theWarnings[ $warning['section_id'] ]['total'] = 0;
387 }
388
389 ++$theWarnings[ $warning['section_id'] ]['total'];
390 ++$theTotal;
391 }
392
393 unset( $this->parent->transients['notices']['warnings'] );
394 $this->parent->localize_data['warnings'] = array(
395 'total' => $theTotal,
396 'warnings' => $theWarnings,
397 );
398 }
399
400 if ( empty( $this->parent->transients['notices'] ) ) {
401 unset( $this->parent->transients['notices'] );
402 }
403 }
404
405 private function set_localized_data() {
406 if ( ! empty( $this->parent->args['last_tab'] ) ) {
407 $this->parent->localize_data['last_tab'] = $this->parent->args['last_tab'];
408 }
409
410 $this->parent->localize_data['required'] = $this->parent->required;
411 $this->parent->localize_data['fonts'] = $this->parent->fonts;
412 $this->parent->localize_data['required_child'] = $this->parent->required_child;
413 $this->parent->localize_data['fields'] = $this->parent->fields;
414
415 if ( isset( $this->parent->font_groups['google'] ) ) {
416 $this->parent->localize_data['googlefonts'] = $this->parent->font_groups['google'];
417 }
418
419 if ( isset( $this->parent->font_groups['std'] ) ) {
420 $this->parent->localize_data['stdfonts'] = $this->parent->font_groups['std'];
421 }
422
423 if ( isset( $this->parent->font_groups['customfonts'] ) ) {
424 $this->parent->localize_data['customfonts'] = $this->parent->font_groups['customfonts'];
425 }
426
427 $this->parent->localize_data['folds'] = $this->parent->folds;
428
429 // Make sure the children are all hidden properly.
430 foreach ( $this->parent->fields as $key => $value ) {
431 if ( in_array( $key, $this->parent->fieldsHidden ) ) {
432 foreach ( $value as $k => $v ) {
433 if ( ! in_array( $k, $this->parent->fieldsHidden ) ) {
434 $this->parent->fieldsHidden[] = $k;
435 $this->parent->folds[ $k ] = 'hide';
436 }
437 }
438 }
439 }
440
441 $this->parent->localize_data['fieldsHidden'] = $this->parent->fieldsHidden;
442 $this->parent->localize_data['options'] = $this->parent->options;
443 $this->parent->localize_data['defaults'] = $this->parent->options_defaults;
444
445 /**
446 * Save pending string
447 * filter 'redux/{opt_name}/localize/save_pending
448 *
449 * @param string save_pending string
450 */
451 $save_pending = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/save_pending", __( 'You have changes that are not saved. Would you like to save them now?', 'redux-framework' ) );
452
453 /**
454 * Reset all string
455 * filter 'redux/{opt_name}/localize/reset
456 *
457 * @param string reset all string
458 */
459 $reset_all = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/reset", __( 'Are you sure? Resetting will lose all custom values.', 'redux-framework' ) );
460
461 /**
462 * Reset section string
463 * filter 'redux/{opt_name}/localize/reset_section
464 *
465 * @param string reset section string
466 */
467 $reset_section = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/reset_section", __( 'Are you sure? Resetting will lose all custom values in this section.', 'redux-framework' ) );
468
469 /**
470 * Preset confirm string
471 * filter 'redux/{opt_name}/localize/preset
472 *
473 * @param string preset confirm string
474 */
475 $preset_confirm = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/preset", __( 'Your current options will be replaced with the values of this preset. Would you like to proceed?', 'redux-framework' ) );
476
477 /**
478 * Import confirm string
479 * filter 'redux/{opt_name}/localize/import
480 *
481 * @param string import confirm string
482 */
483 $import_confirm = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/import", __( 'Your current options will be replaced with the values of this import. Would you like to proceed?', 'redux-framework' ) );
484
485 global $pagenow;
486 $this->parent->localize_data['args'] = array(
487 'save_pending' => $save_pending,
488 'reset_confirm' => $reset_all,
489 'reset_section_confirm' => $reset_section,
490 'import_section_confirm' => $import_confirm,
491 'preset_confirm' => $preset_confirm,
492 'please_wait' => __( 'Please Wait', 'redux-framework' ),
493 'opt_name' => $this->parent->args['opt_name'],
494 'slug' => $this->parent->args['page_slug'],
495 'hints' => $this->parent->args['hints'],
496 'disable_save_warn' => $this->parent->args['disable_save_warn'],
497 'class' => $this->parent->args['class'],
498 'ajax_save' => $this->parent->args['ajax_save'],
499 'menu_search' => $pagenow . '?page=' . $this->parent->args['page_slug'] . '&tab=',
500 );
501
502 $this->parent->localize_data['ajax'] = array(
503 'console' => __( 'There was an error saving. Here is the result of your action:', 'redux-framework' ),
504 'alert' => __( 'There was a problem with your action. Please try again or reload the page.', 'redux-framework' ),
505 );
506
507 $this->parent->localize_data = apply_filters( "redux/{$this->parent->args['opt_name']}/localize", $this->parent->localize_data );
508
509 $this->get_warnings_and_errors_array();
510
511 wp_localize_script(
512 'redux-js',
513 'redux',
514 $this->parent->localize_data
515 );
516
517 wp_enqueue_script( 'redux-js' ); // Enque the JS now
518 }
519 }
520 }
521