PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.0.6
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.0.6
3.6.0 3.5.3 3.5.2 3.5.1 3.5.0 3.4.8 3.4.7 3.4.6 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.5.1 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.10 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.6.1 1.6.7 1.7.0 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.2 1.7.2.1 1.7.2.2 1.7.3 1.7.4 1.7.5 1.7.5.1 1.7.5.2 1.7.6 1.7.7 1.7.7.1 1.7.7.2 1.7.8 1.7.9 1.8.0 1.8.0.1 1.8.1 1.8.2 1.8.2.1 1.8.2.2 1.8.2.3 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.0.1 1.9.1 1.9.2 1.9.3 1.9.4 1.9.4.1 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.0.1 2.0.1 2.0.2 2.0.3 2.0.3.1 2.0.4 2.0.4.1 2.0.5 2.0.6 2.0.7 2.0.8 2.0.8.1 2.0.9 3.0.0 3.0.0.1 3.0.1 3.0.2 3.0.3 3.0.3.1 3.0.4 3.0.4.1 3.0.4.2 3.0.5 3.0.5.1 3.0.5.2 3.0.6 3.0.6.1 3.0.7.1 3.0.8 3.0.8.1 3.0.9 3.0.9.1 3.0.9.2 3.0.9.3 3.0.9.4 3.0.9.5 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.2.5 3.2.6 3.3.0 3.4.0 3.4.1 3.4.2 3.4.2.1 3.4.3 3.4.4 3.4.5 trunk 1.0 1.0.1 1.0.2 1.0.3
everest-forms / includes / class-evf-frontend-scripts.php
everest-forms / includes Last commit date
RestApi 1 year ago abstracts 1 year ago admin 1 year ago blocks 1 year ago elementor 2 years ago export 1 year ago fields 1 year ago interfaces 8 years ago libraries 3 years ago log-handlers 4 years ago shortcodes 1 year ago stats 3 years ago templates 5 years ago class-everest-forms.php 1 year ago class-evf-ajax.php 1 year ago class-evf-autoloader.php 8 years ago class-evf-background-process-import-entries.php 2 years ago class-evf-background-updater.php 8 years ago class-evf-cache-helper.php 6 years ago class-evf-cron.php 2 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-emails.php 1 year ago class-evf-fields.php 2 years ago class-evf-form-handler.php 2 years ago class-evf-form-task.php 1 year ago class-evf-forms-features.php 2 years ago class-evf-frontend-scripts.php 1 year ago class-evf-install.php 2 years ago class-evf-integrations.php 2 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 5 years ago class-evf-privacy.php 6 years ago class-evf-report-cron.php 2 years ago class-evf-reporting.php 2 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 4 years ago class-evf-smart-tags.php 1 year ago class-evf-template-loader.php 2 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 1 year ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 2 years ago evf-formatting-functions.php 4 years ago evf-notice-functions.php 4 years ago evf-template-functions.php 4 years ago evf-template-hooks.php 8 years ago evf-update-functions.php 5 years ago
class-evf-frontend-scripts.php
375 lines
1 <?php
2 /**
3 * Handle frontend scripts
4 *
5 * @class EVF_Frontend_Scripts
6 * @version 1.0.0
7 * @package EverestForms/Classes/
8 */
9
10 defined( 'ABSPATH' ) || exit;
11
12 /**
13 * EVF_Frontend_Scripts Class.
14 */
15 class EVF_Frontend_Scripts {
16
17 /**
18 * Contains an array of script handles registered by EVF.
19 *
20 * @var array
21 */
22 private static $scripts = array();
23
24 /**
25 * Contains an array of script handles registered by EVF.
26 *
27 * @var array
28 */
29 private static $styles = array();
30
31 /**
32 * Contains an array of script handles localized by EVF.
33 *
34 * @var array
35 */
36 private static $wp_localize_scripts = array();
37
38 /**
39 * Hook in methods.
40 */
41 public static function init() {
42 add_action( 'wp_enqueue_scripts', array( __CLASS__, 'load_scripts' ) );
43 add_action( 'wp_print_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
44 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'localize_printed_scripts' ), 5 );
45 }
46
47 /**
48 * Get styles for the frontend.
49 *
50 * @return array
51 */
52 public static function get_styles() {
53 return apply_filters(
54 'everest_forms_enqueue_styles',
55 array(
56 'everest-forms-general' => array(
57 'src' => self::get_asset_url( 'assets/css/everest-forms.css' ),
58 'deps' => '',
59 'version' => EVF_VERSION,
60 'media' => 'all',
61 'has_rtl' => true,
62 ),
63 'jquery-intl-tel-input' => array(
64 'src' => self::get_asset_url( 'assets/css/intlTelInput/intlTelInput.css' ),
65 'deps' => array(),
66 'version' => EVF_VERSION,
67 'media' => 'all',
68 'has_rtl' => false,
69 ),
70 )
71 );
72 }
73
74 /**
75 * Return asset URL.
76 *
77 * @param string $path Assets path.
78 *
79 * @return string
80 */
81 private static function get_asset_url( $path ) {
82 return apply_filters( 'everest_forms_get_asset_url', plugins_url( $path, EVF_PLUGIN_FILE ), $path );
83 }
84
85 /**
86 * Register a script for use.
87 *
88 * @uses wp_register_script()
89 * @param string $handle Name of the script. Should be unique.
90 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
91 * @param string[] $deps An array of registered script handles this script depends on.
92 * @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
93 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
94 */
95 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
96 self::$scripts[] = $handle;
97 wp_register_script( $handle, $path, $deps, $version, $in_footer );
98 }
99
100 /**
101 * Register and enqueue a script for use.
102 *
103 * @uses wp_enqueue_script()
104 * @param string $handle Name of the script. Should be unique.
105 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
106 * @param string[] $deps An array of registered script handles this script depends on.
107 * @param string $version String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
108 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
109 */
110 private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
111 if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
112 self::register_script( $handle, $path, $deps, $version, $in_footer );
113 }
114 wp_enqueue_script( $handle );
115 }
116
117 /**
118 * Register a style for use.
119 *
120 * @uses wp_register_style()
121 * @param string $handle Name of the stylesheet. Should be unique.
122 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
123 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
124 * @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
125 * @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
126 * @param boolean $has_rtl If has RTL version to load too.
127 */
128 private static function register_style( $handle, $path, $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
129 self::$styles[] = $handle;
130 wp_register_style( $handle, $path, $deps, $version, $media );
131
132 if ( $has_rtl ) {
133 wp_style_add_data( $handle, 'rtl', 'replace' );
134 }
135 }
136
137 /**
138 * Register and enqueue a styles for use.
139 *
140 * @uses wp_enqueue_style()
141 * @param string $handle Name of the stylesheet. Should be unique.
142 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
143 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
144 * @param string $version String specifying stylesheet version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.
145 * @param string $media The media for which this stylesheet has been defined. Accepts media types like 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'.
146 * @param boolean $has_rtl If has RTL version to load too.
147 */
148 private static function enqueue_style( $handle, $path = '', $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
149 if ( ! in_array( $handle, self::$styles, true ) && $path ) {
150 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
151 }
152 wp_enqueue_style( $handle );
153 }
154
155 /**
156 * Register all EVF scripts.
157 */
158 private static function register_scripts() {
159 if ( evf_is_amp() ) {
160 return;
161 }
162
163 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
164 $register_scripts = array(
165 'inputmask' => array(
166 'src' => self::get_asset_url( 'assets/js/inputmask/jquery.inputmask.bundle' . $suffix . '.js' ),
167 'deps' => array( 'jquery' ),
168 'version' => '4.0.0-beta.58',
169 ),
170 'flatpickr' => array(
171 'src' => self::get_asset_url( 'assets/js/flatpickr/flatpickr' . $suffix . '.js' ),
172 'deps' => array( 'jquery' ),
173 'version' => '4.6.3',
174 ),
175 'mailcheck' => array(
176 'src' => self::get_asset_url( 'assets/js/mailcheck/mailcheck' . $suffix . '.js' ),
177 'deps' => array( 'jquery' ),
178 'version' => '1.1.2',
179 ),
180 'selectWoo' => array(
181 'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
182 'deps' => array( 'jquery' ),
183 'version' => '1.0.8',
184 ),
185 'jquery-intl-tel-input' => array(
186 'src' => self::get_asset_url( '/assets/js/intlTelInput/jquery.intlTelInput' . $suffix . '.js' ),
187 'deps' => array( 'jquery' ),
188 'version' => '16.0.7',
189 ),
190 'jquery-validate' => array(
191 'src' => self::get_asset_url( 'assets/js/jquery-validate/jquery.validate' . $suffix . '.js' ),
192 'deps' => array( 'jquery' ),
193 'version' => '1.19.2',
194 ),
195 'everest-forms' => array(
196 'src' => self::get_asset_url( 'assets/js/frontend/everest-forms' . $suffix . '.js' ),
197 'deps' => array( 'jquery', 'inputmask', 'jquery-validate', 'jquery-intl-tel-input', 'selectWoo' ),
198 'version' => EVF_VERSION,
199 ),
200 'everest-forms-text-limit' => array(
201 'src' => self::get_asset_url( 'assets/js/frontend/text-limit' . $suffix . '.js' ),
202 'deps' => array(),
203 'version' => EVF_VERSION,
204 ),
205 'everest-forms-ajax-submission' => array(
206 'src' => self::get_asset_url( 'assets/js/frontend/ajax-submission' . $suffix . '.js' ),
207 'deps' => array( 'jquery', 'inputmask', 'jquery-validate' ),
208 'version' => EVF_VERSION,
209 ),
210 'everest-forms-survey-polls-quiz-script' => array(
211 'src' => self::get_asset_url( 'assets/js/frontend/everest-forms-survey-polls-quiz' . $suffix . '.js' ),
212 'deps' => array(),
213 'version' => EVF_VERSION,
214 ),
215 );
216
217 foreach ( $register_scripts as $name => $props ) {
218
219 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
220 }
221 }
222
223 /**
224 * Register all EVF sty;es.
225 */
226 private static function register_styles() {
227 $register_styles = array(
228 'evf_select2' => array(
229 'src' => self::get_asset_url( 'assets/css/select2.css' ),
230 'deps' => array(),
231 'version' => EVF_VERSION,
232 'has_rtl' => false,
233 ),
234 'flatpickr' => array(
235 'src' => self::get_asset_url( 'assets/css/flatpickr.css' ),
236 'deps' => array(),
237 'version' => EVF_VERSION,
238 'has_rtl' => false,
239 ),
240 'jquery-intl-tel-input' => array(
241 'src' => self::get_asset_url( 'assets/css/intlTelInput.css' ),
242 'deps' => array(),
243 'version' => EVF_VERSION,
244 'has_rtl' => false,
245 ),
246 );
247 foreach ( $register_styles as $name => $props ) {
248 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
249 }
250 }
251
252 /**
253 * Register/queue frontend scripts.
254 */
255 public static function load_scripts() {
256 global $post;
257
258 if ( ! did_action( 'before_everest_forms_init' ) ) {
259 return;
260 }
261
262 self::register_scripts();
263 self::register_styles();
264
265 // Enqueue dashicons.
266 wp_enqueue_style( 'dashicons' );
267
268 // CSS Styles.
269 $enqueue_styles = self::get_styles();
270 if ( $enqueue_styles ) {
271 foreach ( $enqueue_styles as $handle => $args ) {
272 if ( ! isset( $args['has_rtl'] ) ) {
273 $args['has_rtl'] = false;
274 }
275
276 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
277 }
278 }
279 }
280
281 /**
282 * Localize a EVF script once.
283 *
284 * @param string $handle Script handle the data will be attached to.
285 */
286 private static function localize_script( $handle ) {
287 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
288 $data = self::get_script_data( $handle );
289
290 if ( ! $data ) {
291 return;
292 }
293
294 $name = str_replace( '-', '_', $handle ) . '_params';
295 self::$wp_localize_scripts[] = $handle;
296 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
297 }
298 }
299
300 /**
301 * Return data for script handles.
302 *
303 * @param string $handle Script handle the data will be attached to.
304 * @return array|bool
305 */
306 private static function get_script_data( $handle ) {
307 switch ( $handle ) {
308 case 'everest-forms':
309 $params = array(
310 'ajax_url' => evf()->ajax_url(),
311 'submit' => esc_html__( 'Submit', 'everest-forms' ),
312 'disable_user_details' => get_option( 'everest_forms_disable_user_details' ),
313 'everest_forms_data_save' => wp_create_nonce( 'everest_forms_data_save_nonce' ),
314 'everest_forms_slot_booking' => wp_create_nonce( 'everest_forms_slot_booking_nonce' ),
315 'i18n_messages_required' => get_option( 'everest_forms_required_validation' ),
316 'i18n_messages_url' => get_option( 'everest_forms_url_validation' ),
317 'i18n_messages_email' => get_option( 'everest_forms_email_validation' ),
318 'i18n_messages_email_suggestion' => get_option( 'everest_forms_email_suggestion', esc_html__( 'Did you mean {suggestion}?', 'everest-forms' ) ),
319 'i18n_messages_email_suggestion_title' => esc_attr__( 'Click to accept this suggestion.', 'everest-forms' ),
320 'i18n_messages_confirm' => get_option( 'everest_forms_confirm_validation', __( 'Field values do not match.', 'everest-forms' ) ),
321 'i18n_messages_check_limit' => get_option( 'everest_forms_check_limit_validation', esc_html__( 'You have exceeded number of allowed selections: {#}.', 'everest-forms' ) ),
322 'i18n_messages_number' => get_option( 'everest_forms_number_validation' ),
323 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'everest-forms' ),
324 'mailcheck_enabled' => (bool) apply_filters( 'everest_forms_mailcheck_enabled', true ),
325 'mailcheck_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_domains', array() ) ),
326 'mailcheck_toplevel_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_toplevel_domains', array( 'dev' ) ) ),
327 'il8n_min_word_length_err_msg' => esc_html__( 'Please enter at least {0} words.', 'everest-forms' ),
328 'il8n_min_character_length_err_msg' => esc_html__( 'Please enter at least {0} characters.', 'everest-forms' ),
329 'plugin_url' => plugin_dir_url( EVF_PLUGIN_FILE ),
330 'i18n_messages_phone' => get_option( 'everest_forms_phone_validation', __( 'Please enter a valid phone number.', 'everest-forms' ) ),
331 'i18n_field_rating_greater_than_max_value_error' => esc_html__( 'Please enter in a value less than 100.', 'everest-forms' ),
332 );
333 break;
334 case 'everest-forms-text-limit':
335 $params = array(
336 'i18n_messages_limit_characters' => esc_html__( '{count} of {limit} max characters.', 'everest-forms' ),
337 'i18n_messages_limit_words' => esc_html__( '{count} of {limit} max words.', 'everest-forms' ),
338 );
339 break;
340 case 'everest-forms-ajax-submission':
341 $params = array(
342 'ajax_url' => admin_url( 'admin-ajax.php' ),
343 'evf_ajax_submission' => wp_create_nonce( 'everest_forms_ajax_form_submission' ),
344 'submit' => esc_html__( 'Submit', 'everest-forms' ),
345 'error' => esc_html__( 'Something went wrong while making an AJAX submission', 'everest-forms' ),
346 'required' => esc_html__( 'This field is required.', 'everest-forms' ),
347 'pdf_download' => esc_html__( 'Click here to download your pdf submission', 'everest-forms' ),
348 );
349 break;
350 case 'everest-forms-survey-polls-quiz-script':
351 $params = array(
352 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),
353 'ajax_nonce' => wp_create_nonce( 'process-ajax-nonce' ),
354 'form_id' => isset( $_GET['form_id'] ) ? wp_unslash( $_GET['form_id'] ) : '', //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
355 );
356 break;
357 default:
358 $params = false;
359 }
360
361 return apply_filters( 'everest_forms_get_script_data', $params, $handle );
362 }
363
364 /**
365 * Localize scripts only when enqueued.
366 */
367 public static function localize_printed_scripts() {
368 foreach ( self::$scripts as $handle ) {
369 self::localize_script( $handle );
370 }
371 }
372 }
373
374 EVF_Frontend_Scripts::init();
375