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-ajax.php
everest-forms / includes Last commit date
Helpers 1 year ago Integrations 3 days ago RestApi 3 days ago abilities 2 months ago abstracts 1 month ago admin 3 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 3 days ago stats 6 months ago templates 4 months ago traits 2 months ago class-everest-forms.php 3 days ago class-evf-addon-upsell.php 2 months ago class-evf-ajax.php 3 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 3 days ago class-evf-form-task.php 2 months ago class-evf-forms-features.php 2 months ago class-evf-frontend-scripts.php 3 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 3 days ago class-evf-template-loader.php 3 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-ajax.php
2369 lines
1 <?php
2
3 /**
4 * EverestForms EVF_AJAX. AJAX Event Handlers.
5 *
6 * @class EVF_AJAX
7 * @package EverestForms/Classes
8 */
9
10 use EverestForms\Helpers\FormHelper;
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * EVF_AJAX class.
16 */
17 class EVF_AJAX {
18
19
20 /**
21 * Background update class.
22 *
23 * @var object
24 */
25 private static $background_process;
26
27 /**
28 * Hook in ajax handlers.
29 */
30 public static function init() {
31 add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
32 add_action( 'template_redirect', array( __CLASS__, 'do_evf_ajax' ), 0 );
33 self::add_ajax_events();
34 add_action( 'init', array( __CLASS__, 'init_background_process' ), 5 );
35 }
36
37 /**
38 * Init background process.
39 */
40 public static function init_background_process() {
41 include_once EVF_ABSPATH . 'includes/class-evf-background-process-import-entries.php';
42
43 self::$background_process = new \EVF_Background_Process_Import_Entries();
44 }
45
46 /**
47 * Set EVF AJAX constant and headers.
48 */
49 public static function define_ajax() { // @codingStandardsIgnoreStart
50 if (! empty($_GET['evf-ajax'])) {
51 evf_maybe_define_constant('DOING_AJAX', true);
52 evf_maybe_define_constant('EVF_DOING_AJAX', true);
53 if (! WP_DEBUG || (WP_DEBUG && ! WP_DEBUG_DISPLAY)) {
54 @ini_set('display_errors', 0); // Turn off display_errors during AJAX events to prevent malformed JSON.
55 }
56 $GLOBALS['wpdb']->hide_errors();
57 }
58 // @codingStandardsIgnoreEnd
59 }
60
61 /**
62 * Send headers for EVF Ajax Requests.
63 *
64 * @since 1.0.0
65 */
66 private static function evf_ajax_headers() {
67 if ( ! headers_sent() ) {
68 send_origin_headers();
69 send_nosniff_header();
70 evf_nocache_headers();
71 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
72 header( 'X-Robots-Tag: noindex' );
73 status_header( 200 );
74 } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
75 headers_sent( $file, $line );
76 trigger_error("evf_ajax_headers cannot set headers - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine
77 }
78 }
79
80 /**
81 * Check for EVF Ajax request and fire action.
82 */
83 public static function do_evf_ajax() {
84 global $wp_query;
85
86 if ( ! empty( $_GET['evf-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
87 $wp_query->set( 'evf-ajax', sanitize_text_field( wp_unslash( $_GET['evf-ajax'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
88 }
89
90 $action = $wp_query->get( 'evf-ajax' );
91
92 if ( $action ) {
93 self::evf_ajax_headers();
94 $action = sanitize_text_field( $action );
95 do_action( 'evf_ajax_' . $action );
96 wp_die();
97 }
98 }
99
100 /**
101 * Hook in methods - uses WordPress ajax handlers (admin-ajax).
102 */
103 public static function add_ajax_events() {
104 $ajax_events = array(
105 'save_form' => false,
106 'create_form' => false,
107 'get_next_id' => false,
108 'install_extension' => false,
109 'integration_connect' => false,
110 'new_email_add' => false,
111 'integration_disconnect' => false,
112 'rated' => false,
113 'review_dismiss' => false,
114 'survey_dismiss' => false,
115 'allow_usage_dismiss' => false,
116 'php_notice_dismiss' => false,
117 'email_failed_notice_dismiss' => false,
118 'enabled_form' => false,
119 'import_form_action' => false,
120 'template_licence_check' => false,
121 'template_activate_addon' => false,
122 'ajax_form_submission' => true,
123 'send_test_email' => false,
124 'locate_form_action' => false,
125 'slot_booking' => true,
126 'active_addons' => false,
127 'get_local_font_url' => false,
128 'form_migrator_forms_list' => false,
129 'form_migrator' => false,
130 'fm_dismiss_notice' => false,
131 'email_duplicate' => false,
132 'form_entry_migrator' => false,
133 'embed_form' => false,
134 'goto_edit_page' => false,
135 'send_routine_report_test_email' => false,
136 'send_manual_report' => false,
137 'map_csv' => false,
138 'import_entries' => false,
139 'generate_restapi_key' => false,
140 'install_and_activate_smart_smtp' => false,
141 'form_preview_save' => false,
142 'delete_form_tags' => false,
143 'update_tags_in_bulk' => false,
144 'save_clean_talk_settings' => true,
145 'get_form_update_nonce' => true,
146 );
147
148 foreach ( $ajax_events as $ajax_event => $nopriv ) {
149 add_action( 'wp_ajax_everest_forms_' . $ajax_event, array( __CLASS__, $ajax_event ) );
150
151 if ( $nopriv ) {
152 add_action( 'wp_ajax_nopriv_everest_forms_' . $ajax_event, array( __CLASS__, $ajax_event ) );
153
154 // EVF AJAX can be used for frontend ajax requests.
155 add_action( 'evf_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
156 }
157 }
158 }
159
160 /**
161 * Ajax handler to get next form ID.
162 */
163 public static function get_next_id() {
164 // Run a security check.
165 check_ajax_referer( 'everest_forms_get_next_id', 'security' );
166
167 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
168 if ( $form_id < 1 ) {
169 wp_send_json_error(
170 array(
171 'error' => esc_html__( 'Invalid form', 'everest-forms' ),
172 )
173 );
174 }
175
176 // Check permisssions.
177 if ( ! current_user_can( 'everest_forms_edit_form', $form_id ) ) {
178 wp_send_json_error();
179 }
180
181 if ( isset( $_POST['fields'] ) ) {
182 $fields_data = array();
183 for ( $i = 0; $i < $_POST['fields']; $i++ ) {
184 $field_key = evf()->form->field_unique_key( $form_id );
185 $field_id_array = explode( '-', $field_key );
186 $new_field_id = ( $field_id_array[ count( $field_id_array ) - 1 ] + 1 );
187 $fields_data[] = array(
188 'field_id' => $new_field_id,
189 'field_key' => $field_key,
190 );
191 }
192 wp_send_json_success(
193 $fields_data
194 );
195 } else {
196 $field_key = evf()->form->field_unique_key( $form_id );
197 $field_id_array = explode( '-', $field_key );
198 $new_field_id = ( $field_id_array[ count( $field_id_array ) - 1 ] + 1 );
199 wp_send_json_success(
200 array(
201 'field_id' => $new_field_id,
202 'field_key' => $field_key,
203 )
204 );
205 }
206 }
207
208 /**
209 * AJAX create new form.
210 */
211 public static function create_form() {
212 ob_start();
213
214 check_ajax_referer( 'everest_forms_create_form', 'security' );
215
216 // Check permissions.
217 if ( ! current_user_can( 'everest_forms_create_forms' ) ) {
218 wp_die( -1 );
219 }
220
221 $title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : esc_html__( 'Blank Form', 'everest-forms' );
222 $template = isset( $_POST['template'] ) ? sanitize_text_field( wp_unslash( $_POST['template'] ) ) : 'blank';
223
224 $form_id = evf()->form->create( $title, $template );
225
226 if ( $form_id ) {
227 $data = array(
228 'id' => $form_id,
229 'redirect' => add_query_arg(
230 array(
231 'tab' => 'fields',
232 'form_id' => $form_id,
233 ),
234 admin_url( 'admin.php?page=evf-builder' )
235 ),
236 );
237
238 wp_send_json_success( $data );
239 }
240
241 wp_send_json_error(
242 array(
243 'error' => esc_html__( 'Something went wrong, please try again later', 'everest-forms' ),
244 )
245 );
246 }
247
248 /**
249 * AJAX Form save.
250 */
251 public static function save_form() {
252 check_ajax_referer( 'everest_forms_save_form', 'security' );
253
254 $logger = evf_get_logger();
255
256 // Check permissions.
257 $logger->info(
258 __( 'Checking permissions.', 'everest-forms' ),
259 array( 'source' => 'form-save' )
260 );
261 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
262 $logger->critical(
263 __( 'You do not have permission.', 'everest-forms' ),
264 array( 'source' => 'form-save' )
265 );
266 die( esc_html__( 'You do not have permission.', 'everest-forms' ) );
267 }
268
269 // Check for form data.
270 $logger->info(
271 __( 'Checking for form data.', 'everest-forms' ),
272 array( 'source' => 'form-save' )
273 );
274 if ( empty( $_POST['form_data'] ) ) {
275 $logger->critical(
276 __( 'No data provided.', 'everest-forms' ),
277 array( 'source' => 'form-save' )
278 );
279 die( esc_html__( 'No data provided', 'everest-forms' ) );
280 }
281
282 $form_post = evf_sanitize_builder( json_decode( wp_unslash( $_POST['form_data'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
283
284 $data = array();
285
286 if ( ! is_null( $form_post ) && $form_post ) {
287 foreach ( $form_post as $post_index => $post_input_data ) {
288 // For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
289 // derive the array path keys via regex and set the value in $_POST.
290 preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
291
292 $array_bits = array( $matches[1] );
293
294 if ( isset( $matches[3] ) ) {
295 $array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) );
296 }
297
298 $new_post_data = array();
299
300 // Build the new array value from leaf to trunk.
301 for ( $i = count( $array_bits ) - 1; $i >= 0; $i-- ) {
302 if ( count( $array_bits ) - 1 === $i ) {
303 if ( '' === $array_bits[ $i ] ) {
304 $new_post_data[ $post_index ] = wp_slash( $post_input_data->value );
305 } else {
306 $new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
307 }
308 } else {
309 $new_post_data = array(
310 $array_bits[ $i ] => $new_post_data,
311 );
312 }
313 }
314 $data = array_replace_recursive( $data, $new_post_data );
315 }
316 }
317
318 $data = apply_filters( 'everest_forms_builder_save_form_data', $data );
319
320 if ( is_array( $data ) ) {
321 // First builder save: form is no longer "fresh"; add-ons can show full/legacy UI if needed.
322 $data['is_new_form'] = false;
323 }
324
325 // Check for empty meta key.
326 $logger->info(
327 __( 'Check for empty meta key.', 'everest-forms' ),
328 array( 'source' => 'form-save' )
329 );
330
331 // Check for empty field label.
332 $logger->info(
333 __( 'Checking if the field label is empty or not.', 'everest-forms' ),
334 array( 'source' => 'form-save' )
335 );
336
337 $empty_meta_data = array();
338 $list_of_meta_keys = array();
339 $empty_field_label = array();
340
341 // Calculation backward compatibility.
342 $old_calculation_format = 0;
343 $new_calculation_format = 0;
344 $not_supported_operator = 0;
345
346 $check_recurring_period = isset( $data['payments'] ) && isset( $data['payments']['stripe'] ) && isset( $data['payments']['stripe']['interval_count'] )
347 ? ( 0 === $data['payments']['stripe']['interval_count'] || empty(
348 $data['payments']['stripe']['interval_count']
349 ? true
350 : false
351 ) )
352 : false;
353
354 $is_recurring_subscription_enabled = isset( $data['payments'] ) && isset( $data['payments']['stripe'] ) && isset( $data['payments']['stripe']['recurring'] ) && 1 == $data['payments']['stripe']['recurring']
355 ? true
356 : false;
357
358 if ( $is_recurring_subscription_enabled && $check_recurring_period ) {
359 $logger->error(
360 __( 'Recurring period required.', 'everest-forms' ),
361 array( 'source' => 'form-save' )
362 );
363 wp_send_json_error(
364 array(
365 'errorTitle' => esc_html__( 'Recurring period required.', 'everest-forms' ),
366 /* translators: %s: empty meta data */
367 'errorMessage' => esc_html__( 'Recurring Period is required. Please enter a valid value before saving the form.', 'everest-forms' ),
368 )
369 );
370 }
371
372 if ( ! empty( $data['form_fields'] ) ) {
373 foreach ( $data['form_fields'] as $field_key => $field ) {
374 if ( ! empty( $field['label'] ) ) {
375 // Only allow specific html in label.
376 $data['form_fields'][ $field_key ]['label'] = wp_kses(
377 $field['label'],
378 array(
379 'a' => array(
380 'href' => array(),
381 'class' => array(),
382 ),
383 'span' => array(
384 'class' => array(),
385 ),
386 'em' => array(),
387 'small' => array(),
388 'strong' => array(),
389 )
390 );
391
392 // Register string for translation.
393 evf_string_translation( $data['id'], $field['id'], $field['label'] );
394 }
395
396 if ( ! empty( $field['meta-key'] ) ) {
397
398 $sanitized_meta_key = sanitize_key( $field['meta-key'] );
399
400 if ( $sanitized_meta_key !== $field['meta-key'] ) {
401 $logger->error(
402 __( 'Invalid meta-key characters detected.', 'everest-forms' ),
403 array( 'source' => 'form-save' )
404 );
405 wp_send_json_error(
406 array(
407 'errorTitle' => esc_html__( 'Invalid Meta Key', 'everest-forms' ),
408 'errorMessage' => sprintf( esc_html__( 'Meta key for field "%s" contains invalid characters. Only lowercase letters, numbers, hyphens, and underscores are allowed.', 'everest-forms' ), '<strong>' . $field['label'] . '</strong>' ),
409 )
410 );
411 }
412
413 $list_of_meta_keys[] = $sanitized_meta_key;
414
415 $field['meta-key'] = $sanitized_meta_key;
416 }
417 $unique_meta_keys = array_unique( $list_of_meta_keys );
418
419 if ( ! in_array( $field['type'], array( 'html', 'title', 'captcha', 'divider', 'reset', 'recaptcha', 'hcaptcha', 'turnstile' ), true ) && count( $unique_meta_keys ) < count( $list_of_meta_keys ) ) {
420 $logger->error(
421 __( 'Duplicate Meta Key.', 'everest-forms' ),
422 array( 'source' => 'form-save' )
423 );
424 wp_send_json_error(
425 array(
426 'errorTitle' => esc_html__( 'Duplicate Meta Key', 'everest-forms' ),
427 /* translators: %s: empty meta data */
428 'errorMessage' => sprintf( esc_html__( '%s field has duplicate meta_key.', 'everest-forms' ), '<strong>' . $field['label'] . '</strong>' ),
429 )
430 );
431 }
432
433 if ( empty( $field['meta-key'] ) && ! in_array( $field['type'], array( 'html', 'title', 'captcha', 'divider', 'reset', 'recaptcha', 'hcaptcha', 'turnstile', 'payment_summary', 'payment-gateway-selector', 'payment-coupon' ), true ) ) {
434 $empty_meta_data[] = ! empty( $field['label'] ) ? $field['label'] : sprintf( /* translators: %s: field id */ esc_html__( 'Field #%s', 'everest-forms' ), isset( $field['id'] ) ? $field['id'] : '' );
435 }
436
437 if ( empty( $field['label'] ) && ! in_array( $field['type'], array( 'html', 'title', 'captcha', 'divider', 'reset', 'recaptcha', 'hcaptcha', 'turnstile', 'payment_summary', 'payment-gateway-selector', 'payment-coupon' ), true ) ) {
438 $empty_field_label[] = $field['id'];
439 }
440
441 if ( isset( $field['enable_calculation'] ) && ! empty( $field['enable_calculation'] ) ) {
442 if ( isset( $field['calculation_field'] ) && ! empty( $field['calculation_field'] ) ) {
443 $formula = stripslashes( $field['calculation_field'] );
444 $old_formula_pattern = '/\{field_id="([^"]+)"\}/';
445 preg_match_all( $old_formula_pattern, $formula, $matches );
446
447 if ( ! empty( $matches[0] ) ) {
448 ++$old_calculation_format;
449 }
450
451 preg_match_all( '/\^/', $formula, $operator );
452
453 if ( ! empty( $operator[0] ) ) {
454 ++$not_supported_operator;
455 }
456
457 $new_formula_pattern = '/\$FIELD_(\d+)/';
458 preg_match_all( $new_formula_pattern, $formula, $new_matches );
459 if ( ! empty( $new_matches[0] ) ) {
460 ++$new_calculation_format;
461 }
462 }
463 }
464 }
465
466 if ( ! empty( $empty_meta_data ) ) {
467 $logger->error(
468 __( 'Meta Key missing.', 'everest-forms' ),
469 array( 'source' => 'form-save' )
470 );
471 wp_send_json_error(
472 array(
473 'errorTitle' => esc_html__( 'Meta Key missing', 'everest-forms' ),
474 /* translators: %s: empty meta data */
475 'errorMessage' => sprintf( esc_html__( 'Please add Meta key for fields: %s', 'everest-forms' ), '<strong>' . implode( ', ', $empty_meta_data ) . '</strong>' ),
476 )
477 );
478 }
479
480 if ( ! empty( $empty_field_label ) ) {
481 $logger->error(
482 __( 'Empty Field Label.', 'everest-forms' ),
483 array( 'source' => 'form-save' )
484 );
485 wp_send_json_error(
486 array(
487 'errorTitle' => esc_html__( 'Empty Field Label.', 'everest-forms' ),
488 /* translators: %s: empty field label */
489 'errorMessage' => sprintf( wp_kses_post( __( 'Please add label for fields: %s.<br>To hide the field please Enable Hide Label option from Advanced Options > Hide Label', 'everest-forms' ) ), '<strong>' . implode( ', ', $empty_field_label ) . '</strong>' ),
490 )
491 );
492 }
493
494 if ( ! empty( $old_calculation_format ) && ! empty( $new_calculation_format ) ) {
495 $logger->error(
496 __( 'Formula update error.', 'everest-forms' ),
497 array( 'source' => 'form-save' )
498 );
499 wp_send_json_error(
500 array(
501 'errorTitle' => esc_html__( 'Heads Up!', 'everest-forms' ),
502 /* translators: %s: empty meta data */
503 'errorMessage' => sprintf( esc_html__( 'Seems like your formula is not up to date. We suggest you update your formula.', 'everest-forms' ) ),
504 )
505 );
506 }
507
508 if ( ! empty( $not_supported_operator ) && ! empty( $new_calculation_format ) ) {
509 $logger->error(
510 __( 'Not supported operator.', 'everest-forms' ),
511 array( 'source' => 'form-save' )
512 );
513 wp_send_json_error(
514 array(
515 'errorTitle' => esc_html__( 'Heads Up!', 'everest-forms' ),
516 /* translators: %s: empty meta data */
517 'errorMessage' => sprintf( esc_html__( 'The ^ sign is now replaced with pow(). Please update accordingly. Tip: pow(a,b) = a^b', 'everest-forms' ) ),
518 )
519 );
520 }
521 }
522
523 /**
524 * Save CleanTalk settings.
525 *
526 * @since 3.3.0
527 */
528 if ( isset( $data['settings']['clean_talk_access_key'] ) && ! empty( $data['settings']['clean_talk_access_key'] ) ) {
529 $logger->info(
530 __( 'Saving CleanTalk settings.', 'everest-forms' ),
531 array( 'source' => 'form-save' )
532 );
533
534 $access_key = sanitize_text_field( $data['settings']['clean_talk_access_key'] );
535 $is_valid_access_key = FormHelper::evf_save_clean_talk_settings( $access_key );
536
537 if ( ! $is_valid_access_key ) {
538 $logger->error(
539 __( 'Invalid CleanTalk Access Key.', 'everest-forms' ),
540 array( 'source' => 'form-save' )
541 );
542 wp_send_json_error(
543 array(
544 'errorTitle' => esc_html__( 'Invalid CleanTalk Access Key', 'everest-forms' ),
545 /* translators: %s: empty meta data */
546 'errorMessage' => esc_html__( 'Please enter a valid CleanTalk Access Key.', 'everest-forms' ),
547 )
548 );
549 }
550 unset( $data['settings']['clean_talk_access_key'] );
551 }
552
553 if ( ! empty( $data['payments']['square']['enable_square'] ) ) {
554 $form_fields = $data['form_fields'];
555 $has_square_credit_card = false;
556
557 foreach ( $form_fields as $field ) {
558 if ( empty( $field['type'] ) ) {
559 continue;
560 }
561 if ( 'square-payment' === $field['type'] ) {
562 $has_square_credit_card = true;
563 break;
564 }
565 }
566
567 if ( ! $has_square_credit_card ) {
568 wp_send_json_error(
569 array(
570 'errorTitle' => esc_html__( 'Square payment requires a credit card.', 'everest-forms' ),
571 /* translators: %s: empty meta data */
572 'errorMessage' => esc_html__( 'Please add a Square credit card field.', 'everest-forms' ),
573 )
574 );
575 }
576 }
577
578 /**
579 * Creating the form tags taxonomy.
580 *
581 * @since 3.2.0
582 */
583 if ( ! empty( $data['settings']['form_tags'] ) ) {
584 $term_ids = array();
585
586 foreach ( $data['settings']['form_tags'] as $tag_name ) {
587 if ( is_numeric( $tag_name ) ) {
588 $term = get_term( absint( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
589 if ( $term && ! is_wp_error( $term ) ) {
590 $term_ids[] = $term->term_id;
591 continue;
592 }
593 }
594
595 $term = term_exists( $tag_name, EVF_Post_Types::TAGS_TAXONOMY );
596 if ( $term === null ) {
597 $term = wp_insert_term( sanitize_text_field( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
598 }
599 if ( ! is_wp_error( $term ) ) {
600 $term_ids[] = is_array( $term ) ? (int) $term['term_id'] : $term;
601 }
602 }
603 if ( ! empty( $term_ids ) ) {
604 wp_set_post_terms( absint( $data['id'] ), $term_ids, EVF_Post_Types::TAGS_TAXONOMY, false );
605 }
606 } else {
607 wp_set_post_terms( absint( $data['id'] ), array(), EVF_Post_Types::TAGS_TAXONOMY, false );
608 }
609
610 // Fix for sorting field ordering.
611 $logger->info(
612 __( 'Fix for sorting field ordering.', 'everest-forms' ),
613 array( 'source' => 'form-save' )
614 );
615 if ( isset( $data['structure'], $data['form_fields'] ) ) {
616 $structure = evf_flatten_array( $data['structure'] );
617 $data['form_fields'] = array_merge( array_intersect_key( array_flip( $structure ), $data['form_fields'] ), $data['form_fields'] );
618 }
619
620 $form_id = evf()->form->update( $data['id'], $data );
621
622 /**
623 * Save immediate feedback to non logged in user option in post meta.
624 *
625 * @since xx.xx.xx
626 */
627 if ( isset( $data['settings']['show_immediate_feedback_to_guests'] ) && ! empty( $data['settings']['show_immediate_feedback_to_guests'] ) ) {
628 $show_or_hide = sanitize_text_field( $data['settings']['show_immediate_feedback_to_guests'] );
629 if ( $show_or_hide ) {
630 update_post_meta( $form_id, 'everest_forms_show_immediate_feedback_to_guests', $show_or_hide );
631 }
632 } else {
633 update_post_meta( $form_id, 'everest_forms_show_immediate_feedback_to_guests', '' );
634 }
635
636 // To track the new confirmation.
637 if ( ! get_post_meta( $form_id, 'updated_form_confirmation', true ) ) {
638 update_post_meta( $form_id, 'updated_form_confirmation', true );
639 }
640
641 $form_styles = get_option( 'everest_forms_styles', array() );
642 $logger->info(
643 __( 'Saving form.', 'everest-forms' ),
644 array( 'source' => 'form-save' )
645 );
646 do_action( 'everest_forms_save_form', $form_id, $data, array(), ! empty( $form_styles[ $form_id ] ) );
647
648 if ( ! $form_id ) {
649 $logger->error(
650 __( 'An error occurred while saving the form.', 'everest-forms' ),
651 array( 'source' => 'form-save' )
652 );
653 wp_send_json_error(
654 array(
655 'errorTitle' => esc_html__( 'Form not found', 'everest-forms' ),
656 'errorMessage' => esc_html__( 'An error occurred while saving the form.', 'everest-forms' ),
657 )
658 );
659 } else {
660 $logger->info(
661 __( 'Form Saved successfully.', 'everest-forms' ),
662 array( 'source' => 'form-save' )
663 );
664 wp_send_json_success(
665 apply_filters(
666 'everest_forms_save_form_data',
667 array(
668 'form_name' => esc_html( $data['settings']['form_title'] ),
669 'redirect_url' => admin_url( 'admin.php?page=evf-builder' ),
670 ),
671 $form_id,
672 $data
673 )
674 );
675 }
676 }
677
678 /**
679 * Ajax handler for form submission.
680 */
681 public static function ajax_form_submission() {
682 // check_ajax_referer( 'everest_forms_ajax_form_submission', 'security' );
683
684 if ( ! empty( $_POST['everest_forms']['id'] ) ) {
685 $process = evf()->task->ajax_form_submission( evf_sanitize_entry( wp_unslash( $_POST['everest_forms'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
686 if ( isset( $process['response'] ) && 'success' === $process['response'] ) {
687 wp_send_json_success( $process );
688 }
689
690 wp_send_json_error( $process );
691 }
692 }
693
694 /**
695 * Ajax handler for template required addon activation.
696 */
697 public static function template_activate_addon() {
698 check_ajax_referer( 'everest_forms_template_licence_check', 'security' );
699
700 if ( ! current_user_can( 'activate_plugins' ) ) {
701 wp_send_json_error(
702 array(
703 'errorCode' => 'invalid_permission',
704 'errorMessage' => esc_html__( 'You do not have permission to activate plugins.', 'everest-forms' ),
705 )
706 );
707 }
708
709 if ( empty( $_POST['addon'] ) ) {
710 wp_send_json_error(
711 array(
712 'errorCode' => 'no_addon_specified',
713 'errorMessage' => esc_html__( 'No Addon specified.', 'everest-forms' ),
714 )
715 );
716 }
717
718 $addon = sanitize_text_field( wp_unslash( $_POST['addon'] ) );
719
720 // Restrict activation to genuine Everest Forms addons so this endpoint
721 // cannot be used to activate arbitrary installed plugins.
722 if ( ! in_array( $addon, EVF_Modules::get_allowed_addon_slugs(), true ) ) {
723 wp_send_json_error(
724 array(
725 'errorCode' => 'invalid_addon_slug',
726 'errorMessage' => esc_html__( 'The requested module is not a valid Everest Forms addon.', 'everest-forms' ),
727 )
728 );
729 }
730
731 $activate = activate_plugin( $addon . '/' . $addon . '.php' );
732
733 if ( is_wp_error( $activate ) ) {
734 wp_send_json_error(
735 array(
736 'errorCode' => 'addon_not_active',
737 'errorMessage' => esc_html__( 'Addon can not be activate. Please try again.', 'everest-forms' ),
738 )
739 );
740 } else {
741 wp_send_json_success( 'Addon sucessfully activated.' );
742 }
743 }
744
745 /**
746 * Ajax handler for licence check.
747 *
748 * @global WP_Filesystem_Base $wp_filesystem Subclass
749 */
750 public static function template_licence_check() {
751 check_ajax_referer( 'everest_forms_template_licence_check', 'security' );
752
753 if ( empty( $_POST['plan'] ) ) {
754 wp_send_json_error(
755 array(
756 'plan' => '',
757 'errorCode' => 'no_plan_specified',
758 'errorMessage' => esc_html__( 'No Plan specified.', 'everest-forms' ),
759 )
760 );
761 }
762
763 $addons = array();
764 $template_data = EVF_Admin_Form_Templates::get_template_data();
765 $template_data = is_array( $template_data ) ? $template_data : array();
766 if ( ! empty( $template_data ) ) {
767 foreach ( $template_data as $template ) {
768 if ( isset( $_POST['slug'] ) && $template->slug === $_POST['slug'] && in_array( trim( $_POST['plan'] ), $template->plan, true ) ) {
769 $addons = $template->addons;
770 }
771 }
772 }
773
774 $output = '<div class="everest-forms-recommend-addons">';
775 $output .= '<p class="desc plugins-info">' . esc_html__( 'This form template requires the following addons.', 'everest-forms' ) . '</p>';
776 $output .= '<table class="plugins-list-table widefat striped">';
777 $output .= '<thead><tr><th scope="col" class="manage-column required-plugins" colspan="2">Required Addons</th></tr></thead><tbody id="the-list">';
778 $output .= '</div>';
779
780 $activated = true;
781 foreach ( $addons as $slug => $addon ) {
782 if ( is_plugin_active( $slug . '/' . $slug . '.php' ) ) {
783 $class = 'active';
784 $parent_class = '';
785 } elseif ( file_exists( WP_PLUGIN_DIR . '/' . $slug . '/' . $slug . '.php' ) ) {
786 $class = 'activate-now';
787 $parent_class = 'inactive';
788 $activated = false;
789 } else {
790 $class = 'install-now';
791 $parent_class = 'inactive';
792 $activated = false;
793 }
794 $output .= '<tr class="plugin-card-' . $slug . ' plugin ' . $parent_class . '" data-slug="' . $slug . '" data-plugin="' . $slug . '/' . $slug . '.php" data-name="' . $addon . '">';
795 $output .= '<td class="plugin-name">' . $addon . '</td>';
796 $output .= '<td class="plugin-status"><span class="' . esc_attr( $class ) . '"></span></td>';
797 $output .= '</tr>';
798 }
799 $output .= '</tbody></table></div>';
800
801 wp_send_json_success(
802 array(
803 'html' => $output,
804 'activate' => $activated,
805 )
806 );
807 }
808
809 /**
810 * Ajax handler for installing a extension.
811 *
812 * @since 1.2.0
813 *
814 * @see Plugin_Upgrader
815 *
816 * @global WP_Filesystem_Base $wp_filesystem Subclass
817 */
818 public static function install_extension() {
819 check_ajax_referer( 'updates' );
820
821 if ( empty( $_POST['slug'] ) ) {
822 wp_send_json_error(
823 array(
824 'slug' => '',
825 'errorCode' => 'no_plugin_specified',
826 'errorMessage' => esc_html__( 'No plugin specified.', 'everest-forms' ),
827 )
828 );
829 }
830
831 $slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
832 $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['slug'] . '/' . $_POST['slug'] . '.php' ) ) );
833 $status = array(
834 'install' => 'plugin',
835 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
836 );
837
838 if ( ! current_user_can( 'install_plugins' ) ) {
839 $status['errorMessage'] = esc_html__( 'Sorry, you are not allowed to install plugins on this site.', 'everest-forms' );
840 wp_send_json_error( $status );
841 }
842
843 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
844 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
845
846 if ( file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
847 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
848 $status['plugin'] = $plugin;
849 $status['pluginName'] = $plugin_data['Name'];
850
851 if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) {
852 $result = activate_plugin( $plugin );
853
854 if ( is_wp_error( $result ) ) {
855 $status['errorCode'] = $result->get_error_code();
856 $status['errorMessage'] = $result->get_error_message();
857 wp_send_json_error( $status );
858 }
859
860 wp_send_json_success( $status );
861 }
862 }
863
864 $api = json_decode(
865 EVF_Updater_Key_API::version(
866 array(
867 'license' => get_option( 'everest-forms-pro_license_key' ),
868 'item_name' => ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
869 )
870 )
871 );
872
873 if ( is_wp_error( $api ) ) {
874 $status['errorMessage'] = $api->get_error_message();
875 wp_send_json_error( $status );
876 }
877
878 $status['pluginName'] = $api->name;
879
880 $skin = new WP_Ajax_Upgrader_Skin();
881 $upgrader = new Plugin_Upgrader( $skin );
882 $result = $upgrader->install( $api->download_link );
883
884 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
885 $status['debug'] = $skin->get_upgrade_messages();
886 }
887
888 if ( is_wp_error( $result ) ) {
889 $status['errorCode'] = $result->get_error_code();
890 $status['errorMessage'] = $result->get_error_message();
891 wp_send_json_error( $status );
892 } elseif ( is_wp_error( $skin->result ) ) {
893 $status['errorCode'] = $skin->result->get_error_code();
894 $status['errorMessage'] = $skin->result->get_error_message();
895 wp_send_json_error( $status );
896 } elseif ( $skin->get_errors()->get_error_code() ) {
897 $status['errorMessage'] = $skin->get_error_messages();
898 wp_send_json_error( $status );
899 } elseif ( is_null( $result ) ) {
900 global $wp_filesystem;
901
902 $status['errorCode'] = 'unable_to_connect_to_filesystem';
903 $status['errorMessage'] = esc_html__( 'Unable to connect to the filesystem. Please confirm your credentials.', 'everest-forms' );
904
905 // Pass through the error from WP_Filesystem if one was raised.
906 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
907 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
908 }
909
910 wp_send_json_error( $status );
911 }
912
913 $install_status = install_plugin_install_status( $api );
914
915 if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
916 if ( isset( $_POST['page'] ) && 'everest-forms_page_evf-builder' === $_POST['page'] ) {
917 activate_plugin( $install_status['file'] );
918 } else {
919 $status['activateUrl'] =
920 esc_url_raw(
921 add_query_arg(
922 array(
923 'action' => 'activate',
924 'plugin' => $install_status['file'],
925 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
926 ),
927 admin_url( 'admin.php?page=evf-addons' )
928 )
929 );
930 }
931 }
932
933 wp_send_json_success( $status );
934 }
935
936 /**
937 * AJAX Integration connect.
938 */
939 public static function integration_connect() {
940 check_ajax_referer( 'process-ajax-nonce', 'security' );
941
942 // Check permissions.
943 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
944 wp_die( -1 );
945 }
946
947 if ( empty( $_POST ) ) {
948 wp_send_json_error(
949 array(
950 'error' => esc_html__( 'Missing data', 'everest-forms' ),
951 )
952 );
953 }
954
955 // EVF_Integrations is normally loaded on current_screen (admin page loads only).
956 // During AJAX requests that hook never fires, so integration action hooks are never
957 // registered. Instantiate it here so provider connect handlers are available.
958 if ( ! EVF()->integrations ) {
959 EVF()->integrations = new EVF_Integrations();
960 }
961
962 do_action( 'everest_forms_integration_account_connect_' . ( isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '' ), $_POST );
963 }
964
965 /**
966 * AJAX Email Add.
967 */
968 public static function new_email_add() {
969 check_ajax_referer( 'process-ajax-nonce', 'security' );
970
971 // Check permissions.
972 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
973 wp_die( -1 );
974 }
975
976 $connection_id = 'connection_' . uniqid();
977 $preview_url = add_query_arg(
978 array(
979 'evf_email_preview' => $connection_id,
980 'form_id' => isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0,
981 ),
982 home_url()
983 );
984 wp_send_json_success(
985 array(
986 'connection_id' => $connection_id,
987 'preview_url' => $preview_url,
988 )
989 );
990 }
991
992 /**
993 * AJAX Email Duplicate.
994 */
995 public static function email_duplicate() {
996 check_ajax_referer( 'process-ajax-nonce', 'security' );
997
998 // Check permissions.
999 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
1000 wp_die( -1 );
1001 }
1002
1003 $connection_id = 'connection_' . uniqid();
1004 $preview_url = '';
1005 $preview_url = add_query_arg(
1006 array(
1007 'evf_email_preview' => $connection_id,
1008 'form_id' => isset( $_POST['id'] ) ? absint( $_POST['id'] ) : 0,
1009 'preview_url' => $preview_url,
1010 ),
1011 home_url()
1012 );
1013
1014 wp_send_json_success(
1015 array(
1016 'connection_id' => $connection_id,
1017 'prev_connection_id' => isset( $_POST['prev_connection_id'] ) ? sanitize_text_field( wp_unslash( $_POST['prev_connection_id'] ) ) : '',
1018 'preview_url' => $preview_url,
1019 )
1020 );
1021 }
1022
1023
1024 /**
1025 * AJAX Integration disconnect.
1026 */
1027 public static function integration_disconnect() {
1028 check_ajax_referer( 'process-ajax-nonce', 'security' );
1029
1030 // Check permissions.
1031 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
1032 wp_die( -1 );
1033 }
1034
1035 if ( empty( $_POST ) ) {
1036 wp_send_json_error(
1037 array(
1038 'error' => esc_html__( 'Missing data', 'everest-forms' ),
1039 )
1040 );
1041 }
1042
1043 if ( ! EVF()->integrations ) {
1044 EVF()->integrations = new EVF_Integrations();
1045 }
1046
1047 do_action( 'everest_forms_integration_account_disconnect_' . ( isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '' ), $_POST );
1048
1049 $connected_accounts = get_option( 'everest_forms_integrations', false );
1050
1051 if ( ! empty( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] ) ) {
1052 unset( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] );
1053 update_option( 'everest_forms_integrations', $connected_accounts );
1054 wp_send_json_success( array( 'remove' => true ) );
1055 } else {
1056 wp_send_json_error(
1057 array(
1058 'error' => esc_html__( 'Connection missing', 'everest-forms' ),
1059 )
1060 );
1061 }
1062 }
1063
1064 /**
1065 * Triggered when clicking the rating footer.
1066 */
1067 public static function rated() {
1068 check_ajax_referer( 'everest_forms_rated', 'security' );
1069
1070 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1071 wp_die( -1 );
1072 }
1073 update_option( 'everest_forms_admin_footer_text_rated', 1 );
1074 wp_die();
1075 }
1076
1077 /**
1078 * Triggered when clicking the review notice button.
1079 */
1080 public static function review_dismiss() {
1081 check_ajax_referer( 'everest_forms_review_dismiss', 'security' );
1082
1083 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1084 wp_die( -1 );
1085 }
1086 $review = get_option( 'everest_forms_review', array() );
1087 $review['time'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
1088 $review['dismissed'] = true;
1089 update_option( 'everest_forms_review', $review );
1090 wp_die();
1091 }
1092
1093 /**
1094 * Triggered when clicking the survey notice button.
1095 */
1096 public static function survey_dismiss() {
1097 check_ajax_referer( 'everest_forms_survey_dismiss', 'security' );
1098
1099 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1100 wp_die( -1 );
1101 }
1102 $survey = get_option( 'everest_forms_survey', array() );
1103 $survey['dismissed'] = true;
1104 update_option( 'everest_forms_survey', $survey );
1105 wp_die();
1106 }
1107
1108 /**
1109 * Triggered when clicking the allow usage notice allow or deny buttons.
1110 */
1111 public static function allow_usage_dismiss() {
1112 check_ajax_referer( 'allow_usage_nonce', '_wpnonce' );
1113
1114 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1115 wp_die( -1 );
1116 }
1117
1118 $allow_usage_tracking = isset( $_POST['allow_usage_tracking'] ) ? sanitize_text_field( wp_unslash( $_POST['allow_usage_tracking'] ) ) : false;
1119
1120 update_option( 'everest_forms_allow_usage_notice_shown', true );
1121
1122 if ( 'true' === $allow_usage_tracking ) {
1123 update_option( 'everest_forms_allow_usage_tracking', 'yes' );
1124 }
1125
1126 wp_die();
1127 }
1128
1129 /**
1130 * Triggered when clicking the PHP deprecation notice.
1131 */
1132 public static function php_notice_dismiss() {
1133 check_ajax_referer( 'php_notice_nonce', '_wpnonce' );
1134
1135 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1136 wp_die( -1 );
1137 }
1138 $current_date = gmdate( 'Y-m-d' );
1139 $prompt_count = get_option( 'everest_forms_php_deprecated_notice_prompt_count', 0 );
1140
1141 update_option( 'everest_forms_php_deprecated_notice_last_prompt_date', $current_date );
1142 update_option( 'everest_forms_php_deprecated_notice_prompt_count', ++$prompt_count );
1143 wp_die();
1144 }
1145
1146
1147 /**
1148 * Triggered when clicking the email failed notice.
1149 */
1150 public static function email_failed_notice_dismiss() {
1151 check_ajax_referer( 'email_failed_nonce', '_wpnonce' );
1152
1153 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1154 wp_die( -1 );
1155 }
1156 update_option( 'everest_forms_email_send_notice_dismiss', true );
1157 wp_die();
1158 }
1159
1160 /**
1161 * Triggered when clicking the form toggle.
1162 */
1163 public static function enabled_form() {
1164 // Run a security check.
1165 check_ajax_referer( 'everest_forms_enabled_form', 'security' );
1166
1167 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
1168 $enabled = isset( $_POST['enabled'] ) ? absint( $_POST['enabled'] ) : 0;
1169
1170 if ( ! current_user_can( 'everest_forms_edit_form', $form_id ) ) {
1171 wp_die( -1 );
1172 }
1173
1174 /**
1175 * Update the form status in post table.
1176 *
1177 * @since 3.2.0
1178 */
1179 $new_status = $enabled ? 'publish' : 'inactive';
1180
1181 $result = wp_update_post(
1182 array(
1183 'ID' => $form_id,
1184 'post_status' => $new_status,
1185 ),
1186 true
1187 );
1188
1189 if ( is_wp_error( $result ) ) {
1190 wp_send_json_error( $result->get_error_message(), 500 );
1191 }
1192
1193 $form_data = evf()->form->get( absint( $form_id ), array( 'content_only' => true ) );
1194
1195 $form_data['form_enabled'] = $enabled;
1196
1197 evf()->form->update( $form_id, $form_data );
1198 }
1199
1200 /**
1201 * Import Form ajax.
1202 */
1203 public static function import_form_action() {
1204 try {
1205 check_ajax_referer( 'process-import-ajax-nonce', 'security' );
1206 EVF_Admin_Import_Export::import_forms();
1207 } catch ( Exception $e ) {
1208 wp_send_json_error(
1209 array(
1210 'message' => $e->getMessage(),
1211 )
1212 );
1213 }
1214 }
1215
1216 /**
1217 * Send test email.
1218 */
1219 public static function send_test_email() {
1220 try {
1221 if ( ! current_user_can( 'manage_options' ) ) {
1222 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1223 }
1224
1225 check_ajax_referer( 'process-ajax-nonce', 'security' );
1226 $from = esc_attr( get_bloginfo( 'name', 'display' ) );
1227 $email = sanitize_email( isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '' );
1228
1229 /* translators: %s: from address */
1230 $subject = 'Everest Form: ' . sprintf( esc_html__( 'Test email from %s', 'everest-forms' ), $from );
1231 $header = "Reply-To: {{from}} \r\n";
1232 $header .= 'Content-Type: text/html; charset=UTF-8';
1233 $message = sprintf(
1234 '%s <br /> %s <br /> %s <br /> %s <br /> %s',
1235 __( 'Congratulations,', 'everest-forms' ),
1236 __( 'Your test email has been received successfully.', 'everest-forms' ),
1237 __( 'We thank you for trying out Everest Forms and joining our mission to make sure you get your emails delivered.', 'everest-forms' ),
1238 __( 'Regards,', 'everest-forms' ),
1239 __( 'Everest Forms Team', 'everest-forms' )
1240 );
1241 $status = wp_mail( $email, $subject, $message, $header );
1242 if ( $status ) {
1243 wp_send_json_success( array( 'message' => __( 'Test email was sent successfully! Please check your inbox to make sure it is delivered.', 'everest-forms' ) ) );
1244 } else {
1245 wp_send_json_error( array( 'message' => __( 'Test email was unsuccessful! Something went wrong.', 'everest-forms' ) ) );
1246 }
1247 } catch ( Exception $e ) {
1248 wp_send_json_error(
1249 array(
1250 'message' => $e->getMessage(),
1251 )
1252 );
1253 }
1254 }
1255
1256 /**
1257 * Send stat routine test email.
1258 *
1259 * @since 2.0.9
1260 */
1261 public static function send_routine_report_test_email() {
1262 try {
1263 if ( ! current_user_can( 'manage_options' ) ) {
1264 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1265 }
1266
1267 check_ajax_referer( 'process-ajax-nonce', 'security' );
1268
1269 $frequency = get_option( 'everest_forms_entries_reporting_frequency', 'Weekly' );
1270 if ( ! in_array( $frequency, array( 'Daily', 'Weekly', 'Monthly' ), true ) ) {
1271 $frequency = 'Weekly';
1272 }
1273
1274 $test_email = sanitize_email( get_option( 'everest_forms_routine_report_send_email_test_to', '' ) );
1275 if ( empty( $test_email ) ) {
1276 $test_email = sanitize_email( get_bloginfo( 'admin_email' ) );
1277 }
1278
1279 $subject = get_option( 'everest_forms_entries_reporting_subject', __( 'Everest Forms - Entries summary statistics', 'everest-forms' ) );
1280 if ( empty( trim( $subject ) ) ) {
1281 $subject = __( 'Everest Forms - Entries summary statistics', 'everest-forms' );
1282 }
1283 $subject = sprintf( __( '[TEST] %s', 'everest-forms' ), $subject );
1284
1285 $email_builder = new EVF_Email_Entries_Report( $frequency, null, true );
1286 $html_message = $email_builder->render_html();
1287
1288 $headers = array(
1289 'Content-Type: text/html; charset=UTF-8',
1290 'From: ' . wp_specialchars_decode( get_bloginfo( 'name' ) ) . ' <' . get_option( 'admin_email' ) . '>',
1291 );
1292
1293 $sent = wp_mail( $test_email, $subject, $html_message, $headers );
1294
1295 if ( $sent ) {
1296 wp_send_json_success(
1297 array(
1298 'message' => sprintf(
1299 __( 'Test report sent to %s. Please check your inbox.', 'everest-forms' ),
1300 $test_email
1301 ),
1302 )
1303 );
1304 } else {
1305 wp_send_json_error( array( 'message' => __( 'Test email could not be sent. Please check your site email configuration.', 'everest-forms' ) ) );
1306 }
1307 } catch ( Exception $e ) {
1308 wp_send_json_error( array( 'message' => $e->getMessage() ) );
1309 }
1310 }
1311
1312 /**
1313 * Manually trigger a full entries report send immediately.
1314 *
1315 * Sends to the configured scheduled recipient (not the test address).
1316 * Logged to report history as type 'manual'.
1317 *
1318 * @since 2.0.9
1319 */
1320 public static function send_manual_report() {
1321 try {
1322 if ( ! current_user_can( 'manage_options' ) ) {
1323 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1324 }
1325
1326 check_ajax_referer( 'process-ajax-nonce', 'security' );
1327
1328 $cron = new EVF_Report_Cron();
1329 $sent = $cron->evf_report_form_statistics_send( false );
1330
1331 if ( $sent ) {
1332 wp_send_json_success( array( 'message' => __( 'Report sent successfully.', 'everest-forms' ) ) );
1333 } else {
1334 wp_send_json_error( array( 'message' => __( 'Report could not be sent. Please check your settings and email configuration.', 'everest-forms' ) ) );
1335 }
1336 } catch ( Exception $e ) {
1337 wp_send_json_error( array( 'message' => $e->getMessage() ) );
1338 }
1339 }
1340
1341 /**
1342 * Locate form.
1343 */
1344 public static function locate_form_action() {
1345 global $wpdb;
1346 try {
1347 check_ajax_referer( 'process-locate-ajax-nonce', 'security' );
1348 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
1349 $everest_form_shortcode = '%[everest_form id="' . $id . '"%';
1350 $form_id_shortcode = '%{"formId":"' . $id . '"%';
1351 $pages = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}posts WHERE post_content LIKE %s OR post_content LIKE %s", $everest_form_shortcode, $form_id_shortcode ) ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1352 $page_list = array();
1353 foreach ( $pages as $page ) {
1354 if ( 'page' === $page->post_type || 'post' === $page->post_type ) {
1355 $page_title = $page->post_title;
1356 $page_guid = get_permalink( $page->ID );
1357 $page_list[ $page_title ] = $page_guid;
1358 }
1359 }
1360 wp_send_json_success( $page_list );
1361 } catch ( Exception $e ) {
1362 wp_send_json_error(
1363 array(
1364 'message' => $e->getMessage(),
1365 )
1366 );
1367 }
1368 }
1369 /**
1370 * Slot booking.
1371 */
1372 public static function slot_booking() {
1373 try {
1374 check_ajax_referer( 'everest_forms_slot_booking_nonce', 'security' );
1375 $datetime_value = isset( $_POST['data-time-value'] ) ? sanitize_text_field( wp_unslash( $_POST['data-time-value'] ) ) : '';
1376 $datetime_format = isset( $_POST['data-time-format'] ) ? sanitize_text_field( wp_unslash( $_POST['data-time-format'] ) ) : '';
1377 $date_format = isset( $_POST['data-format'] ) ? sanitize_text_field( wp_unslash( $_POST['data-format'] ) ) : '';
1378 $mode = isset( $_POST['mode'] ) ? sanitize_text_field( wp_unslash( $_POST['mode'] ) ) : '';
1379 $form_id = isset( $_POST['form-id'] ) ? sanitize_text_field( wp_unslash( $_POST['form-id'] ) ) : '';
1380 $time_interval = isset( $_POST['time-interval'] ) ? sanitize_text_field( wp_unslash( $_POST['time-interval'] ) ) : '';
1381 $datetime_arr = parse_datetime_values( $datetime_value, $datetime_format, $date_format, $mode, $time_interval );
1382
1383 if ( empty( $datetime_arr ) ) {
1384 wp_send_json_error(
1385 array(
1386 'message' => __( 'Please select at least one date time.', 'everest-forms' ),
1387 )
1388 );
1389 }
1390 $booked_slot = evf_maybe_unserialize( get_option( 'evf_booked_slot', '' ) );
1391 $is_booked = false;
1392 if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) {
1393 foreach ( $datetime_arr as $arr ) {
1394
1395 foreach ( $booked_slot[ $form_id ] as $key => $slot ) {
1396 if ( $arr[0] >= $slot[0] && $arr[1] <= $slot[1] ) {
1397 $is_booked = true;
1398 break;
1399 } elseif ( $arr[0] >= $slot[0] && $arr[0] < $slot[1] && $arr[1] >= $slot[1] ) {
1400 $is_booked = true;
1401 break;
1402 }
1403 }
1404 }
1405 }
1406 if ( $is_booked ) {
1407 wp_send_json_success(
1408 array(
1409 'message' => __( 'This slot is already booked. Please choose other slot', 'everest-forms' ),
1410 )
1411 );
1412 }
1413 wp_send_json_error(
1414 array(
1415 'message' => __( 'This slot is not booked.', 'everest-forms' ),
1416 )
1417 );
1418 } catch ( Exception $e ) {
1419 wp_send_json_error(
1420 array(
1421 'message' => __( 'Something went wrong.', 'everest-forms' ),
1422 )
1423 );
1424 }
1425 }
1426
1427 /**
1428 * Activate addons from builder.
1429 */
1430 public static function active_addons() {
1431 try {
1432 check_ajax_referer( 'evf_active_nonce', 'security' );
1433
1434 if ( ! current_user_can( 'activate_plugins' ) ) {
1435 wp_send_json_error(
1436 array(
1437 'message' => esc_html__( 'You do not have permission to activate plugins.', 'everest-forms' ),
1438 )
1439 );
1440 }
1441
1442 $plugin = isset( $_POST['plugin_file'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_file'] ) ) : '';
1443 $slug = dirname( $plugin );
1444
1445 // Restrict activation to genuine Everest Forms addons so this endpoint
1446 // cannot be used to activate arbitrary installed plugins.
1447 if ( '' === $plugin || ! in_array( $slug, EVF_Modules::get_allowed_addon_slugs(), true ) ) {
1448 wp_send_json_error(
1449 array(
1450 'message' => esc_html__( 'The requested module is not a valid Everest Forms addon.', 'everest-forms' ),
1451 )
1452 );
1453 }
1454
1455 $activate = activate_plugin( $plugin );
1456 if ( is_wp_error( $activate ) ) {
1457 $activation_error = $activate->get_error_message();
1458 wp_send_json_error(
1459 array(
1460 'message' => $activation_error,
1461 )
1462 );
1463 } else {
1464 wp_send_json_success(
1465 array(
1466 'message' => __( 'Activated successfully', 'everest-forms' ),
1467 )
1468 );
1469 }
1470 } catch ( Exception $e ) {
1471 wp_send_json_error(
1472 array(
1473 'message' => $e->getMessage(),
1474 )
1475 );
1476 }
1477 }
1478
1479 /**
1480 * Download the provided font and return the url for font file.
1481 *
1482 * @since 2.0.8
1483 */
1484 public static function get_local_font_url() {
1485 $font_url = isset( $_POST['font_url'] ) ? sanitize_text_field( wp_unslash( $_POST['font_url'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification
1486
1487 $allowed_urls = array(
1488 'https://fonts.googleapis.com',
1489 );
1490
1491 if ( ! in_array( $font_url, $allowed_urls ) ) {
1492 return;
1493 }
1494
1495 if ( str_contains( $font_url, 'https://fonts.googleapis.com' ) ) {
1496 $font_url = evf_maybe_get_local_font_url( $font_url );
1497 }
1498
1499 return wp_send_json_success( $font_url );
1500 }
1501
1502 /**
1503 * Forms list for form migrator.
1504 *
1505 * @since 2.0.8
1506 *
1507 * @throws Exception If there is an error.
1508 */
1509 public static function form_migrator_forms_list() {
1510 try {
1511 check_ajax_referer( 'evf_form_migrator_forms_list_nonce', 'security' );
1512
1513 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1514 if ( '' === $form_slug ) {
1515 wp_send_json_error(
1516 array(
1517 'message' => __( 'Missing form slug !', 'everest-forms' ),
1518 )
1519 );
1520 }
1521
1522 // Creating the form instance and getting the form list.
1523 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1524
1525 if ( ! class_exists( $class_name ) ) {
1526 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1527 throw new Exception( $except_message );
1528 }
1529
1530 $form_instance = new $class_name();
1531 $forms_list = $form_instance->get_forms();
1532
1533 if ( empty( $forms_list ) ) {
1534 wp_send_json_error(
1535 array(
1536 'message' => esc_html( 'No forms are currently available in the list !!!', 'everest-forms' ),
1537 )
1538 );
1539 }
1540 $row = 0;
1541 $form_per_page = 5;
1542 $ceil = ceil( count( $forms_list ) / $form_per_page );
1543 $forms_list_table = '<div class="evf-fm-forms-table-wrapper">';
1544 $forms_list_table .= '<h4>' . sprintf( '%s %s', esc_html__( 'Import', 'everest-forms' ), $form_instance->name ) . '</h4>';
1545 $forms_list_table .= '<table class="evf-fm-forms-table" data-form-slug="' . esc_attr( $form_slug ) . '">';
1546 $forms_list_table .= '<tr class="evf-th-title"><th><input id="evf-fm-select-all" type="checkbox" name="fm_select_all_form" /></th><th>' . esc_html__( 'Form Name', 'everest-forms' ) . '</th><th>' . esc_html__( 'Imported', 'everest-forms' ) . '</th><th>' . esc_html__( 'Action', 'everest-forms' ) . '</th></tr>';
1547 $hidden = '';
1548 $imported = get_option( 'evf_fm_' . $form_slug . '_imported_form_list', array() );
1549 foreach ( $forms_list as $form_id => $form_name ) {
1550 ++$row;
1551 if ( in_array( $form_id, $imported ) ) {
1552 $is_imported = true;
1553 $imported_text = esc_html__( 'Yes', 'everest-forms' );
1554 } else {
1555 $is_imported = false;
1556 $imported_text = esc_html__( 'No', 'everest-forms' );
1557 }
1558 $forms_list_table .= '<tr id="evf-fm-row-' . esc_attr( $row ) . '" class="evf-fm-row ' . esc_attr( $hidden ) . '"><td><input class="evf-fm-select-single" type="checkbox" name="fm_select_single_form_' . esc_attr( $form_id ) . '" data-form-id="' . esc_attr( $form_id ) . '" /></td><td>' . esc_html__( $form_name, 'everest-forms' ) . '</td><td><p class="evf-fm-imported" data-form-id="' . esc_attr( $form_id ) . '">' . esc_attr( $imported_text ) . '<p></td>';
1559 $forms_list_table .= '<td>';
1560 $forms_list_table .= '<div class="evf-fm-import-actions"><button class="evf-fm-import-single" data-form-id="' . esc_attr( $form_id ) . '">' . esc_html( 'Import Form' ) . '</button>';
1561 if ( 'contact-form-7' !== $form_slug ) {
1562 $disabled = $is_imported ? '' : 'disabled';
1563 $forms_list_table .= '<button class="evf-fm-import-entry" data-form-id="' . esc_attr( $form_id ) . '"' . esc_attr( $disabled ) . '>' . esc_html( 'Import Entry' ) . '</button>';
1564 }
1565 $forms_list_table .= '</div></td></tr>';
1566 if ( $row === $form_per_page ) {
1567 $hidden = 'evf-fm-hide-row';
1568 }
1569 }
1570 $forms_list_table .= '</table>';
1571 $forms_list_table .= '<div class="evf-fm-import-selected-wrapper"><button class="evf-fm-import-selected-btn">' . esc_html( 'Import Selected Forms' ) . '</button>';
1572 $forms_list_table .= '<div data-total-page="' . esc_attr( count( $forms_list ) ) . '" data-fm-ceil="' . esc_attr( $ceil ) . '" data-form-per-page="' . esc_attr( $form_per_page ) . '" class="evf-fm-pagination">';
1573
1574 for ( $page = 1; $page <= $ceil; $page++ ) {
1575 $active = '';
1576 if ( 1 === $page ) {
1577 $active = 'evf-fm-btn-active';
1578 }
1579 $forms_list_table .= '<button class="evf-fm-page ' . esc_attr( $active ) . '" data-page="' . esc_attr( $page ) . '">' . esc_attr( $page ) . '</button>';
1580 }
1581 $forms_list_table .= '</div></div>';
1582 $forms_list_table .= '</div>';
1583 wp_send_json_success(
1584 array(
1585 'message' => esc_html__( 'All Forms List', 'everest-forms' ),
1586 'forms_list_table' => $forms_list_table,
1587 )
1588 );
1589 } catch ( Exception $e ) {
1590 wp_send_json_error(
1591 array(
1592 'message' => $e->getMessage(),
1593 )
1594 );
1595 }
1596 }
1597
1598 /**
1599 * Form migrator.
1600 *
1601 * @since 2.0.8
1602 *
1603 * @throws Exception If there is an error.
1604 */
1605 public static function form_migrator() {
1606 try {
1607 check_ajax_referer( 'evf_form_migrator_nonce', 'security' );
1608 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1609 $form_ids = isset( $_POST['form_ids'] ) ? wp_unslash( $_POST['form_ids'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1610 if ( '' === $form_ids ) {
1611 wp_send_json_error(
1612 array(
1613 'message' => __( 'Missing Form ID !!!', 'everest-forms' ),
1614 )
1615 );
1616 }
1617
1618 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1619
1620 if ( ! class_exists( $class_name ) ) {
1621 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1622 throw new Exception( $except_message );
1623 }
1624 // Create the instance of class.
1625 $form_instance = new $class_name();
1626 $forms_data = $form_instance->get_fm_mapped_form_data( $form_ids );
1627
1628 if ( 1 === count( $forms_data ) ) {
1629 wp_send_json_success(
1630 array(
1631 'message' => sprintf( '%s <a href="%s" target="_blank">%s</a>', __( 'Imported Successfully.', 'everest-forms' ), esc_url( $forms_data[ $form_ids[0] ]['edit'] ), __( 'View Form', 'everest-forms' ) ),
1632 'form_data' => $forms_data,
1633 )
1634 );
1635 } else {
1636 wp_send_json_success(
1637 array(
1638 'message' => __( 'Imported Successfully', 'everest-forms' ),
1639 'form_data' => $forms_data,
1640 )
1641 );
1642 }
1643 } catch ( Exception $e ) {
1644 wp_send_json_error(
1645 array(
1646 'message' => $e->getMessage(),
1647 )
1648 );
1649 }
1650 }
1651 /**
1652 * Dismiss Form migrator notice.
1653 *
1654 * @since 2.0.8
1655 */
1656 public static function fm_dismiss_notice() {
1657 try {
1658 check_ajax_referer( 'evf_fm_dismiss_notice_nonce', 'security' );
1659 $option_id = isset( $_POST['option_id'] ) ? sanitize_text_field( $_POST['option_id'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
1660 update_option( $option_id, true );
1661
1662 wp_send_json_success(
1663 array(
1664 'message' => __( 'Updated !', 'everest-forms' ),
1665 )
1666 );
1667 } catch ( Exception $e ) {
1668 wp_send_json_error(
1669 array(
1670 'message' => $e->getMessage(),
1671 )
1672 );
1673 }
1674 }
1675 /**
1676 * Form entry migrator.
1677 *
1678 * @since 2.0.8
1679 *
1680 * @throws Exception If there is an error.
1681 */
1682 public static function form_entry_migrator() {
1683 try {
1684 check_ajax_referer( 'evf_form_entry_migrator_nonce', 'security' );
1685 if ( ! wpforms()->is_pro() ) {
1686 wp_send_json_error(
1687 array(
1688 'message' => esc_html__( 'Entries not available in WPForms Lite.', 'everest-forms' ),
1689 )
1690 );
1691 }
1692 $form_id = isset( $_POST['form_id'] ) ? sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) : '';
1693 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1694
1695 if ( empty( $form_id ) || empty( $form_slug ) ) {
1696
1697 wp_send_json_error(
1698 array(
1699 'message' => __( 'Invalid Request !!', 'everest-forms' ),
1700 )
1701 );
1702 }
1703
1704 $migrated_form_list = get_option( 'evf_fm_' . $form_slug . '_imported_form_list', array() );
1705 $evf_form_id = array_search( $form_id, $migrated_form_list );
1706
1707 if ( ! $evf_form_id ) {
1708 wp_send_json_error(
1709 array(
1710 'message' => esc_html__( 'Please migrate the form before importing the entry', 'everest-forms' ),
1711 )
1712 );
1713 }
1714 // Creating the form instance and getting the form list.
1715 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1716
1717 if ( ! class_exists( $class_name ) ) {
1718 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1719 throw new Exception( $except_message );
1720 }
1721 // Create the instance of class.
1722 $form_instance = new $class_name();
1723 $evf_entries = $form_instance->migrate_entry( $evf_form_id, $form_id );
1724
1725 $success = array();
1726 $unsuccess = array();
1727 foreach ( $evf_entries as $key => $entry ) {
1728 if ( ! $entry ) {
1729 $unsuccess[] = $key;
1730 continue;
1731 }
1732 $success[] = $key;
1733 }
1734 if ( count( $unsuccess ) === 0 ) {
1735 $response = array(
1736 'message' => esc_html__( 'All entries are migrated successfully!!', 'everest-forms' ),
1737 'success' => $success,
1738 'unsuccess' => $unsuccess,
1739 );
1740 } elseif ( count( $unsuccess ) > 0 && count( $success ) === 0 ) {
1741 $response = array(
1742 'message' => esc_html__( 'Entry migration failed!!', 'everest-forms' ),
1743 'success' => $success,
1744 'unsuccess' => $unsuccess,
1745 );
1746 } elseif ( count( $unsuccess ) > 0 && count( $success ) > 0 ) {
1747 $response = array(
1748 'message' => esc_html__( 'Only some entries are migrated successfully!!', 'everest-forms' ),
1749 'success' => $success,
1750 'unsuccess' => $unsuccess,
1751 );
1752 }
1753 wp_send_json_success(
1754 $response
1755 );
1756 } catch ( Exception $e ) {
1757 wp_send_json_error(
1758 array(
1759 'message' => $e->getMessage(),
1760 )
1761 );
1762 }
1763 }
1764 /**
1765 * Everest Forms - Embed Form.
1766 *
1767 * @since 2.0.8
1768 */
1769 public static function embed_form() {
1770 check_ajax_referer( 'everest_forms_embed_form', 'security' );
1771 $args = array(
1772 'post_status' => 'publish',
1773 'post_type' => 'page',
1774 );
1775 $pages = get_pages( $args );
1776
1777 wp_send_json_success( $pages );
1778 }
1779
1780 /**
1781 * Get page edit link
1782 *
1783 * @since 2.0.8
1784 */
1785 public static function goto_edit_page() {
1786 check_ajax_referer( 'everest_forms_goto_edit_page', 'security' );
1787
1788 $page_id = empty( $_POST['page_id'] ) ? 0 : sanitize_text_field( absint( $_POST['page_id'] ) );
1789
1790 if ( empty( $page_id ) ) {
1791 $url = add_query_arg( 'post_type', 'page', admin_url( 'post-new.php' ) );
1792 $meta = array(
1793 'embed_page' => 0,
1794 'embed_page_title' => ! empty( $_POST['page_title'] ) ? sanitize_text_field( wp_unslash( $_POST['page_title'] ) ) : '',
1795 );
1796 } else {
1797 $url = get_edit_post_link( $page_id, '' );
1798 $meta = array(
1799 'embed_page' => $page_id,
1800 );
1801 }
1802 $page_url = add_query_arg(
1803 array(
1804 'form' => 'everest-forms',
1805 ),
1806 esc_url_raw( $url )
1807 );
1808 $meta['form_id'] = ! empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
1809 EVF_Admin_Embed_Wizard::set_meta( $meta );
1810
1811 wp_send_json_success( $page_url );
1812 }
1813
1814 /**
1815 * Map csv fields with form fields.
1816 *
1817 * @since 3.0.0
1818 */
1819 public static function map_csv() {
1820 check_ajax_referer( 'evf-import-entries', 'security' );
1821
1822 if ( empty( $_FILES ) ) {
1823 wp_send_json_error(
1824 array(
1825 'message' => 'Please upload csv file.',
1826 )
1827 );
1828 }
1829
1830 $form_id = isset($_POST['form_id']) ? absint($_POST['form_id']) : 0; //phpcs:ignore
1831 $form_fields = evf_get_form_fields( $form_id );
1832
1833 $csv_header = self::get_csv_header( $_FILES );
1834
1835 $output = '';
1836 $output .= '<div class="evf-map-entries-to-form">';
1837 $output .= '<form id="evf-import-entries-form">';
1838 $output .= '<p>' . esc_html__( 'Map CSV fields to Form fields.', 'everest-forms' ) . '</p>';
1839 $output .= '<div class ="evf-form-fields-and-csv-fields" style="display: flex;">';
1840 $output .= '<div class="evf-form-fields" style="width: 50%;">';
1841 $output .= '<h4>' . esc_html__( 'Form Fields', 'everest-forms' ) . '</h4>';
1842 $output .= '</div>';
1843 $output .= '<div class="evf-csv-fields" style="width: 50%;">';
1844 $output .= '<h4>' . esc_html__( 'CSV Fields', 'everest-forms' ) . '</h4>';
1845 $output .= '</div>';
1846 $output .= '</div>';
1847 $output .= '<div class = "evf-map-entries-to-form-wrapper" style="display: flex;">';
1848 $output .= '<div class="evf-form-fields" style="width: 50%;">';
1849 $output .= '<select name="map-entries-to-form" class="evf-form-fields-csv" style="min-width: 90%;">';
1850
1851 if ( ! empty( $form_fields ) ) {
1852 foreach ( $form_fields as $key => $value ) {
1853 $output .= '<option value="' . esc_attr( $key ) . '">' . esc_html( $value['label'] ) . '</option>';
1854 }
1855 } else {
1856 $output .= '<option value="">' . esc_html__( 'No form fields', 'everest-forms' ) . '</option>';
1857 }
1858
1859 $output .= '</select>';
1860 $output .= '</div>';
1861 $output .= '<div class="evf-csv-fields" style="width: 50%;">';
1862 $output .= '<select name="map-entries-to-csv" style="min-width: 90%;">';
1863
1864 if ( ! empty( $csv_header ) ) {
1865 foreach ( $csv_header as $value ) {
1866
1867 $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( str_replace( '"', '', $value ) ) . '</option>';
1868 }
1869 } else {
1870 $output .= '<option value="">' . esc_html__( 'No csv fields', 'everest-forms' ) . '</option>';
1871 }
1872
1873 $output .= '</select>';
1874 $output .= '</div>';
1875 $output .= '<span class="actions" style="display: flex; align-items: center; justify-content: space-between;"><a class="evf-add-clone" href="#" style="text-decoration: none;"><i class="dashicons dashicons-plus"></i></a><a class="evf-remove-clone everest-forms-hidden" href="#" style="text-decoration: none;"><i class="dashicons dashicons-minus"></i></a></span>';
1876 $output .= '</div>';
1877 $output .= '<input type="hidden" name="form_id" value="' . esc_attr( $form_id ) . '">';
1878 $output .= '<span class="evf_import_entries_btn"><input type="submit" class="everest-forms-btn everest-forms-btn-primary evf-import-entries-btn" value="' . esc_html__( 'Import Entries', 'everest-forms' ) . '"></span>';
1879 $output .= '</form>';
1880 $output .= '</div>';
1881
1882 wp_send_json_success(
1883 array(
1884 'html' => $output,
1885 )
1886 );
1887 }
1888
1889 /**
1890 * Retrieves the header of a CSV file.
1891 *
1892 * The function reads the contents of the CSV file, splits it into an array of lines, and retrieves
1893 * the first line, which represents the header of the CSV file. It then sends a JSON success
1894 * response with the header as an array of values.
1895 *
1896 * @since 3.0.0
1897 *
1898 * @param array $csv_data The CSV data containing the file to be processed.
1899 */
1900 public static function get_csv_header( $csv_data ) {
1901
1902 if ( ! isset( $csv_data['csvfile'] ) ) {
1903 wp_send_json_error(
1904 array(
1905 'message' => 'Please upload csv file.',
1906 )
1907 );
1908 }
1909
1910 $file_extension = strtolower( pathinfo( $csv_data['csvfile']['name'], PATHINFO_EXTENSION ) );
1911
1912 if ( 'csv' !== $file_extension ) {
1913 wp_send_json_error(
1914 array(
1915 'message' => 'File must be a CSV file.',
1916 )
1917 );
1918 }
1919
1920 if ( ! function_exists( 'wp_handle_upload' ) ) {
1921 require_once ABSPATH . 'wp-admin/includes/file.php';
1922 }
1923
1924 $upload_dir = wp_upload_dir();
1925 $filename = 'import_entries_data.csv';
1926 $csv_url = $upload_dir['basedir'] . $upload_dir['subdir'] . '/' . $filename;
1927
1928 // Remove existing file if already exists
1929 if ( ! empty( $csv_url ) && file_exists( $csv_url ) ) {
1930 @unlink( $csv_url );
1931 }
1932
1933 // Move uploaded file to uploads directory
1934 $csv_file = $csv_data['csvfile']['tmp_name'];
1935 $upload_file = move_uploaded_file( $csv_file, $csv_url );
1936
1937 if ( ! $upload_file || ! file_exists( $csv_url ) ) {
1938 wp_send_json_error(
1939 array(
1940 'message' => 'File upload failed.',
1941 )
1942 );
1943 }
1944
1945 // Use fgetcsv to safely parse the header
1946 $handle = fopen( $csv_url, 'r' );
1947 if ( ! $handle ) {
1948 wp_send_json_error(
1949 array(
1950 'message' => 'Unable to open uploaded CSV file.',
1951 )
1952 );
1953 }
1954
1955 $csv_header = fgetcsv( $handle );
1956 fclose( $handle );
1957
1958 if ( empty( $csv_header ) ) {
1959 wp_send_json_error(
1960 array(
1961 'message' => 'CSV file doesn\'t contain any header row.',
1962 )
1963 );
1964 }
1965
1966 return $csv_header;
1967 }
1968
1969
1970 /**
1971 * Import entries from the CSV file and process them in the background.
1972 *
1973 * This function checks the AJAX referer and retrieves the mapping fields array from the POST data.
1974 * It then reads the CSV file and processes each row, updating the options and pushing the data to the background process queue.
1975 * Finally, it sends a JSON success response with a message and a link to the imported entries.
1976 *
1977 * @since 3.0.0
1978 *
1979 * @throws Exception If an error occurs during the import process.
1980 */
1981 public static function import_entries() {
1982 try {
1983 check_ajax_referer( 'evf-import-entries', 'security' );
1984
1985 $map_fields_array = array();
1986
1987 if ( ! isset( $_POST['data'] ) ) {
1988 wp_send_json_error(
1989 array(
1990 'message' => 'Something went wrong. Please try again.',
1991 )
1992 );
1993 }
1994
1995 $data = ! empty($_POST['data']) ? $_POST['data'] : array(); //phpcs:ignore
1996
1997 if ( empty( $data ) ) {
1998 wp_send_json_error(
1999 array(
2000 'message' => 'Something went wrong. Please try again.',
2001 )
2002 );
2003 }
2004
2005 foreach ( $data as $key => $map_fields ) {
2006 if ( count( $data ) - 1 === $key ) {
2007 $map_fields_array['form_id'] = sanitize_text_field(wp_unslash($map_fields['value'])); //phpcs:ignore
2008 continue;
2009 }
2010
2011 if ( 0 != $key % 2 ) {
2012 continue;
2013 }
2014
2015 $map_fields_array[ $key ] = array(
2016 'field_id' => sanitize_text_field(wp_unslash($map_fields['value'])), //phpcs:ignore
2017 'map_csv_column' => sanitize_text_field(wp_unslash($data[++$key]['value'])), //phpcs:ignore
2018 );
2019 }
2020
2021 $upload_dir = wp_upload_dir();
2022 $filename = 'import_entries_data.csv';
2023 $csv_url = $upload_dir['basedir'] . $upload_dir['subdir'] . '/' . $filename;
2024
2025 if ( ! empty( $csv_url ) && file_exists( $csv_url ) ) {
2026 $csv_file = fopen( $csv_url, 'r' );
2027 $row = 0;
2028 update_option( 'everest_forms_mapping_fields_array', $map_fields_array );
2029 while ( ( $row_data = fgetcsv( $csv_file, 0, ',' ) ) !== false ) {
2030 if ( strlen( implode( $row_data ) ) != 0 ) {
2031 if ( 0 === $row ) {
2032 update_option( 'everest_forms_csv_titles', $row_data );
2033 } else {
2034 self::$background_process->push_to_queue( $row_data );
2035 }
2036 ++$row;
2037 }
2038 }
2039 fclose( $csv_file );
2040 unlink( $csv_url );
2041 $test = self::$background_process->save()->dispatch();
2042 }
2043
2044 wp_send_json_success(
2045 array(
2046 'message' => 'Your data is currently being imported in the background. Please check the imported entries shortly.',
2047 'entry_link' => admin_url( 'admin.php?page=evf-entries&form_id=' . $map_fields_array['form_id'] ),
2048 'button_text' => 'View Entries',
2049 )
2050 );
2051 } catch ( Exception $e ) {
2052 wp_send_json_error(
2053 array(
2054 'message' => $e->getMessage(),
2055 )
2056 );
2057 }
2058 }
2059 /**
2060 * Generate the restapi key
2061 *
2062 * @since 3.0.5
2063 */
2064 public static function generate_restapi_key() {
2065 try {
2066 check_ajax_referer( 'process-restapi-api-ajax-nonce', 'security' );
2067 $key = generate_api_key();
2068 wp_send_json_success( $key );
2069 } catch ( Exception $e ) {
2070 wp_send_json_error(
2071 array(
2072 'message' => $e->getMessage(),
2073 )
2074 );
2075 }
2076 }
2077
2078 /**
2079 * Installs and activates the Smart SMTP plugin.
2080 *
2081 * @since 3.0.9
2082 *
2083 * @return void Outputs a JSON response.
2084 */
2085 public static function install_and_activate_smart_smtp() {
2086 try {
2087 check_ajax_referer( 'everest-forms-smart-smtp-installation-nonce', 'security' );
2088 if ( ! current_user_can( 'manage_everest_forms' ) ) {
2089 wp_send_json_error( array( 'message' => 'You do not have permission to install plugins.' ) );
2090 }
2091
2092 if ( is_plugin_active( 'smart-smtp/smart-smtp.php' ) ) {
2093 wp_send_json_success( array( 'message' => 'SmartSMTP plugin is already activated!' ) );
2094 }
2095
2096 $installed_plugins = get_plugins();
2097
2098 if ( array_key_exists( 'smart-smtp/smart-smtp.php', $installed_plugins ) ) {
2099 $activate_result = activate_plugin( 'smart-smtp/smart-smtp.php' );
2100 if ( is_wp_error( $activate_result ) ) {
2101 $error_message = $activate_result->get_error_message();
2102 wp_send_json_error(
2103 array(
2104 /* translators: %s: Error message explaining the activation failure */
2105 'message' => esc_html__( 'Sorry, we are unable to activate SmartSMTP because of %s', 'everest-forms' ),
2106 esc_html( $error_message ),
2107 )
2108 );
2109 }
2110 } else {
2111 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
2112 require_once ABSPATH . 'wp-admin/includes/file.php';
2113 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
2114
2115 $plugin_info = plugins_api( 'plugin_information', array( 'slug' => 'smart-smtp' ) );
2116 if ( is_wp_error( $plugin_info ) ) {
2117 wp_send_json_error( array( 'message' => esc_html__( 'Sorry, your internet connection was interrupted', 'everest-forms' ) ) );
2118 }
2119
2120 $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
2121 $install_result = $upgrader->install( $plugin_info->download_link );
2122 if ( is_wp_error( $install_result ) ) {
2123 $installation_error = $install_result->get_error_message();
2124 wp_send_json_error(
2125 array(
2126 /* translators: %s: Error message explaining the installation failure */
2127 'message' => esc_html__( 'Plugin installation failed due to %s', 'everest-forms' ),
2128 esc_html( $installation_error ),
2129 )
2130 );
2131 }
2132
2133 $activate_result = activate_plugin( 'smart-smtp/smart-smtp.php' );
2134 }
2135
2136 if ( is_wp_error( $activate_result ) ) {
2137 wp_send_json_error( array( 'message' => 'Plugin activation failed: ' . $activate_result->get_error_message() ) );
2138 }
2139
2140 wp_send_json_success(
2141 array(
2142 'message' => 'SmartSMTP plugin installed and activated successfully!',
2143 'redirection_url' => evf_get_smart_smtp_google_workspace_setup_url(),
2144 )
2145 );
2146 } catch ( Exception $e ) {
2147 wp_send_json_error( array( 'message' => $e->getMessage() ) );
2148 }
2149 }
2150
2151 /**
2152 * Get form settings theme styles
2153 */
2154 public static function form_preview_save() {
2155 check_ajax_referer( 'evf_form_preview_nonce', 'security' );
2156
2157 if ( ! current_user_can( 'manage_options' ) ) {
2158 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2159 wp_die( -1 );
2160 }
2161 $form_id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
2162 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( $_POST['theme'] ) : '';
2163
2164 if ( empty( $form_id ) || empty( $theme ) ) {
2165 wp_send_json_error( array( 'message' => __( 'Insufficient information', 'everest-forms' ) ) );
2166 }
2167
2168 $default_theme = ( 'default' === $theme ) ? 'default' : 'theme';
2169 update_post_meta( $form_id, 'everest_forms_enable_theme_style', $default_theme );
2170
2171 wp_send_json_success( array( 'message' => __( 'Saved', 'everest-forms' ) ) );
2172 }
2173 /**
2174 * Delete the tags.
2175 *
2176 * @since 3.2.0
2177 */
2178 public static function delete_form_tags() {
2179 check_ajax_referer( 'ajax_manage_tags_nonce', 'security' );
2180
2181 if ( ! current_user_can( 'manage_options' ) ) {
2182 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2183 wp_die( -1 );
2184 }
2185
2186 $tags = isset( $_POST['tags'] ) ? array_map( 'absint', $_POST['tags'] ) : array();
2187
2188 if ( empty( $tags ) ) {
2189 wp_send_json_error( array( 'message' => __( 'Missing tags.', 'everest-forms' ) ) );
2190 }
2191
2192 foreach ( $tags as $tag ) {
2193 wp_delete_term( $tag, EVF_Post_Types::TAGS_TAXONOMY );
2194 }
2195
2196 wp_send_json_success( array( 'message' => __( 'Tags are deleted successfully.', 'everest-forms' ) ) );
2197 }
2198
2199 /**
2200 * Update tags in bulk.
2201 *
2202 * @since 3.2.0
2203 */
2204 public static function update_tags_in_bulk() {
2205 check_ajax_referer( 'ajax_manage_tags_nonce', 'security' );
2206
2207 if ( ! current_user_can( 'manage_options' ) ) {
2208 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2209 wp_die( -1 );
2210 }
2211
2212 $tags = isset( $_POST['tags'] ) ? $_POST['tags'] : array();
2213 $forms = isset( $_POST['forms'] ) ? array_map( 'absint', $_POST['forms'] ) : array();
2214
2215 if ( empty( $forms ) ) {
2216 wp_send_json_error( array( 'message' => __( 'Please select atleast on form to updat the tags.', 'everest-forms' ) ) );
2217 }
2218
2219 $term_ids = array();
2220
2221 foreach ( $tags as $tag_name ) {
2222 if ( is_numeric( $tag_name ) ) {
2223 $term = get_term( absint( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
2224 if ( $term && ! is_wp_error( $term ) ) {
2225 $term_ids[] = $term->term_id;
2226 continue;
2227 }
2228 }
2229
2230 $term = term_exists( $tag_name, EVF_Post_Types::TAGS_TAXONOMY );
2231 if ( $term === null ) {
2232 $term = wp_insert_term( sanitize_text_field( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
2233 }
2234 if ( ! is_wp_error( $term ) ) {
2235 $term_ids[] = is_array( $term ) ? (int) $term['term_id'] : $term;
2236 }
2237 }
2238
2239 foreach ( $forms as $id ) {
2240 wp_set_post_terms( $id, $term_ids, EVF_Post_Types::TAGS_TAXONOMY, false );
2241 }
2242
2243 wp_send_json_success( array( 'message' => __( 'Tags are updated successfully.', 'everest-forms' ) ) );
2244 }
2245
2246 /**
2247 * Save the clean talk settings.
2248 *
2249 * @since 3.2.0
2250 */
2251 public static function save_clean_talk_settings() {
2252 check_ajax_referer( 'everest_forms_clean_talk_nonce', 'security' );
2253
2254 if ( ! current_user_can( 'manage_options' ) ) {
2255 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2256 wp_die( -1 );
2257 }
2258
2259 if ( isset( $_POST['action'] ) && 'everest_forms_save_clean_talk_settings' != $_POST['action'] ) {
2260 wp_send_json_error( array( 'message' => __( 'Action doesn\'t match.', 'everest-forms' ) ) );
2261 wp_die( -1 );
2262 }
2263
2264 $form_data = isset( $_POST['form_data'] ) ? $_POST['form_data'] : '';
2265
2266 if ( empty( $form_data ) ) {
2267 wp_send_json_error( array( 'message' => __( 'Insufficient information', 'everest-forms' ) ) );
2268 }
2269
2270 $access_key = isset( $form_data['access_key'] ) ? sanitize_text_field( wp_unslash( $form_data['access_key'] ) ) : '';
2271
2272 $output = '';
2273 if ( empty( $access_key ) ) {
2274 $output .= '<span class="everest-forms-clean-talk-icon-box">
2275 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2276 <path d="M8.125 8.125L11.875 11.875M11.875 8.125L8.125 11.875M17.5 10C17.5 10.9849 17.306 11.9602 16.9291 12.8701C16.5522 13.7801 15.9997 14.6069 15.3033 15.3033C14.6069 15.9997 13.7801 16.5522 12.8701 16.9291C11.9602 17.306 10.9849 17.5 10 17.5C9.01509 17.5 8.03982 17.306 7.12987 16.9291C6.21993 16.5522 5.39314 15.9997 4.6967 15.3033C4.00026 14.6069 3.44781 13.7801 3.0709 12.8701C2.69399 11.9602 2.5 10.9849 2.5 10C2.5 8.01088 3.29018 6.10322 4.6967 4.6967C6.10322 3.29018 8.01088 2.5 10 2.5C11.9891 2.5 13.8968 3.29018 15.3033 4.6967C16.7098 6.10322 17.5 8.01088 17.5 10Z" stroke="#F75259" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
2277 </svg>
2278 </span>';
2279 $output .= '<span class="everest-forms-clean-talk-message-box">Please enter the CleanTalk access key.</span>';
2280 $output .= '</div>';
2281 wp_send_json_error(
2282 array(
2283 'error' => 'empty',
2284 'html' => $output,
2285 )
2286 );
2287 }
2288
2289 $clean_talk_request = array(
2290 'method_name' => 'notice_paid_till',
2291 'auth_key' => $access_key,
2292 );
2293
2294 $response = wp_remote_post(
2295 'https://api.cleantalk.org/',
2296 array(
2297 'body' => \http_build_query( $clean_talk_request, true ),
2298 'headers' => array(
2299 'Content-Type' => 'application/x-www-form-urlencoded',
2300 ),
2301 )
2302 );
2303 $response = json_decode( wp_remote_retrieve_body( $response ) );
2304
2305 if ( $response->data->moderate == 1 && $response->data->valid == 1 && $response->data->product_id == 1 ) {
2306 update_option( 'everest_forms_recaptcha_cleantalk_access_key', $access_key );
2307
2308 $output .= '<span class="everest-forms-clean-talk-icon-box">
2309 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2310 <path d="M7.5 10.625L9.375 12.5L12.5 8.125M17.5 10C17.5 10.9849 17.306 11.9602 16.9291 12.8701C16.5522 13.7801 15.9997 14.6069 15.3033 15.3033C14.6069 15.9997 13.7801 16.5522 12.8701 16.9291C11.9602 17.306 10.9849 17.5 10 17.5C9.01509 17.5 8.03982 17.306 7.12987 16.9291C6.21993 16.5522 5.39314 15.9997 4.6967 15.3033C4.00026 14.6069 3.44781 13.7801 3.0709 12.8701C2.69399 11.9602 2.5 10.9849 2.5 10C2.5 8.01088 3.29018 6.10322 4.6967 4.6967C6.10322 3.29018 8.01088 2.5 10 2.5C11.9891 2.5 13.8968 3.29018 15.3033 4.6967C16.7098 6.10322 17.5 8.01088 17.5 10Z" stroke="#4CC741" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
2311 </svg>
2312 </span>';
2313 $output .= '<span class="everest-forms-clean-talk-message-box">Settings saved successfully.</span>';
2314 $output .= '</div>';
2315
2316 wp_send_json_success(
2317 array(
2318 'html' => $output,
2319 )
2320 );
2321 } else {
2322 $output .= '<span class="everest-forms-clean-talk-icon-box">
2323 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2324 <path d="M8.125 8.125L11.875 11.875M11.875 8.125L8.125 11.875M17.5 10C17.5 10.9849 17.306 11.9602 16.9291 12.8701C16.5522 13.7801 15.9997 14.6069 15.3033 15.3033C14.6069 15.9997 13.7801 16.5522 12.8701 16.9291C11.9602 17.306 10.9849 17.5 10 17.5C9.01509 17.5 8.03982 17.306 7.12987 16.9291C6.21993 16.5522 5.39314 15.9997 4.6967 15.3033C4.00026 14.6069 3.44781 13.7801 3.0709 12.8701C2.69399 11.9602 2.5 10.9849 2.5 10C2.5 8.01088 3.29018 6.10322 4.6967 4.6967C6.10322 3.29018 8.01088 2.5 10 2.5C11.9891 2.5 13.8968 3.29018 15.3033 4.6967C16.7098 6.10322 17.5 8.01088 17.5 10Z" stroke="#F75259" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
2325 </svg>
2326 </span>';
2327 $output .= '<span class="everest-forms-clean-talk-message-box">Invalid CleanTalk access key.</span>';
2328 $output .= '</div>';
2329 wp_send_json_error(
2330 array(
2331 'error' => 'invalid',
2332 'html' => $output,
2333 )
2334 );
2335 }
2336 }
2337 /**
2338 * This callback give the update nonce of the form.
2339 *
2340 * @since 3.3.0
2341 */
2342 public static function get_form_update_nonce() {
2343 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
2344
2345 if ( empty( $form_id ) ) {
2346 wp_die( __( 'Form ID is missing!', 'everest-forms' ), 403 );
2347 }
2348
2349 $form = evf()->form->get( $form_id );
2350
2351 if ( empty( $form ) ) {
2352 wp_die( __( 'Form not found!', 'everest-forms' ), 403 );
2353 }
2354
2355 // Strict referer verification
2356 $referer = wp_get_referer();
2357 $allowed_host = parse_url( home_url(), PHP_URL_HOST );
2358 $referer_host = parse_url( $referer, PHP_URL_HOST );
2359
2360 if ( ! $referer || $referer_host !== $allowed_host ) {
2361 wp_die( __( 'Invalid form submission source.', 'everest-forms' ), 403 );
2362 }
2363
2364 wp_send_json_success( wp_create_nonce( 'everest-forms_process_submit' ) );
2365 }
2366 }
2367
2368 EVF_AJAX::init();
2369