PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 3.5.3
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v3.5.3
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 1 week ago RestApi 1 month ago abilities 1 month ago abstracts 1 month ago admin 1 week 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 1 month ago stats 6 months ago templates 4 months ago traits 1 month ago class-everest-forms.php 1 week ago class-evf-addon-upsell.php 1 month ago class-evf-ajax.php 1 week 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 1 month ago class-evf-fields.php 1 month ago class-evf-form-handler.php 1 month ago class-evf-form-task.php 1 month ago class-evf-forms-features.php 1 month ago class-evf-frontend-scripts.php 1 month 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 10 months ago class-evf-template-loader.php 1 year ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 1 month 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
2365 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 do_action( 'everest_forms_integration_account_disconnect_' . ( isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '' ), $_POST );
1044
1045 $connected_accounts = get_option( 'everest_forms_integrations', false );
1046
1047 if ( ! empty( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] ) ) {
1048 unset( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] );
1049 update_option( 'everest_forms_integrations', $connected_accounts );
1050 wp_send_json_success( array( 'remove' => true ) );
1051 } else {
1052 wp_send_json_error(
1053 array(
1054 'error' => esc_html__( 'Connection missing', 'everest-forms' ),
1055 )
1056 );
1057 }
1058 }
1059
1060 /**
1061 * Triggered when clicking the rating footer.
1062 */
1063 public static function rated() {
1064 check_ajax_referer( 'everest_forms_rated', 'security' );
1065
1066 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1067 wp_die( -1 );
1068 }
1069 update_option( 'everest_forms_admin_footer_text_rated', 1 );
1070 wp_die();
1071 }
1072
1073 /**
1074 * Triggered when clicking the review notice button.
1075 */
1076 public static function review_dismiss() {
1077 check_ajax_referer( 'everest_forms_review_dismiss', 'security' );
1078
1079 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1080 wp_die( -1 );
1081 }
1082 $review = get_option( 'everest_forms_review', array() );
1083 $review['time'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
1084 $review['dismissed'] = true;
1085 update_option( 'everest_forms_review', $review );
1086 wp_die();
1087 }
1088
1089 /**
1090 * Triggered when clicking the survey notice button.
1091 */
1092 public static function survey_dismiss() {
1093 check_ajax_referer( 'everest_forms_survey_dismiss', 'security' );
1094
1095 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1096 wp_die( -1 );
1097 }
1098 $survey = get_option( 'everest_forms_survey', array() );
1099 $survey['dismissed'] = true;
1100 update_option( 'everest_forms_survey', $survey );
1101 wp_die();
1102 }
1103
1104 /**
1105 * Triggered when clicking the allow usage notice allow or deny buttons.
1106 */
1107 public static function allow_usage_dismiss() {
1108 check_ajax_referer( 'allow_usage_nonce', '_wpnonce' );
1109
1110 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1111 wp_die( -1 );
1112 }
1113
1114 $allow_usage_tracking = isset( $_POST['allow_usage_tracking'] ) ? sanitize_text_field( wp_unslash( $_POST['allow_usage_tracking'] ) ) : false;
1115
1116 update_option( 'everest_forms_allow_usage_notice_shown', true );
1117
1118 if ( 'true' === $allow_usage_tracking ) {
1119 update_option( 'everest_forms_allow_usage_tracking', 'yes' );
1120 }
1121
1122 wp_die();
1123 }
1124
1125 /**
1126 * Triggered when clicking the PHP deprecation notice.
1127 */
1128 public static function php_notice_dismiss() {
1129 check_ajax_referer( 'php_notice_nonce', '_wpnonce' );
1130
1131 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1132 wp_die( -1 );
1133 }
1134 $current_date = gmdate( 'Y-m-d' );
1135 $prompt_count = get_option( 'everest_forms_php_deprecated_notice_prompt_count', 0 );
1136
1137 update_option( 'everest_forms_php_deprecated_notice_last_prompt_date', $current_date );
1138 update_option( 'everest_forms_php_deprecated_notice_prompt_count', ++$prompt_count );
1139 wp_die();
1140 }
1141
1142
1143 /**
1144 * Triggered when clicking the email failed notice.
1145 */
1146 public static function email_failed_notice_dismiss() {
1147 check_ajax_referer( 'email_failed_nonce', '_wpnonce' );
1148
1149 if ( ! current_user_can( 'manage_everest_forms' ) ) {
1150 wp_die( -1 );
1151 }
1152 update_option( 'everest_forms_email_send_notice_dismiss', true );
1153 wp_die();
1154 }
1155
1156 /**
1157 * Triggered when clicking the form toggle.
1158 */
1159 public static function enabled_form() {
1160 // Run a security check.
1161 check_ajax_referer( 'everest_forms_enabled_form', 'security' );
1162
1163 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
1164 $enabled = isset( $_POST['enabled'] ) ? absint( $_POST['enabled'] ) : 0;
1165
1166 if ( ! current_user_can( 'everest_forms_edit_form', $form_id ) ) {
1167 wp_die( -1 );
1168 }
1169
1170 /**
1171 * Update the form status in post table.
1172 *
1173 * @since 3.2.0
1174 */
1175 $new_status = $enabled ? 'publish' : 'inactive';
1176
1177 $result = wp_update_post(
1178 array(
1179 'ID' => $form_id,
1180 'post_status' => $new_status,
1181 ),
1182 true
1183 );
1184
1185 if ( is_wp_error( $result ) ) {
1186 wp_send_json_error( $result->get_error_message(), 500 );
1187 }
1188
1189 $form_data = evf()->form->get( absint( $form_id ), array( 'content_only' => true ) );
1190
1191 $form_data['form_enabled'] = $enabled;
1192
1193 evf()->form->update( $form_id, $form_data );
1194 }
1195
1196 /**
1197 * Import Form ajax.
1198 */
1199 public static function import_form_action() {
1200 try {
1201 check_ajax_referer( 'process-import-ajax-nonce', 'security' );
1202 EVF_Admin_Import_Export::import_forms();
1203 } catch ( Exception $e ) {
1204 wp_send_json_error(
1205 array(
1206 'message' => $e->getMessage(),
1207 )
1208 );
1209 }
1210 }
1211
1212 /**
1213 * Send test email.
1214 */
1215 public static function send_test_email() {
1216 try {
1217 if ( ! current_user_can( 'manage_options' ) ) {
1218 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1219 }
1220
1221 check_ajax_referer( 'process-ajax-nonce', 'security' );
1222 $from = esc_attr( get_bloginfo( 'name', 'display' ) );
1223 $email = sanitize_email( isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '' );
1224
1225 /* translators: %s: from address */
1226 $subject = 'Everest Form: ' . sprintf( esc_html__( 'Test email from %s', 'everest-forms' ), $from );
1227 $header = "Reply-To: {{from}} \r\n";
1228 $header .= 'Content-Type: text/html; charset=UTF-8';
1229 $message = sprintf(
1230 '%s <br /> %s <br /> %s <br /> %s <br /> %s',
1231 __( 'Congratulations,', 'everest-forms' ),
1232 __( 'Your test email has been received successfully.', 'everest-forms' ),
1233 __( 'We thank you for trying out Everest Forms and joining our mission to make sure you get your emails delivered.', 'everest-forms' ),
1234 __( 'Regards,', 'everest-forms' ),
1235 __( 'Everest Forms Team', 'everest-forms' )
1236 );
1237 $status = wp_mail( $email, $subject, $message, $header );
1238 if ( $status ) {
1239 wp_send_json_success( array( 'message' => __( 'Test email was sent successfully! Please check your inbox to make sure it is delivered.', 'everest-forms' ) ) );
1240 } else {
1241 wp_send_json_error( array( 'message' => __( 'Test email was unsuccessful! Something went wrong.', 'everest-forms' ) ) );
1242 }
1243 } catch ( Exception $e ) {
1244 wp_send_json_error(
1245 array(
1246 'message' => $e->getMessage(),
1247 )
1248 );
1249 }
1250 }
1251
1252 /**
1253 * Send stat routine test email.
1254 *
1255 * @since 2.0.9
1256 */
1257 public static function send_routine_report_test_email() {
1258 try {
1259 if ( ! current_user_can( 'manage_options' ) ) {
1260 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1261 }
1262
1263 check_ajax_referer( 'process-ajax-nonce', 'security' );
1264
1265 $frequency = get_option( 'everest_forms_entries_reporting_frequency', 'Weekly' );
1266 if ( ! in_array( $frequency, array( 'Daily', 'Weekly', 'Monthly' ), true ) ) {
1267 $frequency = 'Weekly';
1268 }
1269
1270 $test_email = sanitize_email( get_option( 'everest_forms_routine_report_send_email_test_to', '' ) );
1271 if ( empty( $test_email ) ) {
1272 $test_email = sanitize_email( get_bloginfo( 'admin_email' ) );
1273 }
1274
1275 $subject = get_option( 'everest_forms_entries_reporting_subject', __( 'Everest Forms - Entries summary statistics', 'everest-forms' ) );
1276 if ( empty( trim( $subject ) ) ) {
1277 $subject = __( 'Everest Forms - Entries summary statistics', 'everest-forms' );
1278 }
1279 $subject = sprintf( __( '[TEST] %s', 'everest-forms' ), $subject );
1280
1281 $email_builder = new EVF_Email_Entries_Report( $frequency, null, true );
1282 $html_message = $email_builder->render_html();
1283
1284 $headers = array(
1285 'Content-Type: text/html; charset=UTF-8',
1286 'From: ' . wp_specialchars_decode( get_bloginfo( 'name' ) ) . ' <' . get_option( 'admin_email' ) . '>',
1287 );
1288
1289 $sent = wp_mail( $test_email, $subject, $html_message, $headers );
1290
1291 if ( $sent ) {
1292 wp_send_json_success(
1293 array(
1294 'message' => sprintf(
1295 __( 'Test report sent to %s. Please check your inbox.', 'everest-forms' ),
1296 $test_email
1297 ),
1298 )
1299 );
1300 } else {
1301 wp_send_json_error( array( 'message' => __( 'Test email could not be sent. Please check your site email configuration.', 'everest-forms' ) ) );
1302 }
1303 } catch ( Exception $e ) {
1304 wp_send_json_error( array( 'message' => $e->getMessage() ) );
1305 }
1306 }
1307
1308 /**
1309 * Manually trigger a full entries report send immediately.
1310 *
1311 * Sends to the configured scheduled recipient (not the test address).
1312 * Logged to report history as type 'manual'.
1313 *
1314 * @since 2.0.9
1315 */
1316 public static function send_manual_report() {
1317 try {
1318 if ( ! current_user_can( 'manage_options' ) ) {
1319 wp_send_json_error( array( 'message' => __( 'Unauthorized.', 'everest-forms' ) ), 401 );
1320 }
1321
1322 check_ajax_referer( 'process-ajax-nonce', 'security' );
1323
1324 $cron = new EVF_Report_Cron();
1325 $sent = $cron->evf_report_form_statistics_send( false );
1326
1327 if ( $sent ) {
1328 wp_send_json_success( array( 'message' => __( 'Report sent successfully.', 'everest-forms' ) ) );
1329 } else {
1330 wp_send_json_error( array( 'message' => __( 'Report could not be sent. Please check your settings and email configuration.', 'everest-forms' ) ) );
1331 }
1332 } catch ( Exception $e ) {
1333 wp_send_json_error( array( 'message' => $e->getMessage() ) );
1334 }
1335 }
1336
1337 /**
1338 * Locate form.
1339 */
1340 public static function locate_form_action() {
1341 global $wpdb;
1342 try {
1343 check_ajax_referer( 'process-locate-ajax-nonce', 'security' );
1344 $id = isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '';
1345 $everest_form_shortcode = '%[everest_form id="' . $id . '"%';
1346 $form_id_shortcode = '%{"formId":"' . $id . '"%';
1347 $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
1348 $page_list = array();
1349 foreach ( $pages as $page ) {
1350 if ( 'page' === $page->post_type || 'post' === $page->post_type ) {
1351 $page_title = $page->post_title;
1352 $page_guid = get_permalink( $page->ID );
1353 $page_list[ $page_title ] = $page_guid;
1354 }
1355 }
1356 wp_send_json_success( $page_list );
1357 } catch ( Exception $e ) {
1358 wp_send_json_error(
1359 array(
1360 'message' => $e->getMessage(),
1361 )
1362 );
1363 }
1364 }
1365 /**
1366 * Slot booking.
1367 */
1368 public static function slot_booking() {
1369 try {
1370 check_ajax_referer( 'everest_forms_slot_booking_nonce', 'security' );
1371 $datetime_value = isset( $_POST['data-time-value'] ) ? sanitize_text_field( wp_unslash( $_POST['data-time-value'] ) ) : '';
1372 $datetime_format = isset( $_POST['data-time-format'] ) ? sanitize_text_field( wp_unslash( $_POST['data-time-format'] ) ) : '';
1373 $date_format = isset( $_POST['data-format'] ) ? sanitize_text_field( wp_unslash( $_POST['data-format'] ) ) : '';
1374 $mode = isset( $_POST['mode'] ) ? sanitize_text_field( wp_unslash( $_POST['mode'] ) ) : '';
1375 $form_id = isset( $_POST['form-id'] ) ? sanitize_text_field( wp_unslash( $_POST['form-id'] ) ) : '';
1376 $time_interval = isset( $_POST['time-interval'] ) ? sanitize_text_field( wp_unslash( $_POST['time-interval'] ) ) : '';
1377 $datetime_arr = parse_datetime_values( $datetime_value, $datetime_format, $date_format, $mode, $time_interval );
1378
1379 if ( empty( $datetime_arr ) ) {
1380 wp_send_json_error(
1381 array(
1382 'message' => __( 'Please select at least one date time.', 'everest-forms' ),
1383 )
1384 );
1385 }
1386 $booked_slot = evf_maybe_unserialize( get_option( 'evf_booked_slot', '' ) );
1387 $is_booked = false;
1388 if ( ! empty( $booked_slot ) && array_key_exists( $form_id, $booked_slot ) ) {
1389 foreach ( $datetime_arr as $arr ) {
1390
1391 foreach ( $booked_slot[ $form_id ] as $key => $slot ) {
1392 if ( $arr[0] >= $slot[0] && $arr[1] <= $slot[1] ) {
1393 $is_booked = true;
1394 break;
1395 } elseif ( $arr[0] >= $slot[0] && $arr[0] < $slot[1] && $arr[1] >= $slot[1] ) {
1396 $is_booked = true;
1397 break;
1398 }
1399 }
1400 }
1401 }
1402 if ( $is_booked ) {
1403 wp_send_json_success(
1404 array(
1405 'message' => __( 'This slot is already booked. Please choose other slot', 'everest-forms' ),
1406 )
1407 );
1408 }
1409 wp_send_json_error(
1410 array(
1411 'message' => __( 'This slot is not booked.', 'everest-forms' ),
1412 )
1413 );
1414 } catch ( Exception $e ) {
1415 wp_send_json_error(
1416 array(
1417 'message' => __( 'Something went wrong.', 'everest-forms' ),
1418 )
1419 );
1420 }
1421 }
1422
1423 /**
1424 * Activate addons from builder.
1425 */
1426 public static function active_addons() {
1427 try {
1428 check_ajax_referer( 'evf_active_nonce', 'security' );
1429
1430 if ( ! current_user_can( 'activate_plugins' ) ) {
1431 wp_send_json_error(
1432 array(
1433 'message' => esc_html__( 'You do not have permission to activate plugins.', 'everest-forms' ),
1434 )
1435 );
1436 }
1437
1438 $plugin = isset( $_POST['plugin_file'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_file'] ) ) : '';
1439 $slug = dirname( $plugin );
1440
1441 // Restrict activation to genuine Everest Forms addons so this endpoint
1442 // cannot be used to activate arbitrary installed plugins.
1443 if ( '' === $plugin || ! in_array( $slug, EVF_Modules::get_allowed_addon_slugs(), true ) ) {
1444 wp_send_json_error(
1445 array(
1446 'message' => esc_html__( 'The requested module is not a valid Everest Forms addon.', 'everest-forms' ),
1447 )
1448 );
1449 }
1450
1451 $activate = activate_plugin( $plugin );
1452 if ( is_wp_error( $activate ) ) {
1453 $activation_error = $activate->get_error_message();
1454 wp_send_json_error(
1455 array(
1456 'message' => $activation_error,
1457 )
1458 );
1459 } else {
1460 wp_send_json_success(
1461 array(
1462 'message' => __( 'Activated successfully', 'everest-forms' ),
1463 )
1464 );
1465 }
1466 } catch ( Exception $e ) {
1467 wp_send_json_error(
1468 array(
1469 'message' => $e->getMessage(),
1470 )
1471 );
1472 }
1473 }
1474
1475 /**
1476 * Download the provided font and return the url for font file.
1477 *
1478 * @since 2.0.8
1479 */
1480 public static function get_local_font_url() {
1481 $font_url = isset( $_POST['font_url'] ) ? sanitize_text_field( wp_unslash( $_POST['font_url'] ) ) : ''; //phpcs:ignore WordPress.Security.NonceVerification
1482
1483 $allowed_urls = array(
1484 'https://fonts.googleapis.com',
1485 );
1486
1487 if ( ! in_array( $font_url, $allowed_urls ) ) {
1488 return;
1489 }
1490
1491 if ( str_contains( $font_url, 'https://fonts.googleapis.com' ) ) {
1492 $font_url = evf_maybe_get_local_font_url( $font_url );
1493 }
1494
1495 return wp_send_json_success( $font_url );
1496 }
1497
1498 /**
1499 * Forms list for form migrator.
1500 *
1501 * @since 2.0.8
1502 *
1503 * @throws Exception If there is an error.
1504 */
1505 public static function form_migrator_forms_list() {
1506 try {
1507 check_ajax_referer( 'evf_form_migrator_forms_list_nonce', 'security' );
1508
1509 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1510 if ( '' === $form_slug ) {
1511 wp_send_json_error(
1512 array(
1513 'message' => __( 'Missing form slug !', 'everest-forms' ),
1514 )
1515 );
1516 }
1517
1518 // Creating the form instance and getting the form list.
1519 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1520
1521 if ( ! class_exists( $class_name ) ) {
1522 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1523 throw new Exception( $except_message );
1524 }
1525
1526 $form_instance = new $class_name();
1527 $forms_list = $form_instance->get_forms();
1528
1529 if ( empty( $forms_list ) ) {
1530 wp_send_json_error(
1531 array(
1532 'message' => esc_html( 'No forms are currently available in the list !!!', 'everest-forms' ),
1533 )
1534 );
1535 }
1536 $row = 0;
1537 $form_per_page = 5;
1538 $ceil = ceil( count( $forms_list ) / $form_per_page );
1539 $forms_list_table = '<div class="evf-fm-forms-table-wrapper">';
1540 $forms_list_table .= '<h4>' . sprintf( '%s %s', esc_html__( 'Import', 'everest-forms' ), $form_instance->name ) . '</h4>';
1541 $forms_list_table .= '<table class="evf-fm-forms-table" data-form-slug="' . esc_attr( $form_slug ) . '">';
1542 $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>';
1543 $hidden = '';
1544 $imported = get_option( 'evf_fm_' . $form_slug . '_imported_form_list', array() );
1545 foreach ( $forms_list as $form_id => $form_name ) {
1546 ++$row;
1547 if ( in_array( $form_id, $imported ) ) {
1548 $is_imported = true;
1549 $imported_text = esc_html__( 'Yes', 'everest-forms' );
1550 } else {
1551 $is_imported = false;
1552 $imported_text = esc_html__( 'No', 'everest-forms' );
1553 }
1554 $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>';
1555 $forms_list_table .= '<td>';
1556 $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>';
1557 if ( 'contact-form-7' !== $form_slug ) {
1558 $disabled = $is_imported ? '' : 'disabled';
1559 $forms_list_table .= '<button class="evf-fm-import-entry" data-form-id="' . esc_attr( $form_id ) . '"' . esc_attr( $disabled ) . '>' . esc_html( 'Import Entry' ) . '</button>';
1560 }
1561 $forms_list_table .= '</div></td></tr>';
1562 if ( $row === $form_per_page ) {
1563 $hidden = 'evf-fm-hide-row';
1564 }
1565 }
1566 $forms_list_table .= '</table>';
1567 $forms_list_table .= '<div class="evf-fm-import-selected-wrapper"><button class="evf-fm-import-selected-btn">' . esc_html( 'Import Selected Forms' ) . '</button>';
1568 $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">';
1569
1570 for ( $page = 1; $page <= $ceil; $page++ ) {
1571 $active = '';
1572 if ( 1 === $page ) {
1573 $active = 'evf-fm-btn-active';
1574 }
1575 $forms_list_table .= '<button class="evf-fm-page ' . esc_attr( $active ) . '" data-page="' . esc_attr( $page ) . '">' . esc_attr( $page ) . '</button>';
1576 }
1577 $forms_list_table .= '</div></div>';
1578 $forms_list_table .= '</div>';
1579 wp_send_json_success(
1580 array(
1581 'message' => esc_html__( 'All Forms List', 'everest-forms' ),
1582 'forms_list_table' => $forms_list_table,
1583 )
1584 );
1585 } catch ( Exception $e ) {
1586 wp_send_json_error(
1587 array(
1588 'message' => $e->getMessage(),
1589 )
1590 );
1591 }
1592 }
1593
1594 /**
1595 * Form migrator.
1596 *
1597 * @since 2.0.8
1598 *
1599 * @throws Exception If there is an error.
1600 */
1601 public static function form_migrator() {
1602 try {
1603 check_ajax_referer( 'evf_form_migrator_nonce', 'security' );
1604 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1605 $form_ids = isset( $_POST['form_ids'] ) ? wp_unslash( $_POST['form_ids'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1606 if ( '' === $form_ids ) {
1607 wp_send_json_error(
1608 array(
1609 'message' => __( 'Missing Form ID !!!', 'everest-forms' ),
1610 )
1611 );
1612 }
1613
1614 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1615
1616 if ( ! class_exists( $class_name ) ) {
1617 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1618 throw new Exception( $except_message );
1619 }
1620 // Create the instance of class.
1621 $form_instance = new $class_name();
1622 $forms_data = $form_instance->get_fm_mapped_form_data( $form_ids );
1623
1624 if ( 1 === count( $forms_data ) ) {
1625 wp_send_json_success(
1626 array(
1627 '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' ) ),
1628 'form_data' => $forms_data,
1629 )
1630 );
1631 } else {
1632 wp_send_json_success(
1633 array(
1634 'message' => __( 'Imported Successfully', 'everest-forms' ),
1635 'form_data' => $forms_data,
1636 )
1637 );
1638 }
1639 } catch ( Exception $e ) {
1640 wp_send_json_error(
1641 array(
1642 'message' => $e->getMessage(),
1643 )
1644 );
1645 }
1646 }
1647 /**
1648 * Dismiss Form migrator notice.
1649 *
1650 * @since 2.0.8
1651 */
1652 public static function fm_dismiss_notice() {
1653 try {
1654 check_ajax_referer( 'evf_fm_dismiss_notice_nonce', 'security' );
1655 $option_id = isset( $_POST['option_id'] ) ? sanitize_text_field( $_POST['option_id'] ) : ''; //phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash
1656 update_option( $option_id, true );
1657
1658 wp_send_json_success(
1659 array(
1660 'message' => __( 'Updated !', 'everest-forms' ),
1661 )
1662 );
1663 } catch ( Exception $e ) {
1664 wp_send_json_error(
1665 array(
1666 'message' => $e->getMessage(),
1667 )
1668 );
1669 }
1670 }
1671 /**
1672 * Form entry migrator.
1673 *
1674 * @since 2.0.8
1675 *
1676 * @throws Exception If there is an error.
1677 */
1678 public static function form_entry_migrator() {
1679 try {
1680 check_ajax_referer( 'evf_form_entry_migrator_nonce', 'security' );
1681 if ( ! wpforms()->is_pro() ) {
1682 wp_send_json_error(
1683 array(
1684 'message' => esc_html__( 'Entries not available in WPForms Lite.', 'everest-forms' ),
1685 )
1686 );
1687 }
1688 $form_id = isset( $_POST['form_id'] ) ? sanitize_text_field( wp_unslash( $_POST['form_id'] ) ) : '';
1689 $form_slug = isset( $_POST['form_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['form_slug'] ) ) : '';
1690
1691 if ( empty( $form_id ) || empty( $form_slug ) ) {
1692
1693 wp_send_json_error(
1694 array(
1695 'message' => __( 'Invalid Request !!', 'everest-forms' ),
1696 )
1697 );
1698 }
1699
1700 $migrated_form_list = get_option( 'evf_fm_' . $form_slug . '_imported_form_list', array() );
1701 $evf_form_id = array_search( $form_id, $migrated_form_list );
1702
1703 if ( ! $evf_form_id ) {
1704 wp_send_json_error(
1705 array(
1706 'message' => esc_html__( 'Please migrate the form before importing the entry', 'everest-forms' ),
1707 )
1708 );
1709 }
1710 // Creating the form instance and getting the form list.
1711 $class_name = 'EVF_Fm_' . ucfirst( trim( str_replace( '-', '', $form_slug ) ) );
1712
1713 if ( ! class_exists( $class_name ) ) {
1714 $except_message = sprintf( '<b><i>%s</i></b> %s', $class_name, esc_html__( 'does not exist.', 'everest-forms' ) );
1715 throw new Exception( $except_message );
1716 }
1717 // Create the instance of class.
1718 $form_instance = new $class_name();
1719 $evf_entries = $form_instance->migrate_entry( $evf_form_id, $form_id );
1720
1721 $success = array();
1722 $unsuccess = array();
1723 foreach ( $evf_entries as $key => $entry ) {
1724 if ( ! $entry ) {
1725 $unsuccess[] = $key;
1726 continue;
1727 }
1728 $success[] = $key;
1729 }
1730 if ( count( $unsuccess ) === 0 ) {
1731 $response = array(
1732 'message' => esc_html__( 'All entries are migrated successfully!!', 'everest-forms' ),
1733 'success' => $success,
1734 'unsuccess' => $unsuccess,
1735 );
1736 } elseif ( count( $unsuccess ) > 0 && count( $success ) === 0 ) {
1737 $response = array(
1738 'message' => esc_html__( 'Entry migration failed!!', 'everest-forms' ),
1739 'success' => $success,
1740 'unsuccess' => $unsuccess,
1741 );
1742 } elseif ( count( $unsuccess ) > 0 && count( $success ) > 0 ) {
1743 $response = array(
1744 'message' => esc_html__( 'Only some entries are migrated successfully!!', 'everest-forms' ),
1745 'success' => $success,
1746 'unsuccess' => $unsuccess,
1747 );
1748 }
1749 wp_send_json_success(
1750 $response
1751 );
1752 } catch ( Exception $e ) {
1753 wp_send_json_error(
1754 array(
1755 'message' => $e->getMessage(),
1756 )
1757 );
1758 }
1759 }
1760 /**
1761 * Everest Forms - Embed Form.
1762 *
1763 * @since 2.0.8
1764 */
1765 public static function embed_form() {
1766 check_ajax_referer( 'everest_forms_embed_form', 'security' );
1767 $args = array(
1768 'post_status' => 'publish',
1769 'post_type' => 'page',
1770 );
1771 $pages = get_pages( $args );
1772
1773 wp_send_json_success( $pages );
1774 }
1775
1776 /**
1777 * Get page edit link
1778 *
1779 * @since 2.0.8
1780 */
1781 public static function goto_edit_page() {
1782 check_ajax_referer( 'everest_forms_goto_edit_page', 'security' );
1783
1784 $page_id = empty( $_POST['page_id'] ) ? 0 : sanitize_text_field( absint( $_POST['page_id'] ) );
1785
1786 if ( empty( $page_id ) ) {
1787 $url = add_query_arg( 'post_type', 'page', admin_url( 'post-new.php' ) );
1788 $meta = array(
1789 'embed_page' => 0,
1790 'embed_page_title' => ! empty( $_POST['page_title'] ) ? sanitize_text_field( wp_unslash( $_POST['page_title'] ) ) : '',
1791 );
1792 } else {
1793 $url = get_edit_post_link( $page_id, '' );
1794 $meta = array(
1795 'embed_page' => $page_id,
1796 );
1797 }
1798 $page_url = add_query_arg(
1799 array(
1800 'form' => 'everest-forms',
1801 ),
1802 esc_url_raw( $url )
1803 );
1804 $meta['form_id'] = ! empty( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
1805 EVF_Admin_Embed_Wizard::set_meta( $meta );
1806
1807 wp_send_json_success( $page_url );
1808 }
1809
1810 /**
1811 * Map csv fields with form fields.
1812 *
1813 * @since 3.0.0
1814 */
1815 public static function map_csv() {
1816 check_ajax_referer( 'evf-import-entries', 'security' );
1817
1818 if ( empty( $_FILES ) ) {
1819 wp_send_json_error(
1820 array(
1821 'message' => 'Please upload csv file.',
1822 )
1823 );
1824 }
1825
1826 $form_id = isset($_POST['form_id']) ? absint($_POST['form_id']) : 0; //phpcs:ignore
1827 $form_fields = evf_get_form_fields( $form_id );
1828
1829 $csv_header = self::get_csv_header( $_FILES );
1830
1831 $output = '';
1832 $output .= '<div class="evf-map-entries-to-form">';
1833 $output .= '<form id="evf-import-entries-form">';
1834 $output .= '<p>' . esc_html__( 'Map CSV fields to Form fields.', 'everest-forms' ) . '</p>';
1835 $output .= '<div class ="evf-form-fields-and-csv-fields" style="display: flex;">';
1836 $output .= '<div class="evf-form-fields" style="width: 50%;">';
1837 $output .= '<h4>' . esc_html__( 'Form Fields', 'everest-forms' ) . '</h4>';
1838 $output .= '</div>';
1839 $output .= '<div class="evf-csv-fields" style="width: 50%;">';
1840 $output .= '<h4>' . esc_html__( 'CSV Fields', 'everest-forms' ) . '</h4>';
1841 $output .= '</div>';
1842 $output .= '</div>';
1843 $output .= '<div class = "evf-map-entries-to-form-wrapper" style="display: flex;">';
1844 $output .= '<div class="evf-form-fields" style="width: 50%;">';
1845 $output .= '<select name="map-entries-to-form" class="evf-form-fields-csv" style="min-width: 90%;">';
1846
1847 if ( ! empty( $form_fields ) ) {
1848 foreach ( $form_fields as $key => $value ) {
1849 $output .= '<option value="' . esc_attr( $key ) . '">' . esc_html( $value['label'] ) . '</option>';
1850 }
1851 } else {
1852 $output .= '<option value="">' . esc_html__( 'No form fields', 'everest-forms' ) . '</option>';
1853 }
1854
1855 $output .= '</select>';
1856 $output .= '</div>';
1857 $output .= '<div class="evf-csv-fields" style="width: 50%;">';
1858 $output .= '<select name="map-entries-to-csv" style="min-width: 90%;">';
1859
1860 if ( ! empty( $csv_header ) ) {
1861 foreach ( $csv_header as $value ) {
1862
1863 $output .= '<option value="' . esc_attr( $value ) . '">' . esc_html( str_replace( '"', '', $value ) ) . '</option>';
1864 }
1865 } else {
1866 $output .= '<option value="">' . esc_html__( 'No csv fields', 'everest-forms' ) . '</option>';
1867 }
1868
1869 $output .= '</select>';
1870 $output .= '</div>';
1871 $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>';
1872 $output .= '</div>';
1873 $output .= '<input type="hidden" name="form_id" value="' . esc_attr( $form_id ) . '">';
1874 $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>';
1875 $output .= '</form>';
1876 $output .= '</div>';
1877
1878 wp_send_json_success(
1879 array(
1880 'html' => $output,
1881 )
1882 );
1883 }
1884
1885 /**
1886 * Retrieves the header of a CSV file.
1887 *
1888 * The function reads the contents of the CSV file, splits it into an array of lines, and retrieves
1889 * the first line, which represents the header of the CSV file. It then sends a JSON success
1890 * response with the header as an array of values.
1891 *
1892 * @since 3.0.0
1893 *
1894 * @param array $csv_data The CSV data containing the file to be processed.
1895 */
1896 public static function get_csv_header( $csv_data ) {
1897
1898 if ( ! isset( $csv_data['csvfile'] ) ) {
1899 wp_send_json_error(
1900 array(
1901 'message' => 'Please upload csv file.',
1902 )
1903 );
1904 }
1905
1906 $file_extension = strtolower( pathinfo( $csv_data['csvfile']['name'], PATHINFO_EXTENSION ) );
1907
1908 if ( 'csv' !== $file_extension ) {
1909 wp_send_json_error(
1910 array(
1911 'message' => 'File must be a CSV file.',
1912 )
1913 );
1914 }
1915
1916 if ( ! function_exists( 'wp_handle_upload' ) ) {
1917 require_once ABSPATH . 'wp-admin/includes/file.php';
1918 }
1919
1920 $upload_dir = wp_upload_dir();
1921 $filename = 'import_entries_data.csv';
1922 $csv_url = $upload_dir['basedir'] . $upload_dir['subdir'] . '/' . $filename;
1923
1924 // Remove existing file if already exists
1925 if ( ! empty( $csv_url ) && file_exists( $csv_url ) ) {
1926 @unlink( $csv_url );
1927 }
1928
1929 // Move uploaded file to uploads directory
1930 $csv_file = $csv_data['csvfile']['tmp_name'];
1931 $upload_file = move_uploaded_file( $csv_file, $csv_url );
1932
1933 if ( ! $upload_file || ! file_exists( $csv_url ) ) {
1934 wp_send_json_error(
1935 array(
1936 'message' => 'File upload failed.',
1937 )
1938 );
1939 }
1940
1941 // Use fgetcsv to safely parse the header
1942 $handle = fopen( $csv_url, 'r' );
1943 if ( ! $handle ) {
1944 wp_send_json_error(
1945 array(
1946 'message' => 'Unable to open uploaded CSV file.',
1947 )
1948 );
1949 }
1950
1951 $csv_header = fgetcsv( $handle );
1952 fclose( $handle );
1953
1954 if ( empty( $csv_header ) ) {
1955 wp_send_json_error(
1956 array(
1957 'message' => 'CSV file doesn\'t contain any header row.',
1958 )
1959 );
1960 }
1961
1962 return $csv_header;
1963 }
1964
1965
1966 /**
1967 * Import entries from the CSV file and process them in the background.
1968 *
1969 * This function checks the AJAX referer and retrieves the mapping fields array from the POST data.
1970 * It then reads the CSV file and processes each row, updating the options and pushing the data to the background process queue.
1971 * Finally, it sends a JSON success response with a message and a link to the imported entries.
1972 *
1973 * @since 3.0.0
1974 *
1975 * @throws Exception If an error occurs during the import process.
1976 */
1977 public static function import_entries() {
1978 try {
1979 check_ajax_referer( 'evf-import-entries', 'security' );
1980
1981 $map_fields_array = array();
1982
1983 if ( ! isset( $_POST['data'] ) ) {
1984 wp_send_json_error(
1985 array(
1986 'message' => 'Something went wrong. Please try again.',
1987 )
1988 );
1989 }
1990
1991 $data = ! empty($_POST['data']) ? $_POST['data'] : array(); //phpcs:ignore
1992
1993 if ( empty( $data ) ) {
1994 wp_send_json_error(
1995 array(
1996 'message' => 'Something went wrong. Please try again.',
1997 )
1998 );
1999 }
2000
2001 foreach ( $data as $key => $map_fields ) {
2002 if ( count( $data ) - 1 === $key ) {
2003 $map_fields_array['form_id'] = sanitize_text_field(wp_unslash($map_fields['value'])); //phpcs:ignore
2004 continue;
2005 }
2006
2007 if ( 0 != $key % 2 ) {
2008 continue;
2009 }
2010
2011 $map_fields_array[ $key ] = array(
2012 'field_id' => sanitize_text_field(wp_unslash($map_fields['value'])), //phpcs:ignore
2013 'map_csv_column' => sanitize_text_field(wp_unslash($data[++$key]['value'])), //phpcs:ignore
2014 );
2015 }
2016
2017 $upload_dir = wp_upload_dir();
2018 $filename = 'import_entries_data.csv';
2019 $csv_url = $upload_dir['basedir'] . $upload_dir['subdir'] . '/' . $filename;
2020
2021 if ( ! empty( $csv_url ) && file_exists( $csv_url ) ) {
2022 $csv_file = fopen( $csv_url, 'r' );
2023 $row = 0;
2024 update_option( 'everest_forms_mapping_fields_array', $map_fields_array );
2025 while ( ( $row_data = fgetcsv( $csv_file, 0, ',' ) ) !== false ) {
2026 if ( strlen( implode( $row_data ) ) != 0 ) {
2027 if ( 0 === $row ) {
2028 update_option( 'everest_forms_csv_titles', $row_data );
2029 } else {
2030 self::$background_process->push_to_queue( $row_data );
2031 }
2032 ++$row;
2033 }
2034 }
2035 fclose( $csv_file );
2036 unlink( $csv_url );
2037 $test = self::$background_process->save()->dispatch();
2038 }
2039
2040 wp_send_json_success(
2041 array(
2042 'message' => 'Your data is currently being imported in the background. Please check the imported entries shortly.',
2043 'entry_link' => admin_url( 'admin.php?page=evf-entries&form_id=' . $map_fields_array['form_id'] ),
2044 'button_text' => 'View Entries',
2045 )
2046 );
2047 } catch ( Exception $e ) {
2048 wp_send_json_error(
2049 array(
2050 'message' => $e->getMessage(),
2051 )
2052 );
2053 }
2054 }
2055 /**
2056 * Generate the restapi key
2057 *
2058 * @since 3.0.5
2059 */
2060 public static function generate_restapi_key() {
2061 try {
2062 check_ajax_referer( 'process-restapi-api-ajax-nonce', 'security' );
2063 $key = generate_api_key();
2064 wp_send_json_success( $key );
2065 } catch ( Exception $e ) {
2066 wp_send_json_error(
2067 array(
2068 'message' => $e->getMessage(),
2069 )
2070 );
2071 }
2072 }
2073
2074 /**
2075 * Installs and activates the Smart SMTP plugin.
2076 *
2077 * @since 3.0.9
2078 *
2079 * @return void Outputs a JSON response.
2080 */
2081 public static function install_and_activate_smart_smtp() {
2082 try {
2083 check_ajax_referer( 'everest-forms-smart-smtp-installation-nonce', 'security' );
2084 if ( ! current_user_can( 'manage_everest_forms' ) ) {
2085 wp_send_json_error( array( 'message' => 'You do not have permission to install plugins.' ) );
2086 }
2087
2088 if ( is_plugin_active( 'smart-smtp/smart-smtp.php' ) ) {
2089 wp_send_json_success( array( 'message' => 'SmartSMTP plugin is already activated!' ) );
2090 }
2091
2092 $installed_plugins = get_plugins();
2093
2094 if ( array_key_exists( 'smart-smtp/smart-smtp.php', $installed_plugins ) ) {
2095 $activate_result = activate_plugin( 'smart-smtp/smart-smtp.php' );
2096 if ( is_wp_error( $activate_result ) ) {
2097 $error_message = $activate_result->get_error_message();
2098 wp_send_json_error(
2099 array(
2100 /* translators: %s: Error message explaining the activation failure */
2101 'message' => esc_html__( 'Sorry, we are unable to activate SmartSMTP because of %s', 'everest-forms' ),
2102 esc_html( $error_message ),
2103 )
2104 );
2105 }
2106 } else {
2107 require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
2108 require_once ABSPATH . 'wp-admin/includes/file.php';
2109 require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
2110
2111 $plugin_info = plugins_api( 'plugin_information', array( 'slug' => 'smart-smtp' ) );
2112 if ( is_wp_error( $plugin_info ) ) {
2113 wp_send_json_error( array( 'message' => esc_html__( 'Sorry, your internet connection was interrupted', 'everest-forms' ) ) );
2114 }
2115
2116 $upgrader = new Plugin_Upgrader( new WP_Ajax_Upgrader_Skin() );
2117 $install_result = $upgrader->install( $plugin_info->download_link );
2118 if ( is_wp_error( $install_result ) ) {
2119 $installation_error = $install_result->get_error_message();
2120 wp_send_json_error(
2121 array(
2122 /* translators: %s: Error message explaining the installation failure */
2123 'message' => esc_html__( 'Plugin installation failed due to %s', 'everest-forms' ),
2124 esc_html( $installation_error ),
2125 )
2126 );
2127 }
2128
2129 $activate_result = activate_plugin( 'smart-smtp/smart-smtp.php' );
2130 }
2131
2132 if ( is_wp_error( $activate_result ) ) {
2133 wp_send_json_error( array( 'message' => 'Plugin activation failed: ' . $activate_result->get_error_message() ) );
2134 }
2135
2136 wp_send_json_success(
2137 array(
2138 'message' => 'SmartSMTP plugin installed and activated successfully!',
2139 'redirection_url' => evf_get_smart_smtp_google_workspace_setup_url(),
2140 )
2141 );
2142 } catch ( Exception $e ) {
2143 wp_send_json_error( array( 'message' => $e->getMessage() ) );
2144 }
2145 }
2146
2147 /**
2148 * Get form settings theme styles
2149 */
2150 public static function form_preview_save() {
2151 check_ajax_referer( 'evf_form_preview_nonce', 'security' );
2152
2153 if ( ! current_user_can( 'manage_options' ) ) {
2154 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2155 wp_die( -1 );
2156 }
2157 $form_id = isset( $_POST['id'] ) ? sanitize_text_field( $_POST['id'] ) : '';
2158 $theme = isset( $_POST['theme'] ) ? sanitize_text_field( $_POST['theme'] ) : '';
2159
2160 if ( empty( $form_id ) || empty( $theme ) ) {
2161 wp_send_json_error( array( 'message' => __( 'Insufficient information', 'everest-forms' ) ) );
2162 }
2163
2164 $default_theme = ( 'default' === $theme ) ? 'default' : 'theme';
2165 update_post_meta( $form_id, 'everest_forms_enable_theme_style', $default_theme );
2166
2167 wp_send_json_success( array( 'message' => __( 'Saved', 'everest-forms' ) ) );
2168 }
2169 /**
2170 * Delete the tags.
2171 *
2172 * @since 3.2.0
2173 */
2174 public static function delete_form_tags() {
2175 check_ajax_referer( 'ajax_manage_tags_nonce', 'security' );
2176
2177 if ( ! current_user_can( 'manage_options' ) ) {
2178 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2179 wp_die( -1 );
2180 }
2181
2182 $tags = isset( $_POST['tags'] ) ? array_map( 'absint', $_POST['tags'] ) : array();
2183
2184 if ( empty( $tags ) ) {
2185 wp_send_json_error( array( 'message' => __( 'Missing tags.', 'everest-forms' ) ) );
2186 }
2187
2188 foreach ( $tags as $tag ) {
2189 wp_delete_term( $tag, EVF_Post_Types::TAGS_TAXONOMY );
2190 }
2191
2192 wp_send_json_success( array( 'message' => __( 'Tags are deleted successfully.', 'everest-forms' ) ) );
2193 }
2194
2195 /**
2196 * Update tags in bulk.
2197 *
2198 * @since 3.2.0
2199 */
2200 public static function update_tags_in_bulk() {
2201 check_ajax_referer( 'ajax_manage_tags_nonce', 'security' );
2202
2203 if ( ! current_user_can( 'manage_options' ) ) {
2204 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2205 wp_die( -1 );
2206 }
2207
2208 $tags = isset( $_POST['tags'] ) ? $_POST['tags'] : array();
2209 $forms = isset( $_POST['forms'] ) ? array_map( 'absint', $_POST['forms'] ) : array();
2210
2211 if ( empty( $forms ) ) {
2212 wp_send_json_error( array( 'message' => __( 'Please select atleast on form to updat the tags.', 'everest-forms' ) ) );
2213 }
2214
2215 $term_ids = array();
2216
2217 foreach ( $tags as $tag_name ) {
2218 if ( is_numeric( $tag_name ) ) {
2219 $term = get_term( absint( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
2220 if ( $term && ! is_wp_error( $term ) ) {
2221 $term_ids[] = $term->term_id;
2222 continue;
2223 }
2224 }
2225
2226 $term = term_exists( $tag_name, EVF_Post_Types::TAGS_TAXONOMY );
2227 if ( $term === null ) {
2228 $term = wp_insert_term( sanitize_text_field( $tag_name ), EVF_Post_Types::TAGS_TAXONOMY );
2229 }
2230 if ( ! is_wp_error( $term ) ) {
2231 $term_ids[] = is_array( $term ) ? (int) $term['term_id'] : $term;
2232 }
2233 }
2234
2235 foreach ( $forms as $id ) {
2236 wp_set_post_terms( $id, $term_ids, EVF_Post_Types::TAGS_TAXONOMY, false );
2237 }
2238
2239 wp_send_json_success( array( 'message' => __( 'Tags are updated successfully.', 'everest-forms' ) ) );
2240 }
2241
2242 /**
2243 * Save the clean talk settings.
2244 *
2245 * @since 3.2.0
2246 */
2247 public static function save_clean_talk_settings() {
2248 check_ajax_referer( 'everest_forms_clean_talk_nonce', 'security' );
2249
2250 if ( ! current_user_can( 'manage_options' ) ) {
2251 wp_send_json_error( array( 'message' => __( 'You do not have permission.', 'everest-forms' ) ) );
2252 wp_die( -1 );
2253 }
2254
2255 if ( isset( $_POST['action'] ) && 'everest_forms_save_clean_talk_settings' != $_POST['action'] ) {
2256 wp_send_json_error( array( 'message' => __( 'Action doesn\'t match.', 'everest-forms' ) ) );
2257 wp_die( -1 );
2258 }
2259
2260 $form_data = isset( $_POST['form_data'] ) ? $_POST['form_data'] : '';
2261
2262 if ( empty( $form_data ) ) {
2263 wp_send_json_error( array( 'message' => __( 'Insufficient information', 'everest-forms' ) ) );
2264 }
2265
2266 $access_key = isset( $form_data['access_key'] ) ? sanitize_text_field( wp_unslash( $form_data['access_key'] ) ) : '';
2267
2268 $output = '';
2269 if ( empty( $access_key ) ) {
2270 $output .= '<span class="everest-forms-clean-talk-icon-box">
2271 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2272 <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"/>
2273 </svg>
2274 </span>';
2275 $output .= '<span class="everest-forms-clean-talk-message-box">Please enter the CleanTalk access key.</span>';
2276 $output .= '</div>';
2277 wp_send_json_error(
2278 array(
2279 'error' => 'empty',
2280 'html' => $output,
2281 )
2282 );
2283 }
2284
2285 $clean_talk_request = array(
2286 'method_name' => 'notice_paid_till',
2287 'auth_key' => $access_key,
2288 );
2289
2290 $response = wp_remote_post(
2291 'https://api.cleantalk.org/',
2292 array(
2293 'body' => \http_build_query( $clean_talk_request, true ),
2294 'headers' => array(
2295 'Content-Type' => 'application/x-www-form-urlencoded',
2296 ),
2297 )
2298 );
2299 $response = json_decode( wp_remote_retrieve_body( $response ) );
2300
2301 if ( $response->data->moderate == 1 && $response->data->valid == 1 && $response->data->product_id == 1 ) {
2302 update_option( 'everest_forms_recaptcha_cleantalk_access_key', $access_key );
2303
2304 $output .= '<span class="everest-forms-clean-talk-icon-box">
2305 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2306 <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"/>
2307 </svg>
2308 </span>';
2309 $output .= '<span class="everest-forms-clean-talk-message-box">Settings saved successfully.</span>';
2310 $output .= '</div>';
2311
2312 wp_send_json_success(
2313 array(
2314 'html' => $output,
2315 )
2316 );
2317 } else {
2318 $output .= '<span class="everest-forms-clean-talk-icon-box">
2319 <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
2320 <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"/>
2321 </svg>
2322 </span>';
2323 $output .= '<span class="everest-forms-clean-talk-message-box">Invalid CleanTalk access key.</span>';
2324 $output .= '</div>';
2325 wp_send_json_error(
2326 array(
2327 'error' => 'invalid',
2328 'html' => $output,
2329 )
2330 );
2331 }
2332 }
2333 /**
2334 * This callback give the update nonce of the form.
2335 *
2336 * @since 3.3.0
2337 */
2338 public static function get_form_update_nonce() {
2339 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
2340
2341 if ( empty( $form_id ) ) {
2342 wp_die( __( 'Form ID is missing!', 'everest-forms' ), 403 );
2343 }
2344
2345 $form = evf()->form->get( $form_id );
2346
2347 if ( empty( $form ) ) {
2348 wp_die( __( 'Form not found!', 'everest-forms' ), 403 );
2349 }
2350
2351 // Strict referer verification
2352 $referer = wp_get_referer();
2353 $allowed_host = parse_url( home_url(), PHP_URL_HOST );
2354 $referer_host = parse_url( $referer, PHP_URL_HOST );
2355
2356 if ( ! $referer || $referer_host !== $allowed_host ) {
2357 wp_die( __( 'Invalid form submission source.', 'everest-forms' ), 403 );
2358 }
2359
2360 wp_send_json_success( wp_create_nonce( 'everest-forms_process_submit' ) );
2361 }
2362 }
2363
2364 EVF_AJAX::init();
2365