PluginProbe
QuadMenu – Mega Menu / 2.0.3
QuadMenu – Mega Menu v2.0.3
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 / lib / ReduxCore / core / enqueue.php

enqueue.php in QuadMenu – Mega Menu 2.0.3, at lib/ReduxCore/core/enqueue.php

522 lines 23.0 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( 'reduxCoreEnqueue' ) ) {
8 class reduxCoreEnqueue {
9 public $parent = null;
10
11 private $min = '';
12 private $timestamp = '';
13
14 public function __construct( $parent ) {
15 $this->parent = $parent;
16
17 Redux_Functions::$_parent = $parent;
18 }
19
20 public function init() {
21 $this->min = Redux_Functions::isMin();
22
23 $this->timestamp = ReduxFramework::$_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('Redux_Helpers', 'localize'));
36
37 $this->set_localized_data();
38
39 /**
40 * action 'redux-enqueue-{opt_name}'
41 *
42 * @deprecated
43 *
44 * @param object $this ReduxFramework
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 ReduxFramework::$_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 ReduxFramework::$_url . 'assets/css/redux-fields.css',
74 array(),
75 $this->timestamp,
76 'all'
77 );
78 }
79
80 //*****************************************************************
81 // Select2 CSS
82 //*****************************************************************
83 Redux_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 ReduxFramework::$_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 ReduxFramework::$_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 ReduxFramework::$_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", ReduxFramework::$_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 ReduxFramework::$_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 ReduxFramework::$_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 ReduxFramework::$_url . 'assets/css/rtl.css',
182 array( 'redux-admin-css' ),
183 $this->timestamp,
184 'all'
185 );
186 }
187
188 }
189
190 private function register_scripts() {
191 //*****************************************************************
192 // JQuery / JQuery UI JS
193 //*****************************************************************
194 wp_enqueue_script( 'jquery' );
195 wp_enqueue_script( 'jquery-ui-core' );
196 wp_enqueue_script( 'jquery-ui-dialog' );
197
198 //*****************************************************************
199 // Select2 Sortable JS
200 //*****************************************************************
201 wp_register_script(
202 'redux-select2-sortable-js',
203 ReduxFramework::$_url . 'assets/js/vendor/redux.select2.sortable' . $this->min . '.js',
204 array( 'jquery', 'jquery-ui-sortable' ),
205 $this->timestamp,
206 true
207 );
208
209 //*****************************************************************
210 // Select2 JS
211 //*****************************************************************
212
213 // JWp6 plugin giving us problems. They need to update.
214 if ( wp_script_is ( 'jquerySelect2' )) {
215 wp_deregister_script( 'jquerySelect2' );
216 wp_dequeue_script('jquerySelect2');
217 wp_dequeue_style('jquerySelect2Style');
218 }
219
220
221 Redux_CDN::register_script(
222 'select2-js',
223 '//cdn.jsdelivr.net/select2/3.5.2/select2' . $this->min . '.js',
224 array( 'jquery', 'redux-select2-sortable-js' ),
225 '3.5.2',
226 true
227 );
228
229 //*****************************************************************
230 // QTip JS
231 //*****************************************************************
232 $js_file = 'jquery.qtip.min.js';
233 if ($this->parent->args['dev_mode']) {
234 $js_file = 'jquery.qtip.js';
235 }
236
237 wp_enqueue_script(
238 'qtip-js',
239 ReduxFramework::$_url . 'assets/js/vendor/qtip/' . $js_file,
240 array( 'jquery' ),
241 '2.2.0',
242 true
243 );
244
245 //*****************************************************************
246 // Spectrum JS
247 //*****************************************************************
248 $js_file = 'redux-spectrum.min.js';
249 if ($this->parent->args['dev_mode']) {
250 $js_file = 'redux-spectrum.js';
251 }
252
253 wp_register_script(
254 'redux-spectrum-js',
255 ReduxFramework::$_url . 'assets/js/vendor/spectrum/' . $js_file,
256 array( 'jquery' ),
257 '1.3.3',
258 true
259 );
260
261 $depArray = array( 'jquery' );
262
263 //*****************************************************************
264 // Vendor JS
265 //*****************************************************************
266 wp_register_script(
267 'redux-vendor',
268 ReduxFramework::$_url . 'assets/js/vendor.min.js',
269 array( 'jquery' ),
270 $this->timestamp,
271 true
272 );
273
274 array_push( $depArray, 'redux-vendor' );
275
276
277 //*****************************************************************
278 // Redux JS
279 //*****************************************************************
280 wp_register_script(
281 'redux-js',
282 ReduxFramework::$_url . 'assets/js/redux' . $this->min . '.js',
283 $depArray,
284 $this->timestamp,
285 true
286 );
287
288 wp_enqueue_script(
289 'webfontloader',
290 'https://ajax.googleapis.com/ajax/libs/webfont/1.5.0/webfont.js',
291 array( 'jquery' ),
292 '1.5.0',
293 true
294 );
295 }
296
297 public function _enqueue_field($field) {
298 // TODO AFTER GROUP WORKS - Revert IF below
299 // if( isset( $field['type'] ) && $field['type'] != 'callback' ) {
300 if ( isset( $field['type'] ) && $field['type'] != 'callback' ) {
301
302 $field_class = 'ReduxFramework_' . $field['type'];
303
304 /**
305 * Field class file
306 * filter 'redux/{opt_name}/field/class/{field.type}
307 *
308 * @param string field class file path
309 * @param array $field field config data
310 */
311 $class_file = apply_filters( "redux/{$this->parent->args['opt_name']}/field/class/{$field['type']}", ReduxFramework::$_dir . "inc/fields/{$field['type']}/field_{$field['type']}.php", $field );
312 if ( $class_file ) {
313 if ( ! class_exists( $field_class ) ) {
314 if ( file_exists( $class_file ) ) {
315 require_once $class_file;
316 }
317 }
318
319 if ( ( method_exists( $field_class, 'enqueue' ) ) || method_exists( $field_class, 'localize' ) ) {
320
321 if ( ! isset( $this->parent->options[ $field['id'] ] ) ) {
322 $this->parent->options[ $field['id'] ] = "";
323 }
324
325 $theField = new $field_class( $field, $this->parent->options[ $field['id'] ], $this->parent );
326
327 // Move dev_mode check to a new if/then block
328 if ( ! wp_script_is( 'redux-field-' . $field['type'] . '-js', 'enqueued' ) && class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) {
329 $theField->enqueue();
330 }
331
332 if ( method_exists( $field_class, 'localize' ) ) {
333 $params = $theField->localize( $field );
334 if ( ! isset( $this->parent->localize_data[ $field['type'] ] ) ) {
335 $this->parent->localize_data[ $field['type'] ] = array();
336 }
337 $this->parent->localize_data[ $field['type'] ][ $field['id'] ] = $theField->localize( $field );
338 }
339
340 unset( $theField );
341 }
342 }
343 }
344 }
345
346 private function enqueue_fields() {
347 foreach ( $this->parent->sections as $section ) {
348 if ( isset( $section['fields'] ) ) {
349 foreach ( $section['fields'] as $field ) {
350 $this->_enqueue_field( $field );
351 }
352 }
353 }
354 }
355
356 public function get_warnings_and_errors_array() {
357 // Construct the errors array.
358 if ( isset( $this->parent->transients['last_save_mode'] ) && ! empty( $this->parent->transients['notices']['errors'] ) ) {
359 $theTotal = 0;
360 $theErrors = array();
361
362 foreach ( $this->parent->transients['notices']['errors'] as $error ) {
363 $theErrors[ $error['section_id'] ]['errors'][] = $error;
364
365 if ( ! isset( $theErrors[ $error['section_id'] ]['total'] ) ) {
366 $theErrors[ $error['section_id'] ]['total'] = 0;
367 }
368
369 $theErrors[ $error['section_id'] ]['total'] ++;
370 $theTotal ++;
371 }
372
373 $this->parent->localize_data['errors'] = array( 'total' => $theTotal, 'errors' => $theErrors );
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
442 $this->parent->localize_data['fieldsHidden'] = $this->parent->fieldsHidden;
443 $this->parent->localize_data['options'] = $this->parent->options;
444 $this->parent->localize_data['defaults'] = $this->parent->options_defaults;
445
446 /**
447 * Save pending string
448 * filter 'redux/{opt_name}/localize/save_pending
449 *
450 * @param string save_pending string
451 */
452 $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' ) );
453
454 /**
455 * Reset all string
456 * filter 'redux/{opt_name}/localize/reset
457 *
458 * @param string reset all string
459 */
460 $reset_all = apply_filters( "redux/{$this->parent->args['opt_name']}/localize/reset", __( 'Are you sure? Resetting will lose all custom values.', 'redux-framework' ) );
461
462 /**
463 * Reset section string
464 * filter 'redux/{opt_name}/localize/reset_section
465 *
466 * @param string reset section string
467 */
468 $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' ) );
469
470 /**
471 * Preset confirm string
472 * filter 'redux/{opt_name}/localize/preset
473 *
474 * @param string preset confirm string
475 */
476 $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' ) );
477
478 /**
479 * Import confirm string
480 * filter 'redux/{opt_name}/localize/import
481 *
482 * @param string import confirm string
483 */
484 $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' ) );
485
486 global $pagenow;
487 $this->parent->localize_data['args'] = array(
488 'save_pending' => $save_pending,
489 'reset_confirm' => $reset_all,
490 'reset_section_confirm' => $reset_section,
491 'import_section_confirm' => $import_confirm,
492 'preset_confirm' => $preset_confirm,
493 'please_wait' => __( 'Please Wait', 'redux-framework' ),
494 'opt_name' => $this->parent->args['opt_name'],
495 'slug' => $this->parent->args['page_slug'],
496 'hints' => $this->parent->args['hints'],
497 'disable_save_warn' => $this->parent->args['disable_save_warn'],
498 'class' => $this->parent->args['class'],
499 'ajax_save' => $this->parent->args['ajax_save'],
500 'menu_search' => $pagenow . '?page=' . $this->parent->args['page_slug'] . "&tab="
501 );
502
503 $this->parent->localize_data['ajax'] = array(
504 'console' => __( 'There was an error saving. Here is the result of your action:', 'redux-framework' ),
505 'alert' => __( 'There was a problem with your action. Please try again or reload the page.', 'redux-framework' ),
506 );
507
508 $this->parent->localize_data = apply_filters( "redux/{$this->parent->args['opt_name']}/localize", $this->parent->localize_data );
509
510 $this->get_warnings_and_errors_array();
511
512 wp_localize_script(
513 'redux-js',
514 'redux',
515 $this->parent->localize_data
516 );
517
518 wp_enqueue_script( 'redux-js' ); // Enque the JS now
519
520 }
521 }
522 }