PluginProbe ʕ •ᴥ•ʔ
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI / 1.9.9
Everest Forms – Contact Form, Payment Form, Quiz, Survey & Custom Form Builder with AI v1.9.9
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-form-task.php
everest-forms / includes Last commit date
abstracts 3 years ago admin 3 years ago elementor 4 years ago export 3 years ago fields 3 years ago interfaces 8 years ago libraries 7 years ago log-handlers 4 years ago shortcodes 3 years ago stats 3 years ago templates 5 years ago class-everest-forms.php 3 years ago class-evf-ajax.php 3 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-cron.php 3 years ago class-evf-deprecated-action-hooks.php 6 years ago class-evf-deprecated-filter-hooks.php 5 years ago class-evf-emails.php 3 years ago class-evf-fields.php 6 years ago class-evf-form-block.php 4 years ago class-evf-form-handler.php 3 years ago class-evf-form-task.php 3 years ago class-evf-forms-features.php 3 years ago class-evf-frontend-scripts.php 4 years ago class-evf-install.php 3 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 3 years ago class-evf-template-loader.php 3 years ago class-evf-validation.php 6 years ago evf-conditional-functions.php 6 years ago evf-core-functions.php 3 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-form-task.php
1073 lines
1 <?php
2 /**
3 * Process form data
4 *
5 * @package EverestForms
6 * @since 1.0.0
7 */
8
9 defined( 'ABSPATH' ) || exit;
10
11 /**
12 * EVF_Form_Task class.
13 */
14 class EVF_Form_Task {
15
16 /**
17 * Holds errors.
18 *
19 * @since 1.0.0
20 * @var array
21 */
22 public $errors;
23
24 /**
25 * Holds formatted fields.
26 *
27 * @since 1.0.0
28 * @var array
29 */
30 public $form_fields;
31
32 /**
33 * Holds the ID of a successful entry.
34 *
35 * @since 1.0.0
36 * @var int
37 */
38 public $entry_id = 0;
39
40 /**
41 * Form data and settings.
42 *
43 * @since 1.5.0
44 *
45 * @var array
46 */
47 public $form_data = array();
48
49 /**
50 * Is hash validation?
51 *
52 * @var 1.7.4
53 */
54 public $is_valid_hash = false;
55
56 /**
57 * Primary class constructor.
58 *
59 * @since 1.0.0
60 */
61 public function __construct() {
62 add_action( 'wp', array( $this, 'listen_task' ) );
63 add_filter( 'everest_forms_field_properties', array( $this, 'load_previous_field_value' ), 99, 3 );
64 }
65
66 /**
67 * Listen to see if this is a return callback or a posted form entry.
68 *
69 * @since 1.0.0
70 */
71 public function listen_task() {
72 if ( ! empty( $_GET['everest_forms_return'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
73 $this->entry_confirmation_redirect( '', sanitize_text_field( wp_unslash( $_GET['everest_forms_return'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification
74 }
75
76 $form_id = ! empty( $_POST['everest_forms']['id'] ) ? absint( $_POST['everest_forms']['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
77
78 if ( ! $form_id ) {
79 return;
80 }
81
82 if ( ! empty( $_POST['everest_forms']['id'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
83 $this->do_task( evf_sanitize_entry( wp_unslash( $_POST['everest_forms'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
84 }
85
86 if ( ! evf_is_amp() ) {
87 return;
88 }
89
90 $settings = $this->form_data['settings'];
91 $success_message = isset( $settings['successful_form_submission_message'] ) ? $settings['successful_form_submission_message'] : __( 'Thanks for contacting us! We will be in touch with you shortly.', 'everest-forms' );
92 // Send 400 Bad Request when there are errors.
93 if ( empty( $this->errors[ $form_id ] ) ) {
94 wp_send_json(
95 array(
96 'message' => $success_message,
97 ),
98 200
99 );
100
101 return;
102 }
103 $message = $this->errors[ $form_id ]['header'];
104
105 if ( ! empty( $this->errors[ $form_id ]['footer'] ) ) {
106 $message .= ' ' . $this->errors[ $form_id ]['footer'];
107 }
108
109 wp_send_json(
110 array(
111 'message' => $message,
112 ),
113 400
114 );
115
116 }
117
118 /**
119 * Do task of form entry
120 *
121 * @since 1.0.0
122 * @param array $entry $_POST object.
123 */
124 public function do_task( $entry ) {
125 $logger = evf_get_logger();
126 try {
127 $this->errors = array();
128 $this->form_fields = array();
129 $form_id = absint( $entry['id'] );
130 $form = evf()->form->get( $form_id );
131 $honeypot = false;
132 $response_data = array();
133 $this->ajax_err = array();
134 $this->evf_notice_print = false;
135 $logger = evf_get_logger();
136
137 // Check nonce for form submission.
138 if ( empty( $_POST[ '_wpnonce' . $form_id ] ) || ! wp_verify_nonce( wp_unslash( sanitize_key( $_POST[ '_wpnonce' . $form_id ] ) ), 'everest-forms_process_submit' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
139 $this->errors[ $form_id ]['header'] = esc_html__( 'We were unable to process your form, please try again.', 'everest-forms' );
140 $logger->error(
141 $this->errors[ $form_id ]['header'],
142 array( 'source' => 'form-submission' )
143 );
144 return $this->errors;
145 }
146
147 // Validate form is real and active (published).
148 if ( ! $form || 'publish' !== $form->post_status ) {
149 $this->errors[ $form_id ]['header'] = esc_html__( 'Invalid form. Please check again.', 'everest-forms' );
150 $logger->error(
151 $this->errors[ $form_id ]['header'],
152 array( 'source' => 'form-submission' )
153 );
154 return $this->errors;
155 }
156
157 // Formatted form data for hooks.
158 $this->form_data = apply_filters( 'everest_forms_process_before_form_data', evf_decode( $form->post_content ), $entry );
159
160 // Pre-process/validate hooks and filter. Data is not validated or cleaned yet so use with caution.
161 $entry = apply_filters( 'everest_forms_process_before_filter', $entry, $this->form_data );
162 $this->form_data['page_id'] = array_key_exists( 'post_id', $entry ) ? $entry['post_id'] : $form_id;
163
164 $logger->info(
165 __( 'Everest Forms Process Before.', 'everest-forms' ),
166 array( 'source' => 'form-submission' )
167 );
168 do_action( 'everest_forms_process_before', $entry, $this->form_data );
169 $logger->info(
170 __( 'Everest Forms Process Before Form ID.', 'everest-forms' ),
171 array( 'source' => 'form-submission' )
172 );
173 do_action( "everest_forms_process_before_{$form_id}", $entry, $this->form_data );
174
175 $ajax_form_submission = isset( $this->form_data['settings']['ajax_form_submission'] ) ? $this->form_data['settings']['ajax_form_submission'] : 0;
176 if ( isset( $this->form_data['payments']['stripe']['enable_stripe'] ) && '1' === $this->form_data['payments']['stripe']['enable_stripe'] ) {
177 $ajax_form_submission = '1';
178 }
179 if ( '1' === $ajax_form_submission ) {
180 // For the sake of validation we completely remove the validator option.
181 update_option( 'evf_validation_error', '' );
182
183 // Prepare fields for entry_save.
184 foreach ( $this->form_data['form_fields'] as $field ) {
185 if ( '' === isset( $this->form_data['form_fields']['meta-key'] ) ) {
186 continue;
187 }
188
189 $field_id = $field['id'];
190 $field_type = $field['type'];
191 $field_submit = isset( $entry['form_fields'][ $field_id ] ) ? $entry['form_fields'][ $field_id ] : '';
192
193 if ( 'signature' === $field_type ) {
194 $field_submit = isset( $field_submit['signature_image'] ) ? $field_submit['signature_image'] : '';
195 }
196
197 $exclude = array( 'title', 'html', 'captcha', 'image-upload', 'file-upload', 'divider', 'reset' );
198
199 if ( ! in_array( $field_type, $exclude, true ) ) {
200
201 $this->form_fields[ $field_id ] = array(
202 'id' => $field_id,
203 'name' => sanitize_text_field( $field['label'] ),
204 'meta_key' => $this->form_data['form_fields'][ $field_id ]['meta-key'],
205 'type' => $field_type,
206 'value' => evf_sanitize_textarea_field( $field_submit ),
207 );
208 }
209 }
210 }
211
212 $this->form_data['entry'] = $entry;
213
214 // Validate fields.
215 foreach ( $this->form_data['form_fields'] as $field ) {
216 $field_id = $field['id'];
217 $field_type = $field['type'];
218 $repeater_fields = array_key_exists( 'repeater-fields', $field ) ? $field['repeater-fields'] : 'no';
219
220 $field_submit = isset( $entry['form_fields'][ $field_id ] ) ? $entry['form_fields'][ $field_id ] : '';
221
222 if ( 'no' === $repeater_fields || 'repeater-fields' === $field_type ) {
223 $logger->info(
224 "Everest Forms Process Before validate {$field_type}.",
225 array( 'source' => 'form-submission' )
226 );
227 do_action( "everest_forms_process_validate_{$field_type}", $field_id, $field_submit, $this->form_data, $field_type );
228 }
229
230 if ( 'credit-card' === $field_type && isset( $_POST['everest_form_stripe_payment_intent_id'] ) ) {
231 $this->evf_notice_print = true;
232 }
233
234 if ( 'yes' === get_option( 'evf_validation_error' ) && $ajax_form_submission ) {
235 if ( count( $this->errors ) ) {
236 foreach ( $this->errors as $_error ) {
237 $this->ajax_err [] = $_error;
238 }
239 }
240 update_option( 'evf_validation_error', '' );
241 }
242 }
243
244 // If validation issues occur, send the results accordingly.
245 if ( $ajax_form_submission && count( $this->ajax_err ) ) {
246 $response_data['error'] = $this->ajax_err;
247 $response_data['message'] = __( 'Form has not been submitted, please see the errors below.', 'everest-forms' );
248 $response_data['response'] = 'error';
249 $logger->error(
250 __( 'Form has not been submitted.', 'everest-forms' ),
251 array( 'source' => 'form-submission' )
252 );
253 return $response_data;
254 }
255
256 // reCAPTCHA check.
257 if ( ! apply_filters( 'everest_forms_recaptcha_disabled', false ) ) {
258 $recaptcha_type = get_option( 'everest_forms_recaptcha_type', 'v2' );
259 $invisible_recaptcha = get_option( 'everest_forms_recaptcha_v2_invisible', 'no' );
260
261 if ( 'v2' === $recaptcha_type && 'no' === $invisible_recaptcha ) {
262 $site_key = get_option( 'everest_forms_recaptcha_v2_site_key' );
263 $secret_key = get_option( 'everest_forms_recaptcha_v2_secret_key' );
264 } elseif ( 'v2' === $recaptcha_type && 'yes' === $invisible_recaptcha ) {
265 $site_key = get_option( 'everest_forms_recaptcha_v2_invisible_site_key' );
266 $secret_key = get_option( 'everest_forms_recaptcha_v2_invisible_secret_key' );
267 } elseif ( 'v3' === $recaptcha_type ) {
268 $site_key = get_option( 'everest_forms_recaptcha_v3_site_key' );
269 $secret_key = get_option( 'everest_forms_recaptcha_v3_secret_key' );
270 } elseif ( 'hcaptcha' === $recaptcha_type ) {
271 $site_key = get_option( 'everest_forms_recaptcha_hcaptcha_site_key' );
272 $secret_key = get_option( 'everest_forms_recaptcha_hcaptcha_secret_key' );
273 }
274
275 if ( ! empty( $site_key ) && ! empty( $secret_key ) && isset( $this->form_data['settings']['recaptcha_support'] ) && '1' === $this->form_data['settings']['recaptcha_support'] &&
276 ! isset( $_POST['__amp_form_verify'] ) && ( 'v3' === $recaptcha_type || ! evf_is_amp() ) ) {
277 if ( 'hcaptcha' === $recaptcha_type ) {
278 $error = esc_html__( 'hCaptcha verification failed, please try again later.', 'everest-forms' );
279 } else {
280 $error = esc_html__( 'Google reCAPTCHA verification failed, please try again later.', 'everest-forms' );
281 }
282
283 $logger->error(
284 $error,
285 array( 'source' => 'Google reCAPTCHA' )
286 );
287
288 $token = ! empty( $_POST['g-recaptcha-response'] ) ? evf_clean( wp_unslash( $_POST['g-recaptcha-response'] ) ) : false;
289
290 if ( 'v3' === $recaptcha_type ) {
291 $token = ! empty( $_POST['everest_forms']['recaptcha'] ) ? evf_clean( wp_unslash( $_POST['everest_forms']['recaptcha'] ) ) : false;
292 }
293 if ( 'hcaptcha' === $recaptcha_type ) {
294 $token = ! empty( $_POST['h-captcha-response'] ) ? evf_clean( wp_unslash( $_POST['h-captcha-response'] ) ) : false;
295 $raw_response = wp_safe_remote_get( 'https://hcaptcha.com/siteverify?secret=' . $secret_key . '&response=' . $token );
296 } else {
297 $raw_response = wp_safe_remote_get( 'https://www.google.com/recaptcha/api/siteverify?secret=' . $secret_key . '&response=' . $token );
298 }
299
300 if ( ! is_wp_error( $raw_response ) ) {
301 $response = json_decode( wp_remote_retrieve_body( $raw_response ) );
302 // Check reCAPTCHA response.
303 if ( empty( $response->success ) || ( 'v3' === $recaptcha_type && $response->score <= get_option( 'everest_forms_recaptcha_v3_threshold_score', apply_filters( 'everest_forms_recaptcha_v3_threshold', '0.5' ) ) ) ) {
304 if ( 'v3' === $recaptcha_type ) {
305 if ( isset( $response->score ) ) {
306 $error .= ' (' . esc_html( $response->score ) . ')';
307 }
308 }
309 $this->errors[ $form_id ]['header'] = $error;
310 $logger->error(
311 $error,
312 array( 'source' => 'Google reCAPTCHA' )
313 );
314 return $this->errors;
315 }
316 }
317 }
318 }
319 // Initial error check.
320 $errors = apply_filters( 'everest_forms_process_initial_errors', $this->errors, $this->form_data );
321 if ( isset( $_POST['__amp_form_verify'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
322 if ( empty( $errors[ $form_id ] ) ) {
323 wp_send_json( array(), 200 );
324 } else {
325 $verify_errors = array();
326
327 foreach ( $errors[ $form_id ] as $field_id => $error_fields ) {
328 $field = $this->form_data['fields'][ $field_id ];
329 $field_properties = EVF_Shortcode_Form::get_field_properties( $field, $this->form_data );
330
331 if ( is_string( $error_fields ) ) {
332
333 if ( 'checkbox' === $field['type'] || 'radio' === $field['type'] || 'select' === $field['type'] ) {
334 $first = current( $field_properties['inputs'] );
335 $name = $first['attr']['name'];
336 } elseif ( isset( $field_properties['inputs']['primary']['attr']['name'] ) ) {
337 $name = $field_properties['inputs']['primary']['attr']['name'];
338 }
339
340 $verify_errors[] = array(
341 'name' => $name,
342 'message' => $error_fields,
343 );
344 } else {
345 foreach ( $error_fields as $error_field => $error_message ) {
346
347 if ( isset( $field_properties['inputs'][ $error_field ]['attr']['name'] ) ) {
348 $name = $field_properties['inputs'][ $error_field ]['attr']['name'];
349 }
350
351 $verify_errors[] = array(
352 'name' => $name,
353 'message' => $error_message,
354 );
355 }
356 }
357 }
358
359 wp_send_json(
360 array(
361 'verifyErrors' => $verify_errors,
362 ),
363 400
364 );
365 }
366 return;
367 }
368 if ( ! empty( $errors[ $form_id ] ) ) {
369 if ( empty( $errors[ $form_id ]['header'] ) ) {
370 $errors[ $form_id ]['header'] = __( 'Form has not been submitted, please see the errors below.', 'everest-forms' );
371 $logger->error(
372 $errors[ $form_id ]['header'],
373 array( 'source' => 'form-submission' )
374 );
375 }
376 $this->errors = $errors;
377 return $this->errors;
378 }
379
380 // Early honeypot validation - before actual processing.
381 if ( isset( $this->form_data['settings']['honeypot'] ) && '1' === $this->form_data['settings']['honeypot'] && ! empty( $entry['hp'] ) ) {
382 $honeypot = esc_html__( 'Everest Forms honeypot field triggered.', 'everest-forms' );
383 }
384
385 $honeypot = apply_filters( 'everest_forms_process_honeypot', $honeypot, $this->form_fields, $entry, $this->form_data );
386
387 // If spam - return early.
388 if ( $honeypot ) {
389 $logger = evf_get_logger();
390 $logger->notice( sprintf( 'Spam entry for Form ID %d Response: %s', absint( $this->form_data['id'] ), evf_print_r( $entry, true ) ), array( 'source' => 'honeypot' ) );
391 return $this->errors;
392 }
393
394 // Pass the form created date into the form data.
395 $this->form_data['created'] = $form->post_date;
396
397 // Format and Sanitize inputs.
398 foreach ( (array) $this->form_data['form_fields'] as $field ) {
399 $field_id = $field['id'];
400 $field_key = isset( $field['meta-key'] ) ? $field['meta-key'] : '';
401 $field_type = $field['type'];
402 $field_submit = isset( $entry['form_fields'][ $field_id ] ) ? $entry['form_fields'][ $field_id ] : '';
403 $repeater_fields = array_key_exists( 'repeater-fields', $field ) ? $field['repeater-fields'] : 'no';
404
405 if ( 'no' === $repeater_fields || 'repeater-fields' === $field_type ) {
406 $logger->info(
407 sprintf( 'Everest Forms Process Format %s.', $field_type ),
408 array( 'source' => 'form-submission' )
409 );
410 do_action( "everest_forms_process_format_{$field_type}", $field_id, $field_submit, $this->form_data, $field_key );
411 }
412 }
413
414 // This hook is for internal purposes and should not be leveraged.
415 $logger->info(
416 'Everest Forms Process Format After.',
417 array( 'source' => 'form-submission' )
418 );
419 do_action( 'everest_forms_process_format_after', $this->form_data );
420
421 // Process hooks/filter - this is where most addons should hook
422 // because at this point we have completed all field validation and
423 // formatted the data.
424 $this->form_fields = apply_filters( 'everest_forms_process_filter', $this->form_fields, $entry, $this->form_data );
425 $logger->notice( sprintf( 'Everest Form Process: %s', evf_print_r( $this->form_fields, true ) ) );
426
427 $logger->info(
428 'Everest Forms Process.',
429 array( 'source' => 'form-submission' )
430 );
431 do_action( 'everest_forms_process', $this->form_fields, $entry, $this->form_data );
432 $logger->info(
433 "Everest Forms Process {$form_id}.",
434 array( 'source' => 'form-submission' )
435 );
436 do_action( "everest_forms_process_{$form_id}", $this->form_fields, $entry, $this->form_data );
437
438 $this->form_fields = apply_filters( 'everest_forms_process_after_filter', $this->form_fields, $entry, $this->form_data );
439 $logger->notice( sprintf( 'Everest Form Process After: %s', evf_print_r( $this->form_fields, true ) ) );
440
441 // One last error check - don't proceed if there are any errors.
442 if ( ! empty( $this->errors[ $form_id ] ) ) {
443 if ( empty( $this->errors[ $form_id ]['header'] ) ) {
444 $this->errors[ $form_id ]['header'] = esc_html__( 'Form has not been submitted, please see the errors below.', 'everest-forms' );
445 }
446 $logger->error(
447 __( 'Form has not been submitted', 'everest-forms' ),
448 array( 'source' => 'form-submission' )
449 );
450 return $this->errors;
451 }
452
453 $logger->notice( sprintf( 'Entry is Saving to DataBase' ) );
454 // Success - add entry to database.
455 $logger->info(
456 __( 'Entry Added to Database.', 'everest-forms' ),
457 array( 'source' => 'form-submission' )
458 );
459 $entry_id = $this->entry_save( $this->form_fields, $entry, $this->form_data['id'], $this->form_data );
460 $logger->notice( sprintf( 'Entry is Saved to DataBase' ) );
461
462 $logger->notice( sprintf( 'Sending Email' ) );
463 // Success - send email notification.
464 $logger->info(
465 __( 'Sent Email Notification.', 'everest-forms' ),
466 array( 'source' => 'form-submission' )
467 );
468 $this->entry_email( $this->form_fields, $entry, $this->form_data, $entry_id, 'entry' );
469 $logger->notice( sprintf( 'Successfully Send the email' ) );
470
471 // @todo remove this way of printing notices.
472 add_filter( 'everest_forms_success', array( $this, 'check_success_message' ), 10, 2 );
473
474 // Pass completed and formatted fields in POST.
475 $_POST['everest-forms']['complete'] = $this->form_fields;
476
477 // Pass entry ID in POST.
478 $_POST['everest-forms']['entry_id'] = $entry_id;
479
480 // Post-process hooks.
481 $logger->info(
482 __( 'Everest Forms Process Completed.', 'everest-forms' ),
483 array( 'source' => 'form-submission' )
484 );
485 do_action( 'everest_forms_process_complete', $this->form_fields, $entry, $this->form_data, $entry_id );
486 $logger->info(
487 "Everest Forms Process Completed {$form_id}.",
488 array( 'source' => 'form-submission' )
489 );
490 do_action( "everest_forms_process_complete_{$form_id}", $this->form_fields, $entry, $this->form_data, $entry_id );
491 } catch ( Exception $e ) {
492 evf_add_notice( $e->getMessage(), 'error' );
493 $logger->error(
494 $e->getMessage(),
495 array( 'source' => 'form-submission' )
496 );
497 if ( '1' === $ajax_form_submission ) {
498 $this->errors[] = $e->getMessage();
499 $response_data['message'] = $this->errors;
500 $response_data['response'] = 'error';
501 return $response_data;
502 }
503 }
504
505 $settings = $this->form_data['settings'];
506 $message = isset( $settings['successful_form_submission_message'] ) ? $settings['successful_form_submission_message'] : __( 'Thanks for contacting us! We will be in touch with you shortly.', 'everest-forms' );
507 $pdf_submission = isset( $settings['pdf_submission']['enable_pdf_submission'] ) && 0 !== $settings['pdf_submission']['enable_pdf_submission'] ? $settings['pdf_submission'] : '';
508
509 if ( defined( 'EVF_PDF_SUBMISSION_VERSION' ) && ( 'yes' === get_option( 'everest_forms_pdf_download_after_submit', 'no' ) || ( isset( $pdf_submission['everest_forms_pdf_download_after_submit'] ) && 'yes' === $pdf_submission['everest_forms_pdf_download_after_submit'] ) ) ) {
510 global $__everest_form_id;
511 global $__everest_form_entry_id;
512 $__everest_form_id = $form_id;
513 $__everest_form_entry_id = $entry_id;
514 }
515
516 // Check Conditional Logic and get the redirection URL.
517 $submission_redirection_process = apply_filters( 'everest_forms_submission_redirection_process', array(), $this->form_fields, $this->form_data );
518
519 // Backward compatibility for evf form templates.
520 $this->form_data['settings']['redirect_to'] = '0' === $this->form_data['settings']['redirect_to'] ? 'same' : $this->form_data['settings']['redirect_to'];
521
522 if ( '1' === $ajax_form_submission ) {
523 $response_data['message'] = $message;
524 $response_data['response'] = 'success';
525 $response_data['form_id'] = $form_id;
526 $response_data['entry_id'] = $entry_id;
527
528 if ( defined( 'EVF_PDF_SUBMISSION_VERSION' ) && ( 'yes' === get_option( 'everest_forms_pdf_download_after_submit', 'no' ) || ( isset( $pdf_submission['everest_forms_pdf_download_after_submit'] ) && 'yes' === $pdf_submission['everest_forms_pdf_download_after_submit'] ) ) ) {
529 $response_data['pdf_download'] = true;
530 $pdf_download_message = get_option( 'everest_forms_pdf_custom_download_text', '' );
531
532 if ( isset( $pdf_submission['everest_forms_pdf_custom_download_text'] ) ) {
533 $pdf_download_message = $pdf_submission['everest_forms_pdf_custom_download_text'];
534 }
535
536 if ( empty( $pdf_download_message ) ) {
537 $pdf_download_message = __( 'Download your form submission in PDF format', 'everest-forms' );
538 }
539 $response_data['pdf_download_message'] = $pdf_download_message;
540 }
541
542 // Backward Compatibility Check.
543 switch ( $settings['redirect_to'] ) {
544 case '0':
545 $settings['redirect_to'] = 'same';
546 break;
547
548 case '1':
549 $settings['redirect_to'] = 'custom_page';
550 break;
551
552 case '2':
553 $settings['redirect_to'] = 'external_url';
554 break;
555 }
556
557 // Check for Submission Redirection in Ajax Submission.
558 if ( empty( $submission_redirection_process ) ) {
559 if ( isset( $settings['redirect_to'] ) && 'external_url' === $settings['redirect_to'] ) {
560 $response_data['redirect_url'] = isset( $settings['external_url'] ) ? esc_url( $settings['external_url'] ) : 'undefined';
561 } elseif ( isset( $settings['redirect_to'] ) && 'custom_page' === $settings['redirect_to'] ) {
562 $response_data['redirect_url'] = isset( $settings['custom_page'] ) ? get_page_link( absint( $settings['custom_page'] ) ) : 'undefined';
563 }
564 } else {
565 $response_data['redirect_url'] = $submission_redirection_process['external_url'];
566 }
567
568 // Add notice only if credit card is populated in form fields.
569 if ( isset( $this->evf_notice_print ) && $this->evf_notice_print ) {
570 evf_add_notice( $message, 'success' );
571 }
572 // $this->entry_confirmation_redirect( $this->form_data );
573 $response_data = apply_filters( 'everest_forms_after_success_ajax_message', $response_data, $this->form_data, $entry );
574 return $response_data;
575 } elseif ( ( 'same' === $this->form_data['settings']['redirect_to'] && empty( $submission_redirection_process ) ) || ( ! empty( $submission_redirection_process ) && 'same_page' == $submission_redirection_process['redirect_to'] ) ) {
576 evf_add_notice( $message, 'success' );
577 }
578 $logger->info(
579 'Everest Forms After success Message.',
580 array( 'source' => 'form-submission' )
581 );
582
583 do_action( 'everest_forms_after_success_message', $this->form_data, $entry );
584 $this->entry_confirmation_redirect( $this->form_data );
585
586 }
587
588 /**
589 * Process AJAX form submission.
590 *
591 * @since 1.6.0
592 *
593 * @param mixed $posted_data Posted data.
594 */
595 public function ajax_form_submission( $posted_data ) {
596 add_filter( 'wp_redirect', array( $this, 'ajax_process_redirect' ), 999 );
597 $process = $this->do_task( $posted_data );
598 return $process;
599 }
600
601 /**
602 * Process AJAX redirect.
603 *
604 * @since 1.6.0
605 *
606 * @param string $url Redirect URL.
607 */
608 public function ajax_process_redirect( $url ) {
609 $form_id = isset( $_POST['everest_forms']['id'] ) ? absint( $_POST['everest_forms']['id'] ) : 0; // phpcs:ignore WordPress.Security.NonceVerification
610
611 if ( empty( $form_id ) ) {
612 wp_send_json_error();
613 }
614
615 $response = array(
616 'form_id' => $form_id,
617 'redirect_url' => $url,
618 );
619
620 $response = apply_filters( 'everest_forms_ajax_submit_redirect', $response, $form_id, $url );
621
622 do_action( 'everest_forms_ajax_submit_completed', $form_id, $response );
623 wp_send_json_success( $response );
624 }
625
626 /**
627 * Check the sucessful message.
628 *
629 * @param bool $status Message status.
630 * @param int $form_id Form ID.
631 */
632 public function check_success_message( $status, $form_id ) {
633 if ( isset( $this->form_data['id'] ) && absint( $this->form_data['id'] ) === $form_id ) {
634 return true;
635 }
636 return false;
637 }
638
639 /**
640 * Validate the form return hash.
641 *
642 * @since 1.0.0
643 *
644 * @param string $hash Base64-encoded hash of form and entry IDs.
645 * @return array|false False for invalid or form id.
646 */
647 public function validate_return_hash( $hash = '' ) {
648 $query_args = base64_decode( $hash );
649
650 parse_str( $query_args, $output );
651
652 // Verify hash matches.
653 if ( wp_hash( $output['form_id'] . ',' . $output['entry_id'] ) !== $output['hash'] ) {
654 return false;
655 }
656
657 // Get lead and verify it is attached to the form we received with it.
658 $entry = evf_get_entry( $output['entry_id'] );
659
660 if ( empty( $entry->form_id ) ) {
661 return false;
662 }
663
664 if ( $output['form_id'] !== $entry->form_id ) {
665 return false;
666 }
667
668 return array(
669 'form_id' => absint( $output['form_id'] ),
670 'entry_id' => absint( $output['form_id'] ),
671 'fields' => null !== $entry && isset( $entry->fields ) ? $entry->fields : array(),
672 );
673 }
674
675 /**
676 * Redirects user to a page or URL specified in the form confirmation settings.
677 *
678 * @since 1.0.0
679 *
680 * @param array $form_data Form data and settings.
681 * @param string $hash Base64-encoded hash of form and entry IDs.
682 */
683 public function entry_confirmation_redirect( $form_data = '', $hash = '' ) {
684 $_POST = array(); // Clear fields after successful form submission.
685
686 // Process return hash.
687 if ( ! empty( $hash ) ) {
688 $hash_data = $this->validate_return_hash( $hash );
689
690 if ( ! $hash_data || ! is_array( $hash_data ) ) {
691 return;
692 }
693
694 $this->is_valid_hash = true;
695 $this->entry_id = absint( $hash_data['entry_id'] );
696 $this->form_fields = json_decode( $hash_data['fields'], true );
697 $this->form_data = evf()->form->get(
698 absint( $hash_data['form_id'] ),
699 array(
700 'content_only' => true,
701 )
702 );
703 } else {
704 $this->form_data = $form_data;
705 }
706
707 $settings = $this->form_data['settings'];
708
709 // Backward Compatibility Check.
710 switch ( $settings['redirect_to'] ) {
711 case '0':
712 $settings['redirect_to'] = 'same';
713 break;
714
715 case '1':
716 $settings['redirect_to'] = 'custom_page';
717 break;
718
719 case '2':
720 $settings['redirect_to'] = 'external_url';
721 break;
722 }
723
724 $submission_redirect_process = apply_filters( 'everest_forms_submission_redirection_process', array(), $this->form_fields, $this->form_data );
725
726 if ( ! empty( $submission_redirect_process ) ) {
727 $settings['redirect_to'] = $submission_redirect_process['redirect_to'];
728 $settings['external_url'] = $submission_redirect_process['external_url'];
729 $settings['custom_page'] = $submission_redirect_process['custom_page'];
730 }
731
732 if ( isset( $settings['redirect_to'] ) && 'custom_page' === $settings['redirect_to'] ) {
733 if ( isset( $settings['enable_redirect_query_string'] ) && '1' === $settings['enable_redirect_query_string'] ) {
734 parse_str( $settings['query_string'], $output );
735 $query_redirect_url = array();
736 foreach ( $output as $key => $value ) {
737 $query_redirect_url[ $key ] = apply_filters( 'everest_forms_process_smart_tags', $value, $this->form_data, $this->form_fields );
738 }
739 $redirect_url = add_query_arg( $query_redirect_url, esc_url( get_page_link( $settings['custom_page'] ) ) );
740 } else {
741 $redirect_url = get_page_link( $settings['custom_page'] );
742 }
743
744 ?>
745 <script>
746 var redirect = '<?php echo esc_url_raw( $redirect_url ); ?>';
747 window.setTimeout( function () {
748 window.location.href = redirect;
749 })
750 </script>
751 <?php
752 } elseif ( isset( $settings['redirect_to'] ) && 'external_url' === $settings['redirect_to'] ) {
753 ?>
754 <script>
755 window.setTimeout( function () {
756 window.location.href = '<?php echo esc_url( $settings['external_url'] ); ?>';
757 })
758 </script>
759 <?php
760 }
761
762 // Redirect if needed, to either a page or URL, after form processing.
763 if ( ! empty( $this->form_data['settings']['confirmation_type'] ) && 'message' !== $this->form_data['settings']['confirmation_type'] ) {
764 if ( 'redirect' === $this->form_data['settings']['confirmation_type'] ) {
765 $url = apply_filters( 'everest_forms_process_smart_tags', $this->form_data['settings']['confirmation_redirect'], $this->form_data, $this->form_fields, $this->entry_id );
766 }
767
768 if ( 'page' === $this->form_data['settings']['confirmation_type'] ) {
769 $url = get_permalink( (int) $this->form_data['settings']['confirmation_page'] );
770 }
771 }
772
773 if ( ! empty( $this->form_data['id'] ) ) {
774 $form_id = $this->form_data['id'];
775 } else {
776 return;
777 }
778 if ( isset( $settings['submission_message_scroll'] ) && $settings['submission_message_scroll'] ) {
779 add_filter( 'everest_forms_success_notice_class', array( $this, 'add_scroll_notice_class' ) );
780 }
781
782 if ( ! empty( $url ) ) {
783 $url = apply_filters( 'everest_forms_process_redirect_url', $url, $form_id, $this->form_fields );
784 wp_safe_redirect( esc_url_raw( $url ) );
785 do_action( 'everest_forms_process_redirect', $form_id );
786 do_action( "everest_forms_process_redirect_{$form_id}", $form_id );
787 exit;
788 }
789 }
790
791 /**
792 * Add scroll notice class.
793 *
794 * @param array $classes Notice Classes.
795 * @return array of notice classes.
796 */
797 public function add_scroll_notice_class( $classes ) {
798 $classes[] = 'everest-forms-submission-scroll';
799
800 return $classes;
801 }
802
803 /**
804 * Sends entry email notifications.
805 *
806 * @param array $fields List of fields.
807 * @param array $entry Submitted form entry.
808 * @param array $form_data Form data and settings.
809 * @param int $entry_id Saved entry id.
810 * @param string $context In which context this email is sent.
811 */
812 public function entry_email( $fields, $entry, $form_data, $entry_id, $context = '' ) {
813 // Provide the opportunity to override via a filter.
814 if ( ! apply_filters( 'everest_forms_entry_email', true, $fields, $entry, $form_data ) ) {
815 return;
816 }
817
818 // Make sure we have an entry id.
819 if ( empty( $this->entry_id ) ) {
820 $this->entry_id = (int) $entry_id;
821 }
822
823 $fields = apply_filters( 'everest_forms_entry_email_data', $fields, $entry, $form_data );
824
825 if ( ! isset( $form_data['settings']['email']['connection_1'] ) ) {
826 $old_email_data = $form_data['settings']['email'];
827 $form_data['settings']['email'] = array();
828 $form_data['settings']['email']['connection_1'] = array( 'connection_name' => __( 'Admin Notification', 'everest-forms' ) );
829
830 $email_settings = array( 'evf_to_email', 'evf_from_name', 'evf_from_email', 'evf_reply_to', 'evf_email_subject', 'evf_email_message', 'attach_pdf_to_admin_email', 'show_header_in_attachment_pdf_file', 'conditional_logic_status', 'conditional_option', 'conditionals' );
831 foreach ( $email_settings as $email_setting ) {
832 $form_data['settings']['email']['connection_1'][ $email_setting ] = isset( $old_email_data[ $email_setting ] ) ? $old_email_data[ $email_setting ] : '';
833 }
834 }
835
836 $notifications = isset( $form_data['settings']['email'] ) ? $form_data['settings']['email'] : array();
837
838 foreach ( $notifications as $connection_id => $notification ) :
839
840 // Don't proceed if email notification is not enabled.
841 if ( isset( $notification['enable_email_notification'] ) && '1' !== $notification['enable_email_notification'] ) {
842 continue;
843 }
844
845 $process_email = apply_filters( 'everest_forms_entry_email_process', true, $fields, $form_data, $context, $connection_id );
846
847 if ( ! $process_email ) {
848 continue;
849 }
850
851 $email = array();
852 $evf_to_email = isset( $notification['evf_to_email'] ) ? $notification['evf_to_email'] : '';
853
854 // Setup email properties.
855 /* translators: %s - form name. */
856 $email['subject'] = ! empty( $notification['evf_email_subject'] ) ? $notification['evf_email_subject'] : sprintf( esc_html__( 'New %s Entry', 'everest-forms' ), $form_data['settings']['form_title'] );
857 $email['address'] = explode( ',', apply_filters( 'everest_forms_process_smart_tags', $evf_to_email, $form_data, $fields, $this->entry_id ) );
858 $email['address'] = array_map( 'sanitize_email', $email['address'] );
859 $email['sender_name'] = ! empty( $notification['evf_from_name'] ) ? $notification['evf_from_name'] : get_bloginfo( 'name' );
860 $email['sender_address'] = ! empty( $notification['evf_from_email'] ) ? $notification['evf_from_email'] : get_option( 'admin_email' );
861 $email['reply_to'] = ! empty( $notification['evf_reply_to'] ) ? $notification['evf_reply_to'] : $email['sender_address'];
862 $email['message'] = ! empty( $notification['evf_email_message'] ) ? evf_string_translation( $form_data['id'], 'evf_email_message', $notification['evf_email_message'] ) : '{all_fields}';
863 $email = apply_filters( 'everest_forms_entry_email_atts', $email, $fields, $entry, $form_data );
864 $attachment = '';
865
866 // Create new email.
867 $emails = new EVF_Emails();
868 $emails->__set( 'form_data', $form_data );
869 $emails->__set( 'fields', $fields );
870 $emails->__set( 'entry_id', $entry_id );
871 $emails->__set( 'from_name', $email['sender_name'] );
872 $emails->__set( 'from_address', $email['sender_address'] );
873 $emails->__set( 'reply_to', $email['reply_to'] );
874
875 /**
876 * This filter relies on consistent data being passed for the resultant filters to function.
877 * The third param passed for the filter, $fields, is derived from validation routine, not the DB.
878 */
879 $emails->__set( 'attachments', apply_filters( 'everest_forms_email_file_attachments', $attachment, $fields, $form_data, 'entry-email', $connection_id, $entry_id ) );
880
881 // Maybe include Cc and Bcc email addresses.
882 if ( 'yes' === get_option( 'everest_forms_enable_email_copies' ) ) {
883 if ( ! empty( $notification['evf_carboncopy'] ) ) {
884 $emails->__set( 'cc', $notification['evf_carboncopy'] );
885 }
886 if ( ! empty( $notification['evf_blindcarboncopy'] ) ) {
887 $emails->__set( 'bcc', $notification['evf_blindcarboncopy'] );
888 }
889 }
890
891 $emails = apply_filters( 'everest_forms_entry_email_before_send', $emails );
892
893 // Send entry email.
894 foreach ( $email['address'] as $address ) {
895 $emails->send( trim( $address ), $email['subject'], $email['message'], '', $connection_id );
896 }
897
898 endforeach;
899 }
900
901 /**
902 * Saves entry to database.
903 *
904 * @param array $fields List of form fields.
905 * @param array $entry User submitted data.
906 * @param int $form_id Form ID.
907 * @param array $form_data Prepared form settings.
908 * @return int
909 */
910 public function entry_save( $fields, $entry, $form_id, $form_data = array() ) {
911 global $wpdb;
912
913 // Check if form has entries disabled.
914 if ( isset( $form_data['settings']['disabled_entries'] ) && '1' === $form_data['settings']['disabled_entries'] ) {
915 return;
916 }
917
918 // Provide the opportunity to override via a filter.
919 if ( ! apply_filters( 'everest_forms_entry_save', true, $fields, $entry, $form_data ) ) {
920 return;
921 }
922
923 do_action( 'everest_forms_process_entry_save', $fields, $entry, $form_id, $form_data );
924
925 $fields = apply_filters( 'everest_forms_entry_save_data', $fields, $entry, $form_data );
926 $browser = evf_get_browser();
927 $user_ip = evf_get_ip_address();
928 $user_device = evf_get_user_device();
929 $user_agent = $browser['name'] . '/' . $browser['platform'] . '/' . $user_device;
930 $referer = ! empty( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
931 $entry_id = false;
932
933 // GDPR enhancements - If user details are disabled globally discard the IP and UA.
934 if ( 'yes' === get_option( 'everest_forms_disable_user_details' ) ) {
935 $user_agent = '';
936 $user_ip = '';
937 }
938
939 $entry_data = apply_filters(
940 'everest_forms_entry_data',
941 array(
942 'form_id' => $form_id,
943 'user_id' => get_current_user_id(),
944 'user_device' => sanitize_text_field( $user_agent ),
945 'user_ip_address' => sanitize_text_field( $user_ip ),
946 'status' => 'publish',
947 'referer' => $referer,
948 'fields' => wp_json_encode( $fields ),
949 'date_created' => current_time( 'mysql', true ),
950 ),
951 $entry
952 );
953
954 if ( ! $entry_data['form_id'] ) {
955 return new WP_Error( 'no-form-id', __( 'No form ID was found.', 'everest-forms' ) );
956 }
957
958 // Create entry.
959 $success = $wpdb->insert( $wpdb->prefix . 'evf_entries', $entry_data );
960
961 if ( is_wp_error( $success ) || ! $success ) {
962 return new WP_Error( 'could-not-create', __( 'Could not create an entry', 'everest-forms' ) );
963 }
964
965 $entry_id = $wpdb->insert_id;
966
967 // Create meta data.
968 if ( $entry_id ) {
969 foreach ( $fields as $field ) {
970 $field = apply_filters( 'everest_forms_entry_save_fields', $field, $form_data, $entry_id );
971 // Add only whitelisted fields to entry meta.
972 if ( in_array( $field['type'], array( 'html', 'title' ), true ) ) {
973 continue;
974 }
975
976 // If empty file is supplied, don't store their data nor send email.
977 if ( in_array( $field['type'], array( 'image-upload', 'file-upload' ), true ) ) {
978
979 // BW compatibility for previous file uploader.
980 if ( isset( $field['value']['file_url'] ) && '' === $field['value']['file_url'] ) {
981 continue;
982 }
983 }
984
985 // If empty label is provided for choice field, don't store their data nor send email.
986 if ( in_array( $field['type'], array( 'radio', 'payment-multiple' ), true ) ) {
987 if ( isset( $field['value']['label'] ) && '' === $field['value']['label'] ) {
988 continue;
989 }
990 } elseif ( in_array( $field['type'], array( 'checkbox', 'payment-checkbox' ), true ) ) {
991 if ( isset( $field['value']['label'] ) && ( empty( $field['value']['label'] ) || '' === current( $field['value']['label'] ) ) ) {
992 continue;
993 }
994 }
995
996 if ( isset( $field['meta_key'], $field['value'] ) && '' !== $field['value'] ) {
997 $entry_metadata = array(
998 'entry_id' => $entry_id,
999 'meta_key' => sanitize_key( $field['meta_key'] ),
1000 'meta_value' => maybe_serialize( $field['value'] ), // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value
1001 );
1002
1003 // Insert entry meta.
1004 $wpdb->insert( $wpdb->prefix . 'evf_entrymeta', $entry_metadata );
1005 }
1006 }
1007 }
1008
1009 $this->entry_id = $entry_id;
1010
1011 // Removing Entries Cache.
1012 wp_cache_delete( $entry_id, 'evf-entry' );
1013 wp_cache_delete( $entry_id, 'evf-entrymeta' );
1014 wp_cache_delete( $form_id, 'evf-entries-ids' );
1015 wp_cache_delete( $form_id, 'evf-last-entries-count' );
1016 wp_cache_delete( $form_id, 'evf-search-entries' );
1017 wp_cache_delete( EVF_Cache_Helper::get_cache_prefix( 'entries' ) . '_unread_count', 'entries' );
1018
1019 do_action( 'everest_forms_complete_entry_save', $entry_id, $fields, $entry, $form_id, $form_data );
1020
1021 return $this->entry_id;
1022 }
1023
1024 /**
1025 * Load Previous Field Value.
1026 *
1027 * @param string $properties Value.
1028 * @param mixed $field Field.
1029 * @param mixed $form_data Form Data.
1030 * @return $properties Properties.
1031 */
1032 public function load_previous_field_value( $properties, $field, $form_data ) {
1033
1034 if ( ! isset( $_POST['everest_forms'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1035 return $properties;
1036 }
1037 $data = ! empty( $_POST['everest_forms']['form_fields'][ $field['id'] ] ) ? wp_unslash( $_POST['everest_forms']['form_fields'][ $field['id'] ] ) : array(); // phpcs:ignore WordPress.Security.NonceVerification, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1038
1039 if ( 'checkbox' === $field['type'] ) {
1040 foreach ( $field['choices'] as $key => $option_value ) {
1041 $selected = ! empty( $option_value['default'] ) ? $option_value['default'] : '';
1042 foreach ( $data as $value ) {
1043 if ( $value === $option_value['label'] ) {
1044 $selected = 1;
1045 $properties['inputs'][ $key ]['default'] = $selected;
1046 }
1047 }
1048 }
1049 } elseif ( 'radio' === $field['type'] || 'select' === $field['type'] ) {
1050 foreach ( $field['choices'] as $key => $option_value ) {
1051 if ( $data === $option_value['label'] ) { // phpcs:ignore WordPress.Security.NonceVerification
1052 $selected = 1;
1053 $properties['inputs'][ $key ]['default'] = $selected;
1054 }
1055 }
1056 } elseif ( 'likert' === $field['type'] ) {
1057 if ( count( $data ) ) {
1058 foreach ( $data as $row => $col ) {
1059 foreach ( (array) $col as $col_selected ) {
1060 $index = sprintf( 'rows%d_columns%d', (int) $row, (int) $col_selected );
1061 $properties['inputs'][ $index ]['attr']['checked'] = true;
1062 }
1063 }
1064 }
1065 } else {
1066 if ( ! is_array( $data ) ) {
1067 $properties['inputs']['primary']['attr']['value'] = esc_attr( $data );
1068 }
1069 }
1070 return $properties;
1071 }
1072 }
1073