PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.6.0
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.6.0
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
Helpers 1 year ago Integrations 2 days ago RestApi 2 days ago abilities 2 months ago abstracts 1 month ago admin 2 days ago blocks 1 year ago elementor 2 years ago export 3 months ago fields 1 week ago interfaces 8 years ago libraries 2 years ago log-handlers 1 year ago shortcodes 2 days ago stats 6 months ago templates 4 months ago traits 2 months ago class-everest-forms.php 2 days ago class-evf-addon-upsell.php 2 months ago class-evf-ajax.php 2 days 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 3 months 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-email-entries-report.php 4 months ago class-evf-emails.php 2 months ago class-evf-fields.php 2 months ago class-evf-form-handler.php 2 days ago class-evf-form-task.php 2 months ago class-evf-forms-features.php 2 months ago class-evf-frontend-scripts.php 2 days ago class-evf-install.php 3 months ago class-evf-integrations.php 4 months ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 1 year ago class-evf-privacy.php 6 years ago class-evf-report-cron.php 3 months ago class-evf-reporting.php 3 months ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 1 year ago class-evf-smart-tags.php 2 days ago class-evf-template-loader.php 2 days ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 2 months ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 5 months 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
397 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 $general_css_path = plugin_dir_path( EVF_PLUGIN_FILE ) . 'assets/css/everest-forms.css';
54 $general_version = is_readable( $general_css_path ) ? (string) filemtime( $general_css_path ) : EVF_VERSION;
55
56 return apply_filters(
57 'everest_forms_enqueue_styles',
58 array(
59 'everest-forms-general' => array(
60 'src' => self::get_asset_url( 'assets/css/everest-forms.css' ),
61 'deps' => '',
62 'version' => $general_version,
63 'media' => 'all',
64 'has_rtl' => true,
65 ),
66 'jquery-intl-tel-input' => array(
67 'src' => self::get_asset_url( 'assets/css/intlTelInput/intlTelInput.css' ),
68 'deps' => array(),
69 'version' => EVF_VERSION,
70 'media' => 'all',
71 'has_rtl' => false,
72 ),
73 )
74 );
75 }
76
77 /**
78 * Return asset URL.
79 *
80 * @param string $path Assets path.
81 *
82 * @return string
83 */
84 private static function get_asset_url( $path ) {
85 return apply_filters( 'everest_forms_get_asset_url', plugins_url( $path, EVF_PLUGIN_FILE ), $path );
86 }
87
88 /**
89 * Register a script for use.
90 *
91 * @uses wp_register_script()
92 * @param string $handle Name of the script. Should be unique.
93 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
94 * @param string[] $deps An array of registered script handles this script depends on.
95 * @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.
96 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
97 */
98 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
99 self::$scripts[] = $handle;
100 wp_register_script( $handle, $path, $deps, $version, $in_footer );
101 }
102
103 /**
104 * Register and enqueue a script for use.
105 *
106 * @uses wp_enqueue_script()
107 * @param string $handle Name of the script. Should be unique.
108 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
109 * @param string[] $deps An array of registered script handles this script depends on.
110 * @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.
111 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
112 */
113 private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
114 if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
115 self::register_script( $handle, $path, $deps, $version, $in_footer );
116 }
117 wp_enqueue_script( $handle );
118 }
119
120 /**
121 * Register a style for use.
122 *
123 * @uses wp_register_style()
124 * @param string $handle Name of the stylesheet. Should be unique.
125 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
126 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
127 * @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.
128 * @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)'.
129 * @param boolean $has_rtl If has RTL version to load too.
130 */
131 private static function register_style( $handle, $path, $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
132 self::$styles[] = $handle;
133 wp_register_style( $handle, $path, $deps, $version, $media );
134
135 if ( $has_rtl ) {
136 wp_style_add_data( $handle, 'rtl', 'replace' );
137 }
138 }
139
140 /**
141 * Register and enqueue a styles for use.
142 *
143 * @uses wp_enqueue_style()
144 * @param string $handle Name of the stylesheet. Should be unique.
145 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
146 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
147 * @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.
148 * @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)'.
149 * @param boolean $has_rtl If has RTL version to load too.
150 */
151 private static function enqueue_style( $handle, $path = '', $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
152 if ( ! in_array( $handle, self::$styles, true ) && $path ) {
153 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
154 }
155 wp_enqueue_style( $handle );
156 }
157
158 /**
159 * Register all EVF scripts.
160 */
161 private static function register_scripts() {
162 if ( evf_is_amp() ) {
163 return;
164 }
165
166 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
167 $ajax_submission_path = plugin_dir_path( EVF_PLUGIN_FILE ) . 'assets/js/frontend/ajax-submission' . $suffix . '.js';
168 $ajax_submission_ver = is_readable( $ajax_submission_path ) ? (string) filemtime( $ajax_submission_path ) : EVF_VERSION;
169 $everest_forms_path = plugin_dir_path( EVF_PLUGIN_FILE ) . 'assets/js/frontend/everest-forms' . $suffix . '.js';
170 $everest_forms_ver = is_readable( $everest_forms_path ) ? (string) filemtime( $everest_forms_path ) : EVF_VERSION;
171 $register_scripts = array(
172 'inputmask' => array(
173 'src' => self::get_asset_url( 'assets/js/inputmask/jquery.inputmask.bundle' . $suffix . '.js' ),
174 'deps' => array( 'jquery' ),
175 'version' => '4.0.0-beta.58',
176 ),
177 'flatpickr' => array(
178 'src' => self::get_asset_url( 'assets/js/flatpickr/flatpickr' . $suffix . '.js' ),
179 'deps' => array( 'jquery' ),
180 'version' => '4.6.3',
181 ),
182 'mailcheck' => array(
183 'src' => self::get_asset_url( 'assets/js/mailcheck/mailcheck' . $suffix . '.js' ),
184 'deps' => array( 'jquery' ),
185 'version' => '1.1.2',
186 ),
187 'selectWoo' => array(
188 'src' => self::get_asset_url( 'assets/js/selectWoo/selectWoo.full' . $suffix . '.js' ),
189 'deps' => array( 'jquery' ),
190 'version' => '1.0.8',
191 ),
192 'jquery-intl-tel-input' => array(
193 'src' => self::get_asset_url( '/assets/js/intlTelInput/jquery.intlTelInput' . $suffix . '.js' ),
194 'deps' => array( 'jquery' ),
195 'version' => '16.0.7',
196 ),
197 'jquery-validate' => array(
198 'src' => self::get_asset_url( 'assets/js/jquery-validate/jquery.validate' . $suffix . '.js' ),
199 'deps' => array( 'jquery' ),
200 'version' => '1.21.0',
201 ),
202 'everest-forms' => array(
203 'src' => self::get_asset_url( 'assets/js/frontend/everest-forms' . $suffix . '.js' ),
204 'deps' => array( 'jquery', 'inputmask', 'jquery-validate', 'jquery-intl-tel-input', 'selectWoo' ),
205 'version' => $everest_forms_ver,
206 ),
207 'everest-forms-text-limit' => array(
208 'src' => self::get_asset_url( 'assets/js/frontend/text-limit' . $suffix . '.js' ),
209 'deps' => array(),
210 'version' => EVF_VERSION,
211 ),
212 'everest-forms-ajax-submission' => array(
213 'src' => self::get_asset_url( 'assets/js/frontend/ajax-submission' . $suffix . '.js' ),
214 'deps' => array( 'jquery', 'inputmask', 'jquery-validate' ),
215 'version' => $ajax_submission_ver,
216 ),
217 'everest-forms-survey-polls-quiz-script' => array(
218 'src' => self::get_asset_url( 'assets/js/frontend/everest-forms-survey-polls-quiz' . $suffix . '.js' ),
219 'deps' => array(),
220 'version' => EVF_VERSION,
221 ),
222 );
223
224 foreach ( $register_scripts as $name => $props ) {
225
226 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
227 }
228 }
229
230 /**
231 * Register all EVF sty;es.
232 */
233 private static function register_styles() {
234 $register_styles = array(
235 'evf_select2' => array(
236 'src' => self::get_asset_url( 'assets/css/select2.css' ),
237 'deps' => array(),
238 'version' => EVF_VERSION,
239 'has_rtl' => false,
240 ),
241 'flatpickr' => array(
242 'src' => self::get_asset_url( 'assets/css/flatpickr.css' ),
243 'deps' => array(),
244 'version' => EVF_VERSION,
245 'has_rtl' => false,
246 ),
247 'jquery-intl-tel-input' => array(
248 'src' => self::get_asset_url( 'assets/css/intlTelInput.css' ),
249 'deps' => array(),
250 'version' => EVF_VERSION,
251 'has_rtl' => false,
252 ),
253 );
254 foreach ( $register_styles as $name => $props ) {
255 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
256 }
257 }
258
259 /**
260 * Register/queue frontend scripts.
261 */
262 public static function load_scripts() {
263 global $post;
264
265 if ( ! did_action( 'before_everest_forms_init' ) ) {
266 return;
267 }
268
269 self::register_scripts();
270 self::register_styles();
271
272 // Enqueue dashicons.
273 wp_enqueue_style( 'dashicons' );
274
275 // CSS Styles.
276 $enqueue_styles = self::get_styles();
277 if ( $enqueue_styles ) {
278 foreach ( $enqueue_styles as $handle => $args ) {
279 if ( ! isset( $args['has_rtl'] ) ) {
280 $args['has_rtl'] = false;
281 }
282
283 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
284 }
285 }
286 }
287
288 /**
289 * Whether payment debug logging is enabled for the current request.
290 *
291 * @return bool
292 */
293 private static function is_payment_debug_enabled() {
294 return current_user_can( 'manage_options' );
295 }
296
297 /**
298 * Localize a EVF script once.
299 *
300 * @param string $handle Script handle the data will be attached to.
301 */
302 private static function localize_script( $handle ) {
303 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
304 $data = self::get_script_data( $handle );
305
306 if ( ! $data ) {
307 return;
308 }
309
310 $name = str_replace( '-', '_', $handle ) . '_params';
311 self::$wp_localize_scripts[] = $handle;
312 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
313 }
314 }
315
316 /**
317 * Return data for script handles.
318 *
319 * @param string $handle Script handle the data will be attached to.
320 * @return array|bool
321 */
322 private static function get_script_data( $handle ) {
323 switch ( $handle ) {
324 case 'everest-forms':
325 $params = array(
326 'ajax_url' => evf()->ajax_url(),
327 'submit' => esc_html__( 'Submit', 'everest-forms' ),
328 'disable_user_details' => get_option( 'everest_forms_disable_user_details' ),
329 'everest_forms_data_save' => wp_create_nonce( 'everest_forms_data_save_nonce' ),
330 'everest_forms_slot_booking' => wp_create_nonce( 'everest_forms_slot_booking_nonce' ),
331 'i18n_messages_required' => esc_html( get_option( 'everest_forms_required_validation' ) ),
332 'i18n_messages_url' => esc_html( get_option( 'everest_forms_url_validation' ) ),
333 'i18n_messages_email' => esc_html( get_option( 'everest_forms_email_validation' ) ),
334 'i18n_messages_email_suggestion' => esc_html( get_option( 'everest_forms_email_suggestion', __( 'Did you mean {suggestion}?', 'everest-forms' ) ) ),
335 'i18n_messages_email_suggestion_title' => esc_attr__( 'Click to accept this suggestion.', 'everest-forms' ),
336 'i18n_messages_confirm' => esc_html( get_option( 'everest_forms_confirm_validation', __( 'Field values do not match.', 'everest-forms' ) ) ),
337 'i18n_messages_check_limit' => esc_html( get_option( 'everest_forms_check_limit_validation', __( 'You have exceeded number of allowed selections: {#}.', 'everest-forms' ) ) ),
338 'i18n_messages_number' => esc_html( get_option( 'everest_forms_number_validation' ) ),
339 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'everest-forms' ),
340 'mailcheck_enabled' => (bool) apply_filters( 'everest_forms_mailcheck_enabled', true ),
341 'mailcheck_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_domains', array() ) ),
342 'mailcheck_toplevel_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_toplevel_domains', array( 'dev' ) ) ),
343 'il8n_min_word_length_err_msg' => esc_html__( 'Please enter at least {0} words.', 'everest-forms' ),
344 'il8n_min_character_length_err_msg' => esc_html__( 'Please enter at least {0} characters.', 'everest-forms' ),
345 'plugin_url' => plugin_dir_url( EVF_PLUGIN_FILE ),
346 'i18n_messages_phone' => esc_html( get_option( 'everest_forms_phone_validation', __( 'Please enter a valid phone number.', 'everest-forms' ) ) ),
347 'evf_smart_phone_allowed_countries' => apply_filters( 'everest_forms_smart_phone_allowed_countries', array() ),
348 'i18n_field_rating_greater_than_max_value_error' => esc_html__( 'Please enter in a value less than 100.', 'everest-forms' ),
349 'evf_checked_image_url' => esc_url( self::get_asset_url( 'assets/images/evf-checked.png' ) ),
350 'i18n_evf_success_text' => esc_html__( 'Success!', 'everest-forms' ),
351 );
352 break;
353 case 'everest-forms-text-limit':
354 $params = array(
355 'i18n_messages_limit_characters' => esc_html__( '{count} of {limit} max characters.', 'everest-forms' ),
356 'i18n_messages_limit_words' => esc_html__( '{count} of {limit} max words.', 'everest-forms' ),
357 );
358 break;
359 case 'everest-forms-ajax-submission':
360 $params = array(
361 'ajax_url' => admin_url( 'admin-ajax.php' ),
362 'evf_ajax_submission' => wp_create_nonce( 'everest_forms_ajax_form_submission' ),
363 'submit' => esc_html__( 'Submit', 'everest-forms' ),
364 'error' => esc_html__( 'Something went wrong while making an AJAX submission', 'everest-forms' ),
365 'required' => esc_html__( 'This field is required.', 'everest-forms' ),
366 'pdf_download' => esc_html__( 'Click here to download your pdf submission', 'everest-forms' ),
367 'evf_checked_image_url' => esc_url( self::get_asset_url( 'assets/images/evf-checked.png' ) ),
368 'i18n_evf_success_text' => esc_html__( 'Success!', 'everest-forms' ),
369 'payment_debug' => self::is_payment_debug_enabled() ? '1' : '0',
370 );
371 break;
372 case 'everest-forms-survey-polls-quiz-script':
373 $params = array(
374 'ajax_url' => admin_url( 'admin-ajax.php', 'relative' ),
375 'ajax_nonce' => wp_create_nonce( 'process-ajax-nonce' ),
376 'form_id' => isset( $_GET['form_id'] ) ? wp_unslash( $_GET['form_id'] ) : '', //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.NonceVerification.Recommended
377 );
378 break;
379 default:
380 $params = false;
381 }
382
383 return apply_filters( 'everest_forms_get_script_data', $params, $handle );
384 }
385
386 /**
387 * Localize scripts only when enqueued.
388 */
389 public static function localize_printed_scripts() {
390 foreach ( self::$scripts as $handle ) {
391 self::localize_script( $handle );
392 }
393 }
394 }
395
396 EVF_Frontend_Scripts::init();
397