PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.3.9
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.3.9
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
← All changes | includes/class-scripts-styles.php +509 -505 1.6.81.3.9 View file →
@@ -1,505 +1,509 @@
1 -<?php
2 -
3 -/**
4 - * The scripts class
5 - *
6 - * @since 1.1.0
7 - */
8 -class WeForms_Scripts_Styles {
9 -
10 - /**
11 - * The constructor
12 - */
13 - public function __construct() {
14 - if ( is_admin() ) {
15 - add_action( 'admin_enqueue_scripts', [ $this, 'register_backend' ], 1800 );
16 - add_action( 'admin_enqueue_scripts', [ $this, 'no_conflict_mode' ], 1500 );
17 - } else {
18 - add_action( 'wp_enqueue_scripts', [ $this, 'register_frontend' ] );
19 - }
20 - }
21 -
22 - /**
23 - * Helper function for No-Conflict Mode
24 - *
25 - * @return void
26 - */
27 - public function no_conflict_mode() {
28 - global $wp_scripts;
29 -
30 - $reg_arr = [];
31 - $required_objects = [
32 - 'utils',
33 - 'common',
34 - 'wp-ajax-response',
35 - 'wp-api-request',
36 - 'wp-pointer',
37 - 'wp-auth-check',
38 - 'wp-lists',
39 - 'prototype',
40 - 'jquery',
41 - 'jquery-core',
42 - 'jquery-migrate',
43 - 'jquery-ui-core',
44 - 'jquery-effects-core',
45 - 'jquery-effects-blind',
46 - 'jquery-effects-bounce',
47 - 'jquery-effects-clip',
48 - 'jquery-effects-drop',
49 - 'jquery-effects-explode',
50 - 'jquery-effects-fade',
51 - 'jquery-effects-fold',
52 - 'jquery-effects-highlight',
53 - 'jquery-effects-puff',
54 - 'jquery-effects-pulsate',
55 - 'jquery-effects-scale',
56 - 'jquery-effects-shake',
57 - 'jquery-effects-size',
58 - 'jquery-effects-slide',
59 - 'jquery-effects-transfer',
60 - 'jquery-ui-accordion',
61 - 'jquery-ui-autocomplete',
62 - 'jquery-ui-button',
63 - 'jquery-ui-datepicker',
64 - 'jquery-ui-dialog',
65 - 'jquery-ui-draggable',
66 - 'jquery-ui-droppable',
67 - 'jquery-ui-menu',
68 - 'jquery-ui-mouse',
69 - 'jquery-ui-position',
70 - 'jquery-ui-progressbar',
71 - 'jquery-ui-resizable',
72 - 'jquery-ui-selectable',
73 - 'jquery-ui-selectmenu',
74 - 'jquery-ui-slider',
75 - 'jquery-ui-sortable',
76 - 'jquery-ui-spinner',
77 - 'jquery-ui-tabs',
78 - 'jquery-ui-tooltip',
79 - 'jquery-ui-widget',
80 - 'jquery-form',
81 - 'jquery-color',
82 - 'schedule',
83 - 'jquery-query',
84 - 'jquery-serialize-object',
85 - 'jquery-hotkeys',
86 - 'jquery-table-hotkeys',
87 - 'jquery-touch-punch',
88 - 'thickbox',
89 - 'json2',
90 - 'underscore',
91 - 'backbone',
92 - 'wp-util',
93 - 'wp-sanitize',
94 - 'wp-backbone',
95 - 'wp-embed',
96 - 'wp-api',
97 - 'postbox',
98 - 'post',
99 - 'link',
100 - 'inline-edit-post',
101 - 'inline-edit-tax',
102 - 'iris',
103 - 'wp-color-picker',
104 - 'dashboard',
105 - 'weforms-chart-js',
106 - 'weforms-tiny-mce',
107 - 'weforms-vendor',
108 - 'weforms-form-builder-mixins',
109 - 'weforms-form-builder-mixins-form',
110 - 'weforms-form-builder-components',
111 - 'weforms-int-payment-settings',
112 - 'weforms-int-mailpoet',
113 - 'weforms-int-aweber',
114 - 'weforms-int-campaign-monitor',
115 - 'weforms-int-constant-contact',
116 - 'weforms-int-convertkit',
117 - 'weforms-int-getresponse',
118 - 'weforms-int-google-analytics',
119 - 'weforms-int-google-sheets',
120 - 'weforms-int-hubspot',
121 - 'weforms-int-mailchimp',
122 - 'weforms-int-salesforce',
123 - 'weforms-int-trello',
124 - 'weforms-int-zapier',
125 - 'weforms-int-zoho',
126 - 'weforms-mixins',
127 - 'weforms-components',
128 - 'weforms-app',
129 - 'weforms-pro-wpuf-form-mixins',
130 - 'weforms-pro-wpuf-form-components',
131 - 'weforms-pro-components',
132 - ];
133 -
134 - $wpuf_settings = weforms_get_settings();
135 - $screen = get_current_screen();
136 -
137 - if ( isset( $wpuf_settings['no_conflict'] ) && $wpuf_settings['no_conflict'] && $screen->base == 'toplevel_page_weforms' ) {
138 - $registered_scripts = array_keys( $wp_scripts->registered );
139 -
140 - foreach ( $registered_scripts as $r_script ) {
141 - if ( !in_array( $r_script, $required_objects ) ) {
142 - $reg_arr[] = $r_script;
143 - wp_deregister_script( $r_script );
144 - }
145 - }
146 -
147 - // $this->enqueue_scripts( $this->get_admin_scripts() );
148 -
149 - // foreach ( $reg_arr as $reg_obj ) {
150 - // if ( !in_array( $reg_obj, $wp_scripts->queue ) ) {
151 - // wp_enqueue_script( $reg_obj );
152 - // }
153 - // }
154 - }
155 - }
156 -
157 - /**
158 - * Register frontend scripts and styles
159 - *
160 - * @return void
161 - */
162 - public function register_frontend() {
163 - $this->register_styles( $this->get_frontend_styles() );
164 - $this->register_scripts( $this->get_frontend_scripts() );
165 -
166 - $this->get_frontend_localized();
167 - }
168 -
169 - /**
170 - * Register frontend scripts and styles
171 - *
172 - * @return void
173 - */
174 - public function register_backend() {
175 - // bail out if not weforms screen
176 - $screen = get_current_screen();
177 -
178 - if ( $screen->base != 'toplevel_page_weforms' ) {
179 - return;
180 - }
181 -
182 - $this->register_styles( $this->get_admin_styles() );
183 - $this->register_scripts( $this->get_admin_scripts() );
184 -
185 - $this->get_frontend_localized();
186 - }
187 -
188 - /**
189 - * Enqueue all the scripts and styles for frontend
190 - *
191 - * @return void
192 - */
193 - public function enqueue_frontend() {
194 - $this->enqueue_scripts( $this->get_frontend_scripts() );
195 - $this->enqueue_styles( $this->get_frontend_styles() );
196 - }
197 -
198 - /**
199 - * Enqueue all the scripts and styles for backend
200 - *
201 - * @return void
202 - */
203 - public function enqueue_backend() {
204 - $this->enqueue_scripts( $this->get_admin_scripts() );
205 - $this->enqueue_styles( $this->get_admin_styles() );
206 - }
207 -
208 - /**
209 - * Get file prefix
210 - *
211 - * @return string
212 - */
213 - public function get_prefix() {
214 - $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
215 -
216 - return $prefix;
217 - }
218 -
219 - /**
220 - * Get all registered admin scripts
221 - *
222 - * @return array
223 - */
224 - public function get_admin_scripts() {
225 - $prefix = $this->get_prefix();
226 -
227 - $form_builder_js_deps = apply_filters( 'weforms-form-builder-js-deps', [
228 - 'jquery',
229 - 'jquery-ui-sortable',
230 - 'jquery-ui-draggable',
231 - 'jquery-ui-droppable',
232 - 'jquery-ui-resizable',
233 - 'jquery-ui-datepicker',
234 - 'weforms-tiny-mce',
235 - 'underscore',
236 - ] );
237 -
238 - $builder_scripts = apply_filters( 'weforms_builder_scripts', [
239 - 'weforms-tiny-mce' => [
240 - 'src' => site_url( '/wp-includes/js/tinymce/tinymce.min.js' ),
241 - 'deps' => [],
242 - 'in_footer' => true,
243 - ],
244 - 'weforms-vendor' => [
245 - 'src' => WEFORMS_ASSET_URI . '/js/vendor' . $prefix . '.js',
246 - 'deps' => $form_builder_js_deps,
247 - 'in_footer' => true,
248 - ],
249 - 'weforms-form-builder-mixins' => [
250 - 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-mixins.js',
251 - 'deps' => ['weforms-vendor'],
252 - 'in_footer' => true,
253 - ],
254 - 'weforms-form-builder-mixins-form' => [
255 - 'src' => WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms' . $prefix . '.js',
256 - 'deps' => ['weforms-vendor'],
257 - 'in_footer' => true,
258 - ],
259 - 'weforms-form-builder-components' => [
260 - 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-components' . $prefix . '.js',
261 - 'deps' => [ 'weforms-form-builder-mixins', 'weforms-form-builder-mixins-form' ],
262 - 'in_footer' => true,
263 - ],
264 - ] );
265 -
266 - $spa_scripts = [
267 - 'weforms-mixins' => [
268 - 'src' => WEFORMS_ASSET_URI . '/js/spa-mixins' . $prefix . '.js',
269 - 'deps' => [ 'weforms-vendor', 'wp-util' ],
270 - 'in_footer' => true,
271 - ],
272 - 'weforms-components' => [
273 - 'src' => WEFORMS_ASSET_URI . '/js/form-builder-components' . $prefix . '.js',
274 - 'deps' => [ 'weforms-vendor', 'wp-util' ],
275 - 'in_footer' => true,
276 - ],
277 - 'weforms-app' => [
278 - 'src' => WEFORMS_ASSET_URI . '/js/spa-app' . $prefix . '.js',
279 - 'deps' => [ 'weforms-vendor', 'wp-util', 'weforms-form-builder-components' ],
280 - 'in_footer' => true,
281 - ],
282 - ];
283 -
284 - $scripts = array_merge( $builder_scripts, $spa_scripts );
285 -
286 - return apply_filters( 'weforms_admin_scripts', $scripts );
287 - }
288 -
289 - /**
290 - * Get admin styles
291 - *
292 - * @return array
293 - */
294 - public function get_admin_styles() {
295 - $frontend_styles = $this->get_frontend_styles();
296 -
297 - $backend_styles = [
298 - 'weforms-font-awesome' => [
299 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/font-awesome/css/font-awesome.min.css',
300 - ],
301 - 'weforms-sweetalert2' => [
302 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
303 - ],
304 - 'weforms-selectize' => [
305 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/css/selectize.default.css',
306 - ],
307 - 'weforms-toastr' => [
308 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr.min.css',
309 - ],
310 - 'weforms-tooltip' => [
311 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip.css',
312 - ],
313 - 'weforms-form-builder' => [
314 - 'src' => WEFORMS_ASSET_URI . '/wpuf/css/wpuf-form-builder.css',
315 - 'deps' => [
316 - 'weforms-css',
317 - 'weforms-font-awesome',
318 - 'weforms-sweetalert2',
319 - 'weforms-selectize',
320 - 'weforms-toastr',
321 - 'weforms-tooltip',
322 - ],
323 - ],
324 - 'weforms-style' => [
325 - 'src' => WEFORMS_ASSET_URI . '/css/admin.css',
326 - ],
327 - 'weforms-tiny-mce-css' => [
328 - 'src' => site_url( '/wp-includes/css/editor.css' ),
329 - 'deps' => [ 'wp-color-picker' ],
330 - ],
331 - ];
332 -
333 - $styles = array_merge( $frontend_styles, $backend_styles );
334 -
335 - return apply_filters( 'weforms_admin_styles', $styles );
336 - }
337 -
338 - /**
339 - * Get all registered frontend scripts
340 - *
341 - * @return array
342 - */
343 - public function get_frontend_scripts() {
344 - $prefix = $this->get_prefix();
345 -
346 - $scripts = [
347 - 'wpuf-form' => [
348 - 'src' => WEFORMS_ASSET_URI . '/wpuf/js/frontend-form' . $prefix . '.js',
349 - 'deps' => [ 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider' ],
350 - 'in_footer' => true,
351 - ],
352 - 'wpuf-sweetalert2' => [
353 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2' . $prefix . '.js',
354 - 'in_footer' => true,
355 - ],
356 - 'jquery-ui-timepicker' => [
357 - 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon' . $prefix . '.js',
358 - 'deps' => [ 'jquery-ui-datepicker' ],
359 - 'in_footer' => true,
360 - ],
361 - 'wpuf-upload' => [
362 - 'src' => WEFORMS_ASSET_URI . '/wpuf/js/upload' . $prefix . '.js',
363 - 'deps' => [ 'jquery', 'plupload-handlers', 'jquery-ui-sortable' ],
364 - 'in_footer' => true,
365 - ],
366 - ];
367 -
368 - // load single min file of above scripts including chart js when script debug disabled
369 - // weforms.min.js/weforms.js file generate by grunt release command
370 - // check concat:frontendScripts in Gruntfile.js
371 - if ( !SCRIPT_DEBUG ) {
372 - $scripts = [
373 - 'wpuf-form' => [
374 - 'src' => WEFORMS_ASSET_URI . '/js/weforms.min.js',
375 - 'deps' => [ 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider', 'plupload-handlers', 'jquery-ui-sortable' ],
376 - 'in_footer' => true,
377 - ],
378 - ];
379 - }
380 -
381 - return apply_filters( 'weforms_frontend_scripts', $scripts );
382 - }
383 -
384 - /**
385 - * Get all registered frontend styles
386 - *
387 - * @return array
388 - */
389 - public function get_frontend_styles() {
390 - $styles = [
391 - 'weforms-css' => [
392 - 'src' => WEFORMS_ASSET_URI . '/wpuf/css/frontend-forms.css',
393 - ],
394 - 'wpuf-sweetalert2' => [
395 - 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
396 - ],
397 - 'jquery-ui' => [
398 - 'src' => WEFORMS_ASSET_URI . '/wpuf/css/jquery-ui-1.9.1.custom.css',
399 - ],
400 - ];
401 -
402 - return apply_filters( 'weforms_frontend_styles', $styles );
403 - }
404 -
405 - /**
406 - * Frontend localized scripts
407 - *
408 - * @return void
409 - */
410 - public function get_frontend_localized() {
411 - wp_localize_script( 'wpuf-form', 'wpuf_frontend', apply_filters( 'wpuf_frontend_js_data', [
412 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
413 - 'error_message' => __( 'Please fix the errors to proceed', 'weforms' ),
414 - 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
415 - 'word_limit' => __( 'Word limit reached', 'weforms' ),
416 - ] ) );
417 -
418 - wp_localize_script( 'wpuf-form', 'error_str_obj', [
419 - 'required' => __( 'is required', 'weforms' ),
420 - 'mismatch' => __( 'does not match', 'weforms' ),
421 - 'validation' => __( 'is not valid', 'weforms' ),
422 - 'duplicate' => __( 'requires a unique entry and this value has already been used', 'weforms' ),
423 - ] );
424 -
425 - wp_localize_script( 'wpuf-form', 'wpuf_frontend_upload', [
426 - 'confirmMsg' => __( 'Are you sure?', 'weforms' ),
427 - 'delete_it' => __( 'Yes, delete it', 'weforms' ),
428 - 'cancel_it' => __( 'No, cancel it', 'weforms' ),
429 - 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
430 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
431 - 'plupload' => [
432 - 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
433 - 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
434 - 'filters' => [
435 - [
436 - 'title' => __( 'Allowed Files', 'weforms' ),
437 - 'extensions' => '*',
438 - ],
439 - ],
440 - 'multipart' => true,
441 - 'urlstream_upload' => true,
442 - 'warning' => __( 'Maximum number of files reached!', 'weforms' ),
443 - 'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'weforms' ),
444 - 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'weforms' ),
445 - ],
446 - ] );
447 - }
448 -
449 - /**
450 - * Register scripts
451 - *
452 - * @param array $scripts
453 - *
454 - * @return void
455 - */
456 - public function register_scripts( $scripts ) {
457 - foreach ( $scripts as $handle => $script ) {
458 - $deps = isset( $script['deps'] ) ? $script['deps'] : false;
459 - $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
460 -
461 - wp_register_script( $handle, $script['src'], $deps, WEFORMS_VERSION, $in_footer );
462 - }
463 - }
464 -
465 - /**
466 - * Register styles
467 - *
468 - * @param array $styles
469 - *
470 - * @return void
471 - */
472 - public function register_styles( $styles ) {
473 - foreach ( $styles as $handle => $style ) {
474 - $deps = isset( $style['deps'] ) ? $style['deps'] : false;
475 -
476 - wp_register_style( $handle, $style['src'], $deps, WEFORMS_VERSION );
477 - }
478 - }
479 -
480 - /**
481 - * Enqueue the scripts
482 - *
483 - * @param array $scripts
484 - *
485 - * @return void
486 - */
487 - public function enqueue_scripts( $scripts ) {
488 - foreach ( $scripts as $handle => $script ) {
489 - wp_enqueue_script( $handle );
490 - }
491 - }
492 -
493 - /**
494 - * Enqueue styles
495 - *
496 - * @param array $styles
497 - *
498 - * @return void
499 - */
500 - public function enqueue_styles( $styles ) {
501 - foreach ( $styles as $handle => $script ) {
502 - wp_enqueue_style( $handle );
503 - }
504 - }
505 -}
1 +<?php
2 +
3 +/**
4 + * The scripts class
5 + *
6 + * @since 1.1.0
7 + */
8 +class WeForms_Scripts_Styles {
9 +
10 + /**
11 + * The constructor
12 + */
13 + function __construct() {
14 +
15 + if ( is_admin() ) {
16 + add_action( 'admin_enqueue_scripts', array( $this, 'register_backend' ), 1800 );
17 + add_action( 'admin_enqueue_scripts', array( $this, 'no_conflict_mode' ), 1500 );
18 + } else {
19 + add_action( 'wp_enqueue_scripts', array( $this, 'register_frontend' ) );
20 + }
21 + }
22 +
23 + /**
24 + * Helper function for No-Conflict Mode
25 + *
26 + * @return void
27 + */
28 + public function no_conflict_mode() {
29 + global $wp_scripts;
30 +
31 + $reg_arr = array();
32 + $required_objects = array (
33 + 'utils',
34 + 'common',
35 + 'wp-ajax-response',
36 + 'wp-api-request',
37 + 'wp-pointer',
38 + 'wp-auth-check',
39 + 'wp-lists',
40 + 'prototype',
41 + 'jquery',
42 + 'jquery-core',
43 + 'jquery-migrate',
44 + 'jquery-ui-core',
45 + 'jquery-effects-core',
46 + 'jquery-effects-blind',
47 + 'jquery-effects-bounce',
48 + 'jquery-effects-clip',
49 + 'jquery-effects-drop',
50 + 'jquery-effects-explode',
51 + 'jquery-effects-fade',
52 + 'jquery-effects-fold',
53 + 'jquery-effects-highlight',
54 + 'jquery-effects-puff',
55 + 'jquery-effects-pulsate',
56 + 'jquery-effects-scale',
57 + 'jquery-effects-shake',
58 + 'jquery-effects-size',
59 + 'jquery-effects-slide',
60 + 'jquery-effects-transfer',
61 + 'jquery-ui-accordion',
62 + 'jquery-ui-autocomplete',
63 + 'jquery-ui-button',
64 + 'jquery-ui-datepicker',
65 + 'jquery-ui-dialog',
66 + 'jquery-ui-draggable',
67 + 'jquery-ui-droppable',
68 + 'jquery-ui-menu',
69 + 'jquery-ui-mouse',
70 + 'jquery-ui-position',
71 + 'jquery-ui-progressbar',
72 + 'jquery-ui-resizable',
73 + 'jquery-ui-selectable',
74 + 'jquery-ui-selectmenu',
75 + 'jquery-ui-slider',
76 + 'jquery-ui-sortable',
77 + 'jquery-ui-spinner',
78 + 'jquery-ui-tabs',
79 + 'jquery-ui-tooltip',
80 + 'jquery-ui-widget',
81 + 'jquery-form',
82 + 'jquery-color',
83 + 'schedule',
84 + 'jquery-query',
85 + 'jquery-serialize-object',
86 + 'jquery-hotkeys',
87 + 'jquery-table-hotkeys',
88 + 'jquery-touch-punch',
89 + 'thickbox',
90 + 'json2',
91 + 'underscore',
92 + 'backbone',
93 + 'wp-util',
94 + 'wp-sanitize',
95 + 'wp-backbone',
96 + 'wp-embed',
97 + 'wp-api',
98 + 'postbox',
99 + 'post',
100 + 'link',
101 + 'inline-edit-post',
102 + 'inline-edit-tax',
103 + 'iris',
104 + 'wp-color-picker',
105 + 'dashboard',
106 + 'weforms-chart-js',
107 + 'weforms-tiny-mce',
108 + 'weforms-vendor',
109 + 'weforms-form-builder-mixins',
110 + 'weforms-form-builder-mixins-form',
111 + 'weforms-form-builder-components',
112 + 'weforms-int-payment-settings',
113 + 'weforms-int-mailpoet',
114 + 'weforms-int-aweber',
115 + 'weforms-int-campaign-monitor',
116 + 'weforms-int-constant-contact',
117 + 'weforms-int-convertkit',
118 + 'weforms-int-getresponse',
119 + 'weforms-int-google-analytics',
120 + 'weforms-int-google-sheets',
121 + 'weforms-int-hubspot',
122 + 'weforms-int-mailchimp',
123 + 'weforms-int-salesforce',
124 + 'weforms-int-trello',
125 + 'weforms-int-zapier',
126 + 'weforms-int-zoho',
127 + 'weforms-mixins',
128 + 'weforms-components',
129 + 'weforms-app',
130 + 'weforms-pro-wpuf-form-mixins',
131 + 'weforms-pro-wpuf-form-components',
132 + 'weforms-pro-components',
133 + );
134 +
135 + $wpuf_settings = weforms_get_settings();
136 + $screen = get_current_screen();
137 +
138 + if ( isset( $wpuf_settings['no_conflict'] ) && $wpuf_settings['no_conflict'] && $screen->base == 'toplevel_page_weforms' ) {
139 + $registered_scripts = array_keys( $wp_scripts->registered );
140 +
141 + foreach ( $registered_scripts as $r_script ) {
142 + if ( !in_array( $r_script, $required_objects ) ) {
143 + $reg_arr[] = $r_script;
144 + wp_deregister_script( $r_script );
145 + }
146 + }
147 +
148 +// $this->enqueue_scripts( $this->get_admin_scripts() );
149 +
150 +// foreach ( $reg_arr as $reg_obj ) {
151 +// if ( !in_array( $reg_obj, $wp_scripts->queue ) ) {
152 +// wp_enqueue_script( $reg_obj );
153 +// }
154 +// }
155 + }
156 +
157 + }
158 +
159 + /**
160 + * Register frontend scripts and styles
161 + *
162 + * @return void
163 + */
164 + public function register_frontend() {
165 + $this->register_styles( $this->get_frontend_styles() );
166 + $this->register_scripts( $this->get_frontend_scripts() );
167 +
168 + $this->get_frontend_localized();
169 + }
170 +
171 + /**
172 + * Register frontend scripts and styles
173 + *
174 + * @return void
175 + */
176 + public function register_backend() {
177 + // bail out if not weforms screen
178 + $screen = get_current_screen();
179 + if ( $screen->base != 'toplevel_page_weforms' ) {
180 + return;
181 + }
182 +
183 + $this->register_styles( $this->get_admin_styles() );
184 + $this->register_scripts( $this->get_admin_scripts() );
185 +
186 + $this->get_frontend_localized();
187 + }
188 +
189 + /**
190 + * Enqueue all the scripts and styles for frontend
191 + *
192 + * @return void
193 + */
194 + public function enqueue_frontend() {
195 + $this->enqueue_scripts( $this->get_frontend_scripts() );
196 + $this->enqueue_styles( $this->get_frontend_styles() );
197 + }
198 +
199 + /**
200 + * Enqueue all the scripts and styles for backend
201 + *
202 + * @return void
203 + */
204 + public function enqueue_backend() {
205 + $this->enqueue_scripts( $this->get_admin_scripts() );
206 + $this->enqueue_styles( $this->get_admin_styles() );
207 + }
208 +
209 + /**
210 + * Get file prefix
211 + *
212 + * @return string
213 + */
214 + public function get_prefix() {
215 + $prefix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
216 +
217 + return $prefix;
218 + }
219 +
220 + /**
221 + * Get all registered admin scripts
222 + *
223 + * @return array
224 + */
225 + public function get_admin_scripts() {
226 + $prefix = $this->get_prefix();
227 +
228 + $form_builder_js_deps = apply_filters( 'weforms-form-builder-js-deps', array(
229 + 'jquery',
230 + 'jquery-ui-sortable',
231 + 'jquery-ui-draggable',
232 + 'jquery-ui-droppable',
233 + 'jquery-ui-resizable',
234 + 'jquery-ui-datepicker',
235 + 'weforms-tiny-mce',
236 + 'underscore',
237 + ) );
238 +
239 + $builder_scripts = apply_filters( 'weforms_builder_scripts', array(
240 + 'weforms-tiny-mce' => array(
241 + 'src' => site_url( '/wp-includes/js/tinymce/tinymce.min.js' ),
242 + 'deps' => array(),
243 + 'in_footer' => true
244 + ),
245 + 'weforms-vendor' => array(
246 + 'src' => WEFORMS_ASSET_URI . '/js/vendor' . $prefix . '.js',
247 + 'deps' => $form_builder_js_deps,
248 + 'in_footer' => true
249 + ),
250 + 'weforms-form-builder-mixins' => array(
251 + 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-mixins.js',
252 + 'deps' => array('weforms-vendor'),
253 + 'in_footer' => true
254 + ),
255 + 'weforms-form-builder-mixins-form' => array(
256 + 'src' => WEFORMS_ASSET_URI . '/js/wpuf-form-builder-contact-forms' . $prefix . '.js',
257 + 'deps' => array('weforms-vendor'),
258 + 'in_footer' => true
259 + ),
260 + 'weforms-form-builder-components' => array(
261 + 'src' => WEFORMS_ASSET_URI . '/wpuf/js/wpuf-form-builder-components' . $prefix . '.js',
262 + 'deps' => array( 'weforms-form-builder-mixins', 'weforms-form-builder-mixins-form' ),
263 + 'in_footer' => true
264 + ),
265 + ) );
266 +
267 + $spa_scripts = array(
268 + 'weforms-mixins' => array(
269 + 'src' => WEFORMS_ASSET_URI . '/js/spa-mixins' . $prefix . '.js',
270 + 'deps' => array( 'weforms-vendor', 'wp-util' ),
271 + 'in_footer' => true
272 + ),
273 + 'weforms-components' => array(
274 + 'src' => WEFORMS_ASSET_URI . '/js/form-builder-components' . $prefix . '.js',
275 + 'deps' => array( 'weforms-vendor', 'wp-util' ),
276 + 'in_footer' => true
277 + ),
278 + 'weforms-app' => array(
279 + 'src' => WEFORMS_ASSET_URI . '/js/spa-app' . $prefix . '.js',
280 + 'deps' => array( 'weforms-vendor', 'wp-util', 'weforms-form-builder-components' ),
281 + 'in_footer' => true
282 + ),
283 + );
284 +
285 + $scripts = array_merge( $builder_scripts, $spa_scripts );
286 +
287 + return apply_filters( 'weforms_admin_scripts', $scripts );
288 + }
289 +
290 + /**
291 + * Get admin styles
292 + *
293 + * @return array
294 + */
295 + public function get_admin_styles() {
296 + $frontend_styles = $this->get_frontend_styles();
297 +
298 + $backend_styles = array(
299 + 'weforms-font-awesome' => array(
300 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/font-awesome/css/font-awesome.min.css',
301 + ),
302 + 'weforms-sweetalert2' => array(
303 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
304 + ),
305 + 'weforms-selectize' => array(
306 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/selectize/css/selectize.default.css',
307 + ),
308 + 'weforms-toastr' => array(
309 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/toastr/toastr.min.css',
310 + ),
311 + 'weforms-tooltip' => array(
312 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/tooltip/tooltip.css',
313 + ),
314 + 'weforms-form-builder' => array(
315 + 'src' => WEFORMS_ASSET_URI . '/wpuf/css/wpuf-form-builder.css',
316 + 'deps' => array(
317 + 'weforms-css',
318 + 'weforms-font-awesome',
319 + 'weforms-sweetalert2',
320 + 'weforms-selectize',
321 + 'weforms-toastr',
322 + 'weforms-tooltip'
323 + )
324 + ),
325 + 'weforms-style' => array(
326 + 'src' => WEFORMS_ASSET_URI . '/css/admin.css',
327 + ),
328 + 'weforms-tiny-mce-css' => array(
329 + 'src' => site_url( '/wp-includes/css/editor.css' ),
330 + 'deps' => array( 'wp-color-picker' )
331 + )
332 +
333 + );
334 +
335 + $styles = array_merge( $frontend_styles, $backend_styles );
336 +
337 + return apply_filters( 'weforms_admin_styles', $styles );
338 + }
339 +
340 + /**
341 + * Get all registered frontend scripts
342 + *
343 + * @return array
344 + */
345 + public function get_frontend_scripts() {
346 +
347 + $prefix = $this->get_prefix();
348 +
349 + $scripts = array(
350 + 'wpuf-form' => array(
351 + 'src' => WEFORMS_ASSET_URI . '/wpuf/js/frontend-form' . $prefix . '.js',
352 + 'deps' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider' ),
353 + 'in_footer' => false
354 + ),
355 + 'wpuf-sweetalert2' => array(
356 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2' . $prefix . '.js',
357 + 'in_footer' => false
358 + ),
359 + 'jquery-ui-timepicker' => array(
360 + 'src' => WEFORMS_ASSET_URI . '/wpuf/js/jquery-ui-timepicker-addon' . $prefix . '.js',
361 + 'deps' => array( 'jquery-ui-datepicker' ),
362 + 'in_footer' => false
363 + ),
364 + 'wpuf-upload' => array(
365 + 'src' => WEFORMS_ASSET_URI . '/wpuf/js/upload' . $prefix . '.js',
366 + 'deps' => array( 'jquery', 'plupload-handlers', 'jquery-ui-sortable' ),
367 + 'in_footer' => false
368 + )
369 + );
370 +
371 + // load single min file of above scripts including chart js when script debug disabled
372 + // weforms.min.js/weforms.js file generate by grunt release command
373 + // check concat:frontendScripts in Gruntfile.js
374 + if ( !SCRIPT_DEBUG ) {
375 + $scripts = array(
376 + 'wpuf-form' => array(
377 + 'src' => WEFORMS_ASSET_URI . '/js/weforms.min.js',
378 + 'deps' => array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-slider', 'plupload-handlers', 'jquery-ui-sortable' ),
379 + 'in_footer' => false
380 + )
381 + );
382 + }
383 +
384 + return apply_filters( 'weforms_frontend_scripts', $scripts );
385 + }
386 +
387 + /**
388 + * Get all registered frontend styles
389 + *
390 + * @return array
391 + */
392 + public function get_frontend_styles() {
393 + $styles = array(
394 + 'weforms-css' => array(
395 + 'src' => WEFORMS_ASSET_URI . '/wpuf/css/frontend-forms.css',
396 + ),
397 + 'wpuf-sweetalert2' => array(
398 + 'src' => WEFORMS_ASSET_URI . '/wpuf/vendor/sweetalert2/dist/sweetalert2.css',
399 + ),
400 + 'jquery-ui' => array(
401 + 'src' => WEFORMS_ASSET_URI . '/wpuf/css/jquery-ui-1.9.1.custom.css',
402 + )
403 + );
404 +
405 + return apply_filters( 'weforms_frontend_styles', $styles );
406 + }
407 +
408 + /**
409 + * Frontend localized scripts
410 + *
411 + * @return void
412 + */
413 + public function get_frontend_localized() {
414 +
415 + wp_localize_script( 'wpuf-form', 'wpuf_frontend', apply_filters( 'wpuf_frontend_js_data' , array(
416 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
417 + 'error_message' => __( 'Please fix the errors to proceed', 'weforms' ),
418 + 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
419 + 'word_limit' => __( 'Word limit reached', 'weforms' )
420 + ) ) );
421 +
422 + wp_localize_script( 'wpuf-form', 'error_str_obj', array(
423 + 'required' => __( 'is required', 'weforms' ),
424 + 'mismatch' => __( 'does not match', 'weforms' ),
425 + 'validation' => __( 'is not valid', 'weforms' ),
426 + 'duplicate' => __( 'requires a unique entry and this value has already been used', 'weforms' ),
427 + ) );
428 +
429 + wp_localize_script( 'wpuf-form', 'wpuf_frontend_upload', array(
430 + 'confirmMsg' => __( 'Are you sure?', 'weforms' ),
431 + 'delete_it' => __( 'Yes, delete it', 'weforms' ),
432 + 'cancel_it' => __( 'No, cancel it', 'weforms' ),
433 + 'nonce' => wp_create_nonce( 'wpuf_nonce' ),
434 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
435 + 'plupload' => array(
436 + 'url' => admin_url( 'admin-ajax.php' ) . '?nonce=' . wp_create_nonce( 'wpuf-upload-nonce' ),
437 + 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
438 + 'filters' => array(
439 + array(
440 + 'title' => __( 'Allowed Files', 'weforms' ),
441 + 'extensions' => '*'
442 + )
443 + ),
444 + 'multipart' => true,
445 + 'urlstream_upload' => true,
446 + 'warning' => __( 'Maximum number of files reached!', 'weforms' ),
447 + 'size_error' => __( 'The file you have uploaded exceeds the file size limit. Please try again.', 'weforms' ),
448 + 'type_error' => __( 'You have uploaded an incorrect file type. Please try again.', 'weforms' )
449 + )
450 + ) );
451 + }
452 +
453 + /**
454 + * Register scripts
455 + *
456 + * @param array $scripts
457 + *
458 + * @return void
459 + */
460 + public function register_scripts( $scripts ) {
461 + foreach ( $scripts as $handle => $script ) {
462 + $deps = isset( $script['deps'] ) ? $script['deps'] : false;
463 + $in_footer = isset( $script['in_footer'] ) ? $script['in_footer'] : false;
464 +
465 + wp_register_script( $handle, $script['src'], $deps, WEFORMS_VERSION, $in_footer );
466 + }
467 + }
468 +
469 + /**
470 + * Register styles
471 + *
472 + * @param array $styles
473 + *
474 + * @return void
475 + */
476 + public function register_styles( $styles ) {
477 + foreach ( $styles as $handle => $style ) {
478 + $deps = isset( $style['deps'] ) ? $style['deps'] : false;
479 +
480 + wp_register_style( $handle, $style['src'], $deps, WEFORMS_VERSION );
481 + }
482 + }
483 +
484 + /**
485 + * Enqueue the scripts
486 + *
487 + * @param array $scripts
488 + *
489 + * @return void
490 + */
491 + public function enqueue_scripts( $scripts ) {
492 + foreach ( $scripts as $handle => $script ) {
493 + wp_enqueue_script( $handle );
494 + }
495 + }
496 +
497 + /**
498 + * Enqueue styles
499 + *
500 + * @param array $styles
501 + *
502 + * @return void
503 + */
504 + public function enqueue_styles( $styles ) {
505 + foreach ( $styles as $handle => $script ) {
506 + wp_enqueue_style( $handle );
507 + }
508 + }
509 +}