PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.6.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.6.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
abstracts 6 years ago admin 6 years ago export 6 years ago fields 6 years ago interfaces 8 years ago libraries 7 years ago log-handlers 6 years ago shortcodes 6 years ago templates 6 years ago class-everest-forms.php 6 years ago class-evf-ajax.php 6 years ago class-evf-autoloader.php 7 years ago class-evf-background-updater.php 7 years ago class-evf-cache-helper.php 6 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 7 years ago class-evf-emails.php 6 years ago class-evf-fields.php 6 years ago class-evf-form-block.php 6 years ago class-evf-form-handler.php 6 years ago class-evf-form-task.php 6 years ago class-evf-forms-features.php 6 years ago class-evf-frontend-scripts.php 6 years ago class-evf-install.php 6 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 6 years ago class-evf-post-types.php 6 years ago class-evf-privacy.php 6 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 7 years ago class-evf-smart-tags.php 6 years ago class-evf-template-loader.php 6 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 6 years ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 6 years ago evf-formatting-functions.php 6 years ago evf-notice-functions.php 6 years ago evf-template-functions.php 6 years ago evf-template-hooks.php 7 years ago evf-update-functions.php 6 years ago
class-evf-frontend-scripts.php
326 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 )
64 );
65 }
66
67 /**
68 * Return asset URL.
69 *
70 * @param string $path Assets path.
71 *
72 * @return string
73 */
74 private static function get_asset_url( $path ) {
75 return apply_filters( 'everest_forms_get_asset_url', plugins_url( $path, EVF_PLUGIN_FILE ), $path );
76 }
77
78 /**
79 * Register a script for use.
80 *
81 * @uses wp_register_script()
82 * @param string $handle Name of the script. Should be unique.
83 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
84 * @param string[] $deps An array of registered script handles this script depends on.
85 * @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.
86 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
87 */
88 private static function register_script( $handle, $path, $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
89 self::$scripts[] = $handle;
90 wp_register_script( $handle, $path, $deps, $version, $in_footer );
91 }
92
93 /**
94 * Register and enqueue a script for use.
95 *
96 * @uses wp_enqueue_script()
97 * @param string $handle Name of the script. Should be unique.
98 * @param string $path Full URL of the script, or path of the script relative to the WordPress root directory.
99 * @param string[] $deps An array of registered script handles this script depends on.
100 * @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.
101 * @param boolean $in_footer Whether to enqueue the script before </body> instead of in the <head>. Default 'false'.
102 */
103 private static function enqueue_script( $handle, $path = '', $deps = array( 'jquery' ), $version = EVF_VERSION, $in_footer = true ) {
104 if ( ! in_array( $handle, self::$scripts, true ) && $path ) {
105 self::register_script( $handle, $path, $deps, $version, $in_footer );
106 }
107 wp_enqueue_script( $handle );
108 }
109
110 /**
111 * Register a style for use.
112 *
113 * @uses wp_register_style()
114 * @param string $handle Name of the stylesheet. Should be unique.
115 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
116 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
117 * @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.
118 * @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)'.
119 * @param boolean $has_rtl If has RTL version to load too.
120 */
121 private static function register_style( $handle, $path, $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
122 self::$styles[] = $handle;
123 wp_register_style( $handle, $path, $deps, $version, $media );
124
125 if ( $has_rtl ) {
126 wp_style_add_data( $handle, 'rtl', 'replace' );
127 }
128 }
129
130 /**
131 * Register and enqueue a styles for use.
132 *
133 * @uses wp_enqueue_style()
134 * @param string $handle Name of the stylesheet. Should be unique.
135 * @param string $path Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
136 * @param string[] $deps An array of registered stylesheet handles this stylesheet depends on.
137 * @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.
138 * @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)'.
139 * @param boolean $has_rtl If has RTL version to load too.
140 */
141 private static function enqueue_style( $handle, $path = '', $deps = array(), $version = EVF_VERSION, $media = 'all', $has_rtl = false ) {
142 if ( ! in_array( $handle, self::$styles, true ) && $path ) {
143 self::register_style( $handle, $path, $deps, $version, $media, $has_rtl );
144 }
145 wp_enqueue_style( $handle );
146 }
147
148 /**
149 * Register all EVF scripts.
150 */
151 private static function register_scripts() {
152 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
153 $register_scripts = array(
154 'inputmask' => array(
155 'src' => self::get_asset_url( 'assets/js/inputmask/jquery.inputmask.bundle' . $suffix . '.js' ),
156 'deps' => array( 'jquery' ),
157 'version' => '4.0.0-beta.58',
158 ),
159 'flatpickr' => array(
160 'src' => self::get_asset_url( 'assets/js/flatpickr/flatpickr' . $suffix . '.js' ),
161 'deps' => array( 'jquery' ),
162 'version' => '4.5.1',
163 ),
164 'mailcheck' => array(
165 'src' => self::get_asset_url( 'assets/js/mailcheck/mailcheck' . $suffix . '.js' ),
166 'deps' => array( 'jquery' ),
167 'version' => '1.1.2',
168 ),
169 'jquery-validate' => array(
170 'src' => self::get_asset_url( 'assets/js/jquery-validate/jquery.validate' . $suffix . '.js' ),
171 'deps' => array( 'jquery' ),
172 'version' => '1.17.0',
173 ),
174 'everest-forms' => array(
175 'src' => self::get_asset_url( 'assets/js/frontend/everest-forms' . $suffix . '.js' ),
176 'deps' => array( 'jquery', 'inputmask', 'jquery-validate' ),
177 'version' => EVF_VERSION,
178 ),
179 'everest-forms-text-limit' => array(
180 'src' => self::get_asset_url( 'assets/js/frontend/text-limit' . $suffix . '.js' ),
181 'deps' => array(),
182 'version' => EVF_VERSION,
183 ),
184 'everest-forms-ajax-submission' => array(
185 'src' => self::get_asset_url( 'assets/js/frontend/ajax-submission' . $suffix . '.js' ),
186 'deps' => array( 'jquery', 'inputmask', 'jquery-validate' ),
187 'version' => EVF_VERSION,
188 ),
189 );
190 foreach ( $register_scripts as $name => $props ) {
191 self::register_script( $name, $props['src'], $props['deps'], $props['version'] );
192 }
193 }
194
195 /**
196 * Register all EVF sty;es.
197 */
198 private static function register_styles() {
199 $register_styles = array(
200 'select2' => array(
201 'src' => self::get_asset_url( 'assets/css/select2.css' ),
202 'deps' => array(),
203 'version' => EVF_VERSION,
204 'has_rtl' => false,
205 ),
206 'flatpickr' => array(
207 'src' => self::get_asset_url( 'assets/css/flatpickr.css' ),
208 'deps' => array(),
209 'version' => EVF_VERSION,
210 'has_rtl' => false,
211 ),
212 );
213 foreach ( $register_styles as $name => $props ) {
214 self::register_style( $name, $props['src'], $props['deps'], $props['version'], 'all', $props['has_rtl'] );
215 }
216 }
217
218 /**
219 * Register/queue frontend scripts.
220 */
221 public static function load_scripts() {
222 global $post;
223
224 if ( ! did_action( 'before_everest_forms_init' ) ) {
225 return;
226 }
227
228 self::register_scripts();
229 self::register_styles();
230
231 // Enqueue dashicons.
232 wp_enqueue_style( 'dashicons' );
233
234 // CSS Styles.
235 $enqueue_styles = self::get_styles();
236 if ( $enqueue_styles ) {
237 foreach ( $enqueue_styles as $handle => $args ) {
238 if ( ! isset( $args['has_rtl'] ) ) {
239 $args['has_rtl'] = false;
240 }
241
242 self::enqueue_style( $handle, $args['src'], $args['deps'], $args['version'], $args['media'], $args['has_rtl'] );
243 }
244 }
245 }
246
247 /**
248 * Localize a EVF script once.
249 *
250 * @param string $handle Script handle the data will be attached to.
251 */
252 private static function localize_script( $handle ) {
253 if ( ! in_array( $handle, self::$wp_localize_scripts, true ) && wp_script_is( $handle ) ) {
254 $data = self::get_script_data( $handle );
255
256 if ( ! $data ) {
257 return;
258 }
259
260 $name = str_replace( '-', '_', $handle ) . '_params';
261 self::$wp_localize_scripts[] = $handle;
262 wp_localize_script( $handle, $name, apply_filters( $name, $data ) );
263 }
264 }
265
266 /**
267 * Return data for script handles.
268 *
269 * @param string $handle Script handle the data will be attached to.
270 * @return array|bool
271 */
272 private static function get_script_data( $handle ) {
273 switch ( $handle ) {
274 case 'everest-forms':
275 $params = array(
276 'ajax_url' => evf()->ajax_url(),
277 'submit' => esc_html__( 'Submit', 'everest-forms' ),
278 'disable_user_details' => get_option( 'everest_forms_disable_user_details' ),
279 'everest_forms_data_save' => wp_create_nonce( 'everest_forms_data_save_nonce' ),
280 'i18n_messages_required' => get_option( 'everest_forms_required_validation' ),
281 'i18n_messages_url' => get_option( 'everest_forms_url_validation' ),
282 'i18n_messages_email' => get_option( 'everest_forms_email_validation' ),
283 'i18n_messages_email_suggestion' => get_option( 'everest_forms_email_suggestion', esc_html__( 'Did you mean {suggestion}?', 'everest-forms' ) ),
284 'i18n_messages_email_suggestion_title' => esc_attr__( 'Click to accept this suggestion.', 'everest-forms' ),
285 'i18n_messages_confirm' => get_option( 'everest_forms_confirm_validation', __( 'Field values do not match.', 'everest-forms' ) ),
286 'i18n_messages_check_limit' => get_option( 'everest_forms_check_limit_validation', esc_html__( 'You have exceeded number of allowed selections: {#}.', 'everest-forms' ) ),
287 'i18n_messages_number' => get_option( 'everest_forms_number_validation' ),
288 'mailcheck_enabled' => (bool) apply_filters( 'everest_forms_mailcheck_enabled', true ),
289 'mailcheck_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_domains', array() ) ),
290 'mailcheck_toplevel_domains' => array_map( 'sanitize_text_field', (array) apply_filters( 'everest_forms_mailcheck_toplevel_domains', array( 'dev' ) ) ),
291 );
292 break;
293 case 'everest-forms-text-limit':
294 $params = array(
295 'i18n_messages_limit_characters' => esc_html__( '{count} of {limit} max characters.', 'everest-forms' ),
296 'i18n_messages_limit_words' => esc_html__( '{count} of {limit} max words.', 'everest-forms' ),
297 );
298 break;
299 case 'everest-forms-ajax-submission':
300 $params = array(
301 'ajax_url' => admin_url( 'admin-ajax.php' ),
302 'evf_ajax_submission' => wp_create_nonce( 'everest_forms_ajax_form_submission' ),
303 'submit' => esc_html__( 'Submit', 'everest-forms' ),
304 'error' => esc_html__( 'Sorry, something went wrong. Please try again', 'everest-forms' ),
305 'required' => esc_html__( 'This field is required.', 'everest-forms' ),
306 );
307 break;
308 default:
309 $params = false;
310 }
311
312 return apply_filters( 'everest_forms_get_script_data', $params, $handle );
313 }
314
315 /**
316 * Localize scripts only when enqueued.
317 */
318 public static function localize_printed_scripts() {
319 foreach ( self::$scripts as $handle ) {
320 self::localize_script( $handle );
321 }
322 }
323 }
324
325 EVF_Frontend_Scripts::init();
326