PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.8.7
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.8.7
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
abstracts 4 years ago admin 4 years ago elementor 4 years ago export 4 years ago fields 4 years ago interfaces 8 years ago libraries 7 years ago log-handlers 4 years ago shortcodes 4 years ago templates 5 years ago class-everest-forms.php 4 years ago class-evf-ajax.php 4 years ago class-evf-autoloader.php 7 years ago class-evf-background-updater.php 7 years ago class-evf-cache-helper.php 6 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-emails.php 5 years ago class-evf-fields.php 6 years ago class-evf-form-block.php 4 years ago class-evf-form-handler.php 4 years ago class-evf-form-task.php 4 years ago class-evf-forms-features.php 4 years ago class-evf-frontend-scripts.php 4 years ago class-evf-install.php 5 years ago class-evf-integrations.php 7 years ago class-evf-log-levels.php 8 years ago class-evf-logger.php 5 years ago class-evf-post-types.php 5 years ago class-evf-privacy.php 6 years ago class-evf-session-handler.php 7 years ago class-evf-shortcodes.php 4 years ago class-evf-smart-tags.php 4 years ago class-evf-template-loader.php 4 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 4 years ago evf-deprecated-functions.php 6 years ago evf-entry-functions.php 4 years ago evf-formatting-functions.php 4 years ago evf-notice-functions.php 4 years ago evf-template-functions.php 4 years ago evf-template-hooks.php 7 years ago evf-update-functions.php 5 years ago
class-evf-ajax.php
835 lines
1 <?php
2 /**
3 * EverestForms EVF_AJAX. AJAX Event Handlers.
4 *
5 * @class EVF_AJAX
6 * @package EverestForms/Classes
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_AJAX class.
13 */
14 class EVF_AJAX {
15
16 /**
17 * Hook in ajax handlers.
18 */
19 public static function init() {
20 add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21 add_action( 'template_redirect', array( __CLASS__, 'do_evf_ajax' ), 0 );
22 self::add_ajax_events();
23 }
24
25 /**
26 * Set EVF AJAX constant and headers.
27 */
28 public static function define_ajax() {
29 // @codingStandardsIgnoreStart
30 if ( ! empty( $_GET['evf-ajax'] ) ) {
31 evf_maybe_define_constant( 'DOING_AJAX', true );
32 evf_maybe_define_constant( 'EVF_DOING_AJAX', true );
33 if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34 @ini_set( 'display_errors', 0 ); // Turn off display_errors during AJAX events to prevent malformed JSON.
35 }
36 $GLOBALS['wpdb']->hide_errors();
37 }
38 // @codingStandardsIgnoreEnd
39 }
40
41 /**
42 * Send headers for EVF Ajax Requests.
43 *
44 * @since 1.0.0
45 */
46 private static function evf_ajax_headers() {
47 if ( ! headers_sent() ) {
48 send_origin_headers();
49 send_nosniff_header();
50 evf_nocache_headers();
51 header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52 header( 'X-Robots-Tag: noindex' );
53 status_header( 200 );
54 } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
55 headers_sent( $file, $line );
56 trigger_error( "evf_ajax_headers cannot set headers - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine
57 }
58 }
59
60 /**
61 * Check for EVF Ajax request and fire action.
62 */
63 public static function do_evf_ajax() {
64 global $wp_query;
65
66 if ( ! empty( $_GET['evf-ajax'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
67 $wp_query->set( 'evf-ajax', sanitize_text_field( wp_unslash( $_GET['evf-ajax'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
68 }
69
70 $action = $wp_query->get( 'evf-ajax' );
71
72 if ( $action ) {
73 self::evf_ajax_headers();
74 $action = sanitize_text_field( $action );
75 do_action( 'evf_ajax_' . $action );
76 wp_die();
77 }
78 }
79
80 /**
81 * Hook in methods - uses WordPress ajax handlers (admin-ajax).
82 */
83 public static function add_ajax_events() {
84 $ajax_events = array(
85 'save_form' => false,
86 'create_form' => false,
87 'get_next_id' => false,
88 'install_extension' => false,
89 'integration_connect' => false,
90 'new_email_add' => false,
91 'integration_disconnect' => false,
92 'deactivation_notice' => false,
93 'rated' => false,
94 'review_dismiss' => false,
95 'survey_dismiss' => false,
96 'enabled_form' => false,
97 'import_form_action' => false,
98 'template_licence_check' => false,
99 'template_activate_addon' => false,
100 'ajax_form_submission' => true,
101 'send_test_email' => false,
102 );
103
104 foreach ( $ajax_events as $ajax_event => $nopriv ) {
105 add_action( 'wp_ajax_everest_forms_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
107 if ( $nopriv ) {
108 add_action( 'wp_ajax_nopriv_everest_forms_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
110 // EVF AJAX can be used for frontend ajax requests.
111 add_action( 'evf_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112 }
113 }
114 }
115
116 /**
117 * Ajax handler to get next form ID.
118 */
119 public static function get_next_id() {
120 // Run a security check.
121 check_ajax_referer( 'everest_forms_get_next_id', 'security' );
122
123 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
124 if ( $form_id < 1 ) {
125 wp_send_json_error(
126 array(
127 'error' => esc_html__( 'Invalid form', 'everest-forms' ),
128 )
129 );
130 }
131
132 // Check permisssions.
133 if ( ! current_user_can( 'everest_forms_edit_form', $form_id ) ) {
134 wp_send_json_error();
135 }
136
137 if ( isset( $_POST['fields'] ) ) {
138 $fields_data = array();
139 for ( $i = 0; $i < $_POST['fields']; $i++ ) {
140 $field_key = evf()->form->field_unique_key( $form_id );
141 $field_id_array = explode( '-', $field_key );
142 $new_field_id = ( $field_id_array[ count( $field_id_array ) - 1 ] + 1 );
143 $fields_data [] = array(
144 'field_id' => $new_field_id,
145 'field_key' => $field_key,
146 );
147 }
148 wp_send_json_success(
149 $fields_data
150 );
151 } else {
152 $field_key = evf()->form->field_unique_key( $form_id );
153 $field_id_array = explode( '-', $field_key );
154 $new_field_id = ( $field_id_array[ count( $field_id_array ) - 1 ] + 1 );
155 wp_send_json_success(
156 array(
157 'field_id' => $new_field_id,
158 'field_key' => $field_key,
159 )
160 );
161 }
162 }
163
164 /**
165 * AJAX create new form.
166 */
167 public static function create_form() {
168 ob_start();
169
170 check_ajax_referer( 'everest_forms_create_form', 'security' );
171
172 // Check permissions.
173 if ( ! current_user_can( 'everest_forms_create_forms' ) ) {
174 wp_die( -1 );
175 }
176
177 $title = isset( $_POST['title'] ) ? sanitize_text_field( wp_unslash( $_POST['title'] ) ) : esc_html__( 'Blank Form', 'everest-forms' );
178 $template = isset( $_POST['template'] ) ? sanitize_text_field( wp_unslash( $_POST['template'] ) ) : 'blank';
179
180 $form_id = evf()->form->create( $title, $template );
181
182 if ( $form_id ) {
183 $data = array(
184 'id' => $form_id,
185 'redirect' => add_query_arg(
186 array(
187 'tab' => 'fields',
188 'form_id' => $form_id,
189 ),
190 admin_url( 'admin.php?page=evf-builder' )
191 ),
192 );
193
194 wp_send_json_success( $data );
195 }
196
197 wp_send_json_error(
198 array(
199 'error' => esc_html__( 'Something went wrong, please try again later', 'everest-forms' ),
200 )
201 );
202 }
203
204 /**
205 * AJAX Form save.
206 */
207 public static function save_form() {
208 check_ajax_referer( 'everest_forms_save_form', 'security' );
209
210 $logger = evf_get_logger();
211
212 // Check permissions.
213 $logger->info(
214 __( 'Checking permissions.', 'everest-forms' ),
215 array( 'source' => 'form-save' )
216 );
217 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
218 $logger->critical(
219 __( 'You do not have permission.', 'everest-forms' ),
220 array( 'source' => 'form-save' )
221 );
222 die( esc_html__( 'You do not have permission.', 'everest-forms' ) );
223 }
224
225 // Check for form data.
226 $logger->info(
227 __( 'Checking for form data.', 'everest-forms' ),
228 array( 'source' => 'form-save' )
229 );
230 if ( empty( $_POST['form_data'] ) ) {
231 $logger->critical(
232 __( 'No data provided.', 'everest-forms' ),
233 array( 'source' => 'form-save' )
234 );
235 die( esc_html__( 'No data provided', 'everest-forms' ) );
236 }
237
238 $form_post = evf_sanitize_builder( json_decode( wp_unslash( $_POST['form_data'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
239
240 $data = array();
241 $choose_field = array();
242
243 if ( ! is_null( $form_post ) && $form_post ) {
244 foreach ( $form_post as $post_input_data ) {
245 // For input names that are arrays (e.g. `menu-item-db-id[3][4][5]`),
246 // derive the array path keys via regex and set the value in $_POST.
247 preg_match( '#([^\[]*)(\[(.+)\])?#', $post_input_data->name, $matches );
248
249 $array_bits = array( $matches[1] );
250
251 if ( isset( $matches[3] ) ) {
252 $array_bits = array_merge( $array_bits, explode( '][', $matches[3] ) );
253 }
254
255 $new_post_data = array();
256
257 // Build the new array value from leaf to trunk.
258 for ( $i = count( $array_bits ) - 1; $i >= 0; $i -- ) {
259 if ( count( $array_bits ) - 1 === $i ) {
260 $new_post_data[ $array_bits[ $i ] ] = wp_slash( $post_input_data->value );
261 } else {
262 $new_post_data = array(
263 $array_bits[ $i ] => $new_post_data,
264 );
265 }
266 }
267 $choose_field_data = isset( $new_post_data['settings']['choose_pdf_fields'] ) ? $new_post_data['settings']['choose_pdf_fields'] : array();
268 if ( ! empty( $choose_field_data ) ) {
269 array_push( $choose_field, $choose_field_data );
270 }
271 $data = array_replace_recursive( $data, $new_post_data );
272 }
273 }
274 $data['settings']['choose_pdf_fields'] = $choose_field;
275 // Check for empty meta key.
276 $logger->info(
277 __( 'Check for empty meta key.', 'everest-forms' ),
278 array( 'source' => 'form-save' )
279 );
280 $empty_meta_data = array();
281 if ( ! empty( $data['form_fields'] ) ) {
282 foreach ( $data['form_fields'] as $field_key => $field ) {
283 if ( ! empty( $field['label'] ) ) {
284 // Only allow specific html in label.
285 $data['form_fields'][ $field_key ]['label'] = wp_kses(
286 $field['label'],
287 array(
288 'a' => array(
289 'href' => array(),
290 'class' => array(),
291 ),
292 'span' => array(
293 'class' => array(),
294 ),
295 'em' => array(),
296 'small' => array(),
297 'strong' => array(),
298 )
299 );
300
301 // Register string for translation.
302 evf_string_translation( $data['id'], $field['id'], $field['label'] );
303 }
304
305 if ( empty( $field['meta-key'] ) && ! in_array( $field['type'], array( 'html', 'title', 'captcha', 'divider' ), true ) ) {
306 $empty_meta_data[] = $field['label'];
307 }
308 }
309
310 if ( ! empty( $empty_meta_data ) ) {
311 $logger->error(
312 __( 'Meta Key missing.', 'everest-forms' ),
313 array( 'source' => 'form-save' )
314 );
315 wp_send_json_error(
316 array(
317 'errorTitle' => esc_html__( 'Meta Key missing', 'everest-forms' ),
318 /* translators: %s: empty meta data */
319 'errorMessage' => sprintf( esc_html__( 'Please add Meta key for fields: %s', 'everest-forms' ), '<strong>' . implode( ', ', $empty_meta_data ) . '</strong>' ),
320 )
321 );
322 }
323 }
324
325 // Fix for sorting field ordering.
326 $logger->info(
327 __( 'Fix for sorting field ordering.', 'everest-forms' ),
328 array( 'source' => 'form-save' )
329 );
330 if ( isset( $data['structure'], $data['form_fields'] ) ) {
331 $structure = evf_flatten_array( $data['structure'] );
332 $data['form_fields'] = array_merge( array_intersect_key( array_flip( $structure ), $data['form_fields'] ), $data['form_fields'] );
333 }
334
335 $form_id = evf()->form->update( $data['id'], $data );
336 $form_styles = get_option( 'everest_forms_styles', array() );
337 $logger->info(
338 __( 'Saving form.', 'everest-forms' ),
339 array( 'source' => 'form-save' )
340 );
341 do_action( 'everest_forms_save_form', $form_id, $data, array(), ! empty( $form_styles[ $form_id ] ) );
342
343 if ( ! $form_id ) {
344 $logger->error(
345 __( 'An error occurred while saving the form.', 'everest-forms' ),
346 array( 'source' => 'form-save' )
347 );
348 wp_send_json_error(
349 array(
350 'errorTitle' => esc_html__( 'Form not found', 'everest-forms' ),
351 'errorMessage' => esc_html__( 'An error occurred while saving the form.', 'everest-forms' ),
352 )
353 );
354 } else {
355 $logger->info(
356 __( 'Form Saved successfully.', 'everest-forms' ),
357 array( 'source' => 'form-save' )
358 );
359 wp_send_json_success(
360 array(
361 'form_name' => esc_html( $data['settings']['form_title'] ),
362 'redirect_url' => admin_url( 'admin.php?page=evf-builder' ),
363 )
364 );
365 }
366 }
367
368 /**
369 * Ajax handler for form submission.
370 */
371 public static function ajax_form_submission() {
372 check_ajax_referer( 'everest_forms_ajax_form_submission', 'security' );
373
374 if ( ! empty( $_POST['everest_forms']['id'] ) ) {
375 $process = evf()->task->ajax_form_submission( evf_sanitize_entry( wp_unslash( $_POST['everest_forms'] ) ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
376 if ( 'success' === $process['response'] ) {
377 wp_send_json_success( $process );
378 }
379
380 wp_send_json_error( $process );
381 }
382 }
383
384 /**
385 * Ajax handler for template required addon activation.
386 */
387 public static function template_activate_addon() {
388 check_ajax_referer( 'everest_forms_template_licence_check', 'security' );
389
390 if ( empty( $_POST['addon'] ) ) {
391 wp_send_json_error(
392 array(
393 'errorCode' => 'no_addon_specified',
394 'errorMessage' => esc_html__( 'No Addon specified.', 'everest-forms' ),
395 )
396 );
397 }
398
399 $activate = activate_plugin( sanitize_text_field( wp_unslash( $_POST['addon'] ) ) . '/' . sanitize_text_field( wp_unslash( $_POST['addon'] ) ) . '.php' );
400
401 if ( is_wp_error( $activate ) ) {
402 wp_send_json_error(
403 array(
404 'errorCode' => 'addon_not_active',
405 'errorMessage' => esc_html__( 'Addon can not be activate. Please try again.', 'everest-forms' ),
406 )
407 );
408 } else {
409 wp_send_json_success( 'Addon sucessfully activated.' );
410 }
411 }
412
413 /**
414 * Ajax handler for licence check.
415 *
416 * @global WP_Filesystem_Base $wp_filesystem Subclass
417 */
418 public static function template_licence_check() {
419 check_ajax_referer( 'everest_forms_template_licence_check', 'security' );
420
421 if ( empty( $_POST['plan'] ) ) {
422 wp_send_json_error(
423 array(
424 'plan' => '',
425 'errorCode' => 'no_plan_specified',
426 'errorMessage' => esc_html__( 'No Plan specified.', 'everest-forms' ),
427 )
428 );
429 }
430
431 $addons = array();
432 $template_data = evf_get_json_file_contents( 'assets/extensions-json/templates/all_templates.json' );
433
434 if ( ! empty( $template_data->templates ) ) {
435 foreach ( $template_data->templates as $template ) {
436 if ( isset( $_POST['slug'] ) && $template->slug === $_POST['slug'] && in_array( $_POST['plan'], $template->plan, true ) ) {
437 $addons = $template->addons;
438 }
439 }
440 }
441
442 $output = '<div class="everest-forms-recommend-addons">';
443 $output .= '<p class="desc plugins-info">' . esc_html__( 'This form template requires the following addons.', 'everest-forms' ) . '</p>';
444 $output .= '<table class="plugins-list-table widefat striped">';
445 $output .= '<thead><tr><th scope="col" class="manage-column required-plugins" colspan="2">Required Addons</th></tr></thead><tbody id="the-list">';
446 $output .= '</div>';
447
448 $activated = true;
449 foreach ( $addons as $slug => $addon ) {
450 if ( is_plugin_active( $slug . '/' . $slug . '.php' ) ) {
451 $class = 'active';
452 $parent_class = '';
453 } elseif ( file_exists( WP_PLUGIN_DIR . '/' . $slug . '/' . $slug . '.php' ) ) {
454 $class = 'activate-now';
455 $parent_class = 'inactive';
456 $activated = false;
457 } else {
458 $class = 'install-now';
459 $parent_class = 'inactive';
460 $activated = false;
461 }
462 $output .= '<tr class="plugin-card-' . $slug . ' plugin ' . $parent_class . '" data-slug="' . $slug . '" data-plugin="' . $slug . '/' . $slug . '.php" data-name="' . $addon . '">';
463 $output .= '<td class="plugin-name">' . $addon . '</td>';
464 $output .= '<td class="plugin-status"><span class="' . esc_attr( $class ) . '"></span></td>';
465 $output .= '</tr>';
466 }
467 $output .= '</tbody></table></div>';
468
469 wp_send_json_success(
470 array(
471 'html' => $output,
472 'activate' => $activated,
473 )
474 );
475 }
476
477 /**
478 * Ajax handler for installing a extension.
479 *
480 * @since 1.2.0
481 *
482 * @see Plugin_Upgrader
483 *
484 * @global WP_Filesystem_Base $wp_filesystem Subclass
485 */
486 public static function install_extension() {
487 check_ajax_referer( 'updates' );
488
489 if ( empty( $_POST['slug'] ) ) {
490 wp_send_json_error(
491 array(
492 'slug' => '',
493 'errorCode' => 'no_plugin_specified',
494 'errorMessage' => esc_html__( 'No plugin specified.', 'everest-forms' ),
495 )
496 );
497 }
498
499 $slug = sanitize_key( wp_unslash( $_POST['slug'] ) );
500 $plugin = plugin_basename( sanitize_text_field( wp_unslash( $_POST['slug'] . '/' . $_POST['slug'] . '.php' ) ) );
501 $status = array(
502 'install' => 'plugin',
503 'slug' => sanitize_key( wp_unslash( $_POST['slug'] ) ),
504 );
505
506 if ( ! current_user_can( 'install_plugins' ) ) {
507 $status['errorMessage'] = esc_html__( 'Sorry, you are not allowed to install plugins on this site.', 'everest-forms' );
508 wp_send_json_error( $status );
509 }
510
511 include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
512 include_once ABSPATH . 'wp-admin/includes/plugin-install.php';
513
514 if ( file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
515 $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin );
516 $status['plugin'] = $plugin;
517 $status['pluginName'] = $plugin_data['Name'];
518
519 if ( current_user_can( 'activate_plugin', $plugin ) && is_plugin_inactive( $plugin ) ) {
520 $result = activate_plugin( $plugin );
521
522 if ( is_wp_error( $result ) ) {
523 $status['errorCode'] = $result->get_error_code();
524 $status['errorMessage'] = $result->get_error_message();
525 wp_send_json_error( $status );
526 }
527
528 wp_send_json_success( $status );
529 }
530 }
531
532 $api = json_decode(
533 EVF_Updater_Key_API::version(
534 array(
535 'license' => get_option( 'everest-forms-pro_license_key' ),
536 'item_name' => ! empty( $_POST['name'] ) ? sanitize_text_field( wp_unslash( $_POST['name'] ) ) : '',
537 )
538 )
539 );
540
541 if ( is_wp_error( $api ) ) {
542 $status['errorMessage'] = $api->get_error_message();
543 wp_send_json_error( $status );
544 }
545
546 $status['pluginName'] = $api->name;
547
548 $skin = new WP_Ajax_Upgrader_Skin();
549 $upgrader = new Plugin_Upgrader( $skin );
550 $result = $upgrader->install( $api->download_link );
551
552 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
553 $status['debug'] = $skin->get_upgrade_messages();
554 }
555
556 if ( is_wp_error( $result ) ) {
557 $status['errorCode'] = $result->get_error_code();
558 $status['errorMessage'] = $result->get_error_message();
559 wp_send_json_error( $status );
560 } elseif ( is_wp_error( $skin->result ) ) {
561 $status['errorCode'] = $skin->result->get_error_code();
562 $status['errorMessage'] = $skin->result->get_error_message();
563 wp_send_json_error( $status );
564 } elseif ( $skin->get_errors()->get_error_code() ) {
565 $status['errorMessage'] = $skin->get_error_messages();
566 wp_send_json_error( $status );
567 } elseif ( is_null( $result ) ) {
568 global $wp_filesystem;
569
570 $status['errorCode'] = 'unable_to_connect_to_filesystem';
571 $status['errorMessage'] = esc_html__( 'Unable to connect to the filesystem. Please confirm your credentials.', 'everest-forms' );
572
573 // Pass through the error from WP_Filesystem if one was raised.
574 if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
575 $status['errorMessage'] = esc_html( $wp_filesystem->errors->get_error_message() );
576 }
577
578 wp_send_json_error( $status );
579 }
580
581 $install_status = install_plugin_install_status( $api );
582
583 if ( current_user_can( 'activate_plugin', $install_status['file'] ) && is_plugin_inactive( $install_status['file'] ) ) {
584 if ( isset( $_POST['page'] ) && 'everest-forms_page_evf-builder' === $_POST['page'] ) {
585 activate_plugin( $install_status['file'] );
586 } else {
587 $status['activateUrl'] =
588 esc_url_raw(
589 add_query_arg(
590 array(
591 'action' => 'activate',
592 'plugin' => $install_status['file'],
593 '_wpnonce' => wp_create_nonce( 'activate-plugin_' . $install_status['file'] ),
594 ),
595 admin_url( 'admin.php?page=evf-addons' )
596 )
597 );
598 }
599 }
600
601 wp_send_json_success( $status );
602 }
603
604 /**
605 * AJAX Integration connect.
606 */
607 public static function integration_connect() {
608 check_ajax_referer( 'process-ajax-nonce', 'security' );
609
610 // Check permissions.
611 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
612 wp_die( -1 );
613 }
614
615 if ( empty( $_POST ) ) {
616 wp_send_json_error(
617 array(
618 'error' => esc_html__( 'Missing data', 'everest-forms' ),
619 )
620 );
621 }
622
623 do_action( 'everest_forms_integration_account_connect_' . ( isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '' ), $_POST );
624 }
625
626 /**
627 * AJAX Email Add.
628 */
629 public static function new_email_add() {
630 check_ajax_referer( 'process-ajax-nonce', 'security' );
631
632 // Check permissions.
633 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
634 wp_die( -1 );
635 }
636
637 $connection_id = 'connection_' . uniqid();
638
639 wp_send_json_success(
640 array(
641 'connection_id' => $connection_id,
642 )
643 );
644 }
645
646 /**
647 * AJAX Integration disconnect.
648 */
649 public static function integration_disconnect() {
650 check_ajax_referer( 'process-ajax-nonce', 'security' );
651
652 // Check permissions.
653 if ( ! current_user_can( 'everest_forms_edit_forms' ) ) {
654 wp_die( -1 );
655 }
656
657 if ( empty( $_POST ) ) {
658 wp_send_json_error(
659 array(
660 'error' => esc_html__( 'Missing data', 'everest-forms' ),
661 )
662 );
663 }
664
665 do_action( 'everest_forms_integration_account_disconnect_' . ( isset( $_POST['source'] ) ? sanitize_text_field( wp_unslash( $_POST['source'] ) ) : '' ), $_POST );
666
667 $connected_accounts = get_option( 'everest_forms_integrations', false );
668
669 if ( ! empty( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] ) ) {
670 unset( $connected_accounts[ $_POST['source'] ][ $_POST['key'] ] );
671 update_option( 'everest_forms_integrations', $connected_accounts );
672 wp_send_json_success( array( 'remove' => true ) );
673 } else {
674 wp_send_json_error(
675 array(
676 'error' => esc_html__( 'Connection missing', 'everest-forms' ),
677 )
678 );
679 }
680 }
681
682 /**
683 * AJAX plugin deactivation notice.
684 */
685 public static function deactivation_notice() {
686 global $status, $page, $s;
687
688 check_ajax_referer( 'deactivation-notice', 'security' );
689
690 $deactivate_url = esc_url(
691 wp_nonce_url(
692 add_query_arg(
693 array(
694 'action' => 'deactivate',
695 'plugin' => EVF_PLUGIN_BASENAME,
696 'plugin_status' => $status,
697 'paged' => $page,
698 's' => $s,
699 ),
700 admin_url( 'plugins.php' )
701 ),
702 'deactivate-plugin_' . EVF_PLUGIN_BASENAME
703 )
704 );
705
706 /* translators: %1$s - deactivation reason page; %2$d - deactivation url. */
707 $deactivation_notice = sprintf( __( 'Before we deactivate Everest Forms, would you care to <a href="%1$s" target="_blank">let us know why</a> so we can improve it for you? <a href="%2$s">No, deactivate now</a>.', 'everest-forms' ), 'https://wpeverest.com/deactivation/everest-forms/', $deactivate_url );
708
709 wp_send_json(
710 array(
711 'fragments' => apply_filters(
712 'everest_forms_deactivation_notice_fragments',
713 array(
714 'deactivation_notice' => '<tr class="plugin-update-tr active updated" data-slug="everest-forms" data-plugin="everest-forms/everest-forms.php"><td colspan ="3" class="plugin-update colspanchange"><div class="notice inline notice-warning notice-alt"><p>' . $deactivation_notice . '</p></div></td></tr>',
715 )
716 ),
717 )
718 );
719 }
720
721 /**
722 * Triggered when clicking the rating footer.
723 */
724 public static function rated() {
725 if ( ! current_user_can( 'manage_everest_forms' ) ) {
726 wp_die( -1 );
727 }
728 update_option( 'everest_forms_admin_footer_text_rated', 1 );
729 wp_die();
730 }
731
732 /**
733 * Triggered when clicking the review notice button.
734 */
735 public static function review_dismiss() {
736 if ( ! current_user_can( 'manage_everest_forms' ) ) {
737 wp_die( -1 );
738 }
739 $review = get_option( 'everest_forms_review', array() );
740 $review['time'] = current_time( 'timestamp' ); // phpcs:ignore WordPress.DateTime.CurrentTimeTimestamp.Requested
741 $review['dismissed'] = true;
742 update_option( 'everest_forms_review', $review );
743 wp_die();
744 }
745
746 /**
747 * Triggered when clicking the survey notice button.
748 */
749 public static function survey_dismiss() {
750
751 if ( ! current_user_can( 'manage_everest_forms' ) ) {
752 wp_die( -1 );
753 }
754 $survey = get_option( 'everest_forms_survey', array() );
755 $survey['dismissed'] = true;
756 update_option( 'everest_forms_survey', $survey );
757 wp_die();
758 }
759
760 /**
761 * Triggered when clicking the form toggle.
762 */
763 public static function enabled_form() {
764 // Run a security check.
765 check_ajax_referer( 'everest_forms_enabled_form', 'security' );
766
767 $form_id = isset( $_POST['form_id'] ) ? absint( $_POST['form_id'] ) : 0;
768 $enabled = isset( $_POST['enabled'] ) ? absint( $_POST['enabled'] ) : 0;
769
770 if ( ! current_user_can( 'everest_forms_edit_form', $form_id ) ) {
771 wp_die( -1 );
772 }
773
774 $form_data = evf()->form->get( absint( $form_id ), array( 'content_only' => true ) );
775
776 $form_data['form_enabled'] = $enabled;
777
778 evf()->form->update( $form_id, $form_data );
779 }
780
781 /**
782 * Import Form ajax.
783 */
784 public static function import_form_action() {
785 try {
786 check_ajax_referer( 'process-import-ajax-nonce', 'security' );
787 EVF_Admin_Import_Export::import_form();
788 } catch ( Exception $e ) {
789 wp_send_json_error(
790 array(
791 'message' => $e->getMessage(),
792 )
793 );
794 }
795 }
796
797 /**
798 * Send test email.
799 */
800 public static function send_test_email() {
801 try {
802 check_ajax_referer( 'process-ajax-nonce', 'security' );
803 $from = esc_attr( get_bloginfo( 'name', 'display' ) );
804 $email = sanitize_email( isset( $_POST['email'] ) ? wp_unslash( $_POST['email'] ) : '' );
805
806 /* translators: %s: from address */
807 $subject = 'Everest Form: ' . sprintf( esc_html__( 'Test email from %s', 'everest-forms' ), $from );
808 $header = "Reply-To: {{from}} \r\n";
809 $header .= 'Content-Type: text/html; charset=UTF-8';
810 $message = sprintf(
811 '%s <br /> %s <br /> %s <br /> %s <br /> %s',
812 __( 'Congratulations,', 'everest-forms' ),
813 __( 'Your test email has been received successfully.', 'everest-forms' ),
814 __( 'We thank you for trying out Everest Forms and joining our mission to make sure you get your emails delivered.', 'everest-forms' ),
815 __( 'Regards,', 'everest-forms' ),
816 __( 'Everest Forms Team', 'everest-forms' )
817 );
818 $status = wp_mail( $email, $subject, $message, $header );
819 if ( $status ) {
820 wp_send_json_success( array( 'message' => __( 'Test email was sent successfully! Please check your inbox to make sure it is delivered.', 'everest-forms' ) ) );
821 } else {
822 wp_send_json_error( array( 'message' => __( 'Test email was unsuccessful! Something went wrong.', 'everest-forms' ) ) );
823 }
824 } catch ( Exception $e ) {
825 wp_send_json_error(
826 array(
827 'message' => $e->getMessage(),
828 )
829 );
830 }
831 }
832 }
833
834 EVF_AJAX::init();
835