PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/models/FrmEntryValidate.php +112 -322 6.256.2 View file →
@@ -3,21 +3,8 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmEntryValidate {
7 -
8 - /**
9 - * @since 6.17
10 - *
11 - * @var array|null
12 - */
13 - private static $name_text_fields;
14 -
15 - /**
16 - * @param array $values
17 - * @param bool|string[] $exclude
18 - * @return array
19 - */
20 7 public static function validate( $values, $exclude = false ) {
21 8 FrmEntry::sanitize_entry_post( $values );
22 9 $errors = array();
23 10
@@ -31,9 +18,8 @@
31 18 $frm_settings = FrmAppHelper::get_settings();
32 19 $errors['form'] = $frm_settings->admin_permission;
33 20 }
34 21
35 - self::maybe_fix_item_meta();
36 22 self::set_item_key( $values );
37 23
38 24 $posted_fields = self::get_fields_to_validate( $values, $exclude );
39 25
@@ -57,34 +43,13 @@
57 43 * @param array $errors Errors data.
58 44 * @param array $values Value data of the form.
59 45 * @param array $args Custom arguments. Contains `exclude` and `posted_fields`.
60 46 */
61 - $filtered_errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
47 + $errors = apply_filters( 'frm_validate_entry', $errors, $values, compact( 'exclude', 'posted_fields' ) );
62 48
63 - if ( is_array( $filtered_errors ) ) {
64 - $errors = $filtered_errors;
65 - } else {
66 - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_validate_entry filter.', '6.3' );
67 - }
68 -
69 49 return $errors;
70 50 }
71 51
72 - /**
73 - * In case $_POST['item_meta'] is not an array, change it to an empty array.
74 - * This helps to avoid some warnings and errors when $_POST['item_meta'] is updated.
75 - *
76 - * @since 6.6
77 - *
78 - * @return void
79 - */
80 - private static function maybe_fix_item_meta() {
81 - // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated
82 - if ( ! isset( $_POST['item_meta'] ) || ! is_array( $_POST['item_meta'] ) ) {
83 - $_POST['item_meta'] = array();
84 - }
85 - }
86 -
87 52 private static function set_item_key( &$values ) {
88 53 if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) {
89 54 global $wpdb;
90 55 $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
@@ -118,20 +83,16 @@
118 83
119 84 public static function validate_field( $posted_field, &$errors, $values, $args = array() ) {
120 85 $defaults = array(
121 86 'id' => $posted_field->id,
122 - // The id of the repeat or embed form.
123 - 'parent_field_id' => '',
124 - // The pointer in the posted array.
125 - 'key_pointer' => '',
126 - // Exclude these field types from validation.
127 - 'exclude' => array(),
128 -
87 + 'parent_field_id' => '', // the id of the repeat or embed form
88 + 'key_pointer' => '', // the pointer in the posted array
89 + 'exclude' => array(), // exclude these field types from validation
129 90 );
130 - $args = wp_parse_args( $args, $defaults );
91 + $args = wp_parse_args( $args, $defaults );
131 92
132 93 if ( empty( $args['parent_field_id'] ) ) {
133 - $value = $values['item_meta'][ $args['id'] ] ?? '';
94 + $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : '';
134 95 } else {
135 96 // value is from a nested form
136 97 $value = $values;
137 98 }
@@ -157,9 +118,8 @@
157 118 }
158 119
159 120 FrmEntriesHelper::set_posted_value( $posted_field, $value, $args );
160 121
161 - self::validate_options( $errors, $posted_field, $value, $args );
162 122 self::validate_field_types( $errors, $posted_field, $value, $args );
163 123
164 124 // Field might want to modify value before other parts of the system
165 125 // e.g. trim off excess values like in the case of fields with limit.
@@ -170,188 +130,16 @@
170 130 }
171 131
172 132 $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args );
173 133 $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args );
174 -
175 - if ( ! FrmAppHelper::pro_is_installed() && empty( $args['other'] ) ) {
176 - FrmEntriesHelper::get_posted_value( $posted_field, $value, $args );
177 - }
178 134 }
179 135
180 136 /**
181 - * @since 6.21
182 - *
183 - * @param array $errors
184 - * @param object $posted_field
185 - * @param array|string $value
186 - * @param array $args
187 - *
188 - * @return void
189 - */
190 - private static function validate_options( &$errors, $posted_field, $value, $args ) {
191 - if ( empty( $posted_field->options ) ) {
192 - return;
193 - }
194 -
195 - $option_is_valid = self::option_is_valid( $posted_field, $value, $posted_field->options );
196 -
197 - /**
198 - * @since 6.21
199 - *
200 - * @param bool $option_is_valid
201 - * @param array|string $value
202 - * @param object $field
203 - */
204 - $option_is_valid = (bool) apply_filters( 'frm_option_is_valid', $option_is_valid, $value, $posted_field );
205 -
206 - if ( ! $option_is_valid ) {
207 - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'invalid' );
208 - }
209 - }
210 -
211 - /**
212 - * Validate that value matches one of the options for the field.
213 - *
214 - * @since 6.21
215 - *
216 - * @param stdClass $field
217 - * @param array|string $value
218 - * @param array $options
219 - * @return bool
220 - */
221 - private static function option_is_valid( $field, $value, $options ) {
222 - if ( '' === $value ) {
223 - return true;
224 - }
225 -
226 - $field_object = FrmFieldFactory::get_field_type( $field->type, $field );
227 - if ( ! $field_object->field_type_has_options_settings() ) {
228 - return true;
229 - }
230 -
231 - if ( in_array( $field->type, array( 'likert', 'ranking' ), true ) ) {
232 - // Ignore these field types automatically.
233 - return true;
234 - }
235 -
236 - if ( 'product' === $field->type && 'user_def' === FrmField::get_option( $field, 'data_type' ) ) {
237 - return true;
238 - }
239 -
240 - if ( ! empty( $field->field_options['post_field'] ) ) {
241 - return true;
242 - }
243 -
244 - $value = (array) $value;
245 -
246 - foreach ( $value as $current_value ) {
247 - $match = false;
248 -
249 - foreach ( $options as $key => $option ) {
250 - if ( strpos( $key, 'other_' ) === 0 ) {
251 - // Always return true if an other option is found.
252 - return true;
253 - }
254 -
255 - if ( is_array( $option ) ) {
256 - $separate_value = FrmField::get_option( $field, 'separate_value' );
257 - $option_value = $separate_value ? $option['value'] : $option['label'];
258 - } else {
259 - $option_value = $option;
260 - }
261 -
262 - $match = trim( $current_value ) === trim( $option_value );
263 - if ( $match ) {
264 - break;
265 - }
266 -
267 - $match = trim( $current_value ) === trim( do_shortcode( $option_value ) );
268 - if ( $match ) {
269 - break;
270 - }
271 -
272 - $match = self::is_filtered_match( $current_value, $option_value );
273 - if ( $match ) {
274 - break;
275 - }
276 -
277 - if ( is_numeric( $current_value ) ) {
278 - $match = (int) $current_value === (int) $option_value;
279 - if ( $match ) {
280 - break;
281 - }
282 - }
283 - }//end foreach
284 -
285 - if ( ! $match ) {
286 - return self::options_are_dynamic_based_on_hook( $field, $value );
287 - }
288 - }//end foreach
289 -
290 - return true;
291 - }
292 -
293 - /**
294 - * Make an extra check after passing $option_value through the_content filter.
295 - * This is to help catch cases where the option's formatting has been modified using
296 - * the_content filter.
297 - *
298 - * @since 6.22
299 - *
300 - * @param string $value
301 - * @param string $option_value
302 - * @return bool
303 - */
304 - private static function is_filtered_match( $value, $option_value ) {
305 - // First remove the wpautop filter so it doesn't add extra tags to $option_value.
306 - $filter_priority = has_filter( 'the_content', 'wpautop' );
307 - if ( is_numeric( $filter_priority ) ) {
308 - remove_filter( 'the_content', 'wpautop', $filter_priority );
309 - }
310 - $filtered_option = apply_filters( 'the_content', $option_value );
311 - if ( is_numeric( $filter_priority ) ) {
312 - add_filter( 'the_content', 'wpautop', $filter_priority );
313 - }
314 - return trim( $value ) === trim( $filtered_option );
315 - }
316 -
317 - /**
318 - * Do not validate options if they have been modified with a hook.
319 - * This is to help avoid issues where the options could be based on a URL param for example.
320 - *
321 - * @since 6.21
322 - *
323 - * @return bool
324 - */
325 - private static function options_are_dynamic_based_on_hook( $field_object, $value ) {
326 - $values = (array) $field_object;
327 - $values['value'] = $value;
328 - FrmFieldsHelper::prepare_new_front_field( $values, $field_object );
329 -
330 - $separate_value = FrmField::get_option( $field_object, 'separate_value' );
331 - $map_callback = function ( $option ) use ( $separate_value ) {
332 - if ( is_array( $option ) ) {
333 - $option_value = $separate_value ? $option['value'] : $option['label'];
334 - } else {
335 - $option_value = $option;
336 - }
337 - $option_value = do_shortcode( $option_value );
338 - return $option_value;
339 - };
340 -
341 - $values_options = array_map( $map_callback, $values['options'] );
342 - $field_object_options = array_map( $map_callback, $field_object->options );
343 -
344 - return $values_options !== $field_object_options;
345 - }
346 -
347 - /**
348 137 * Maybe add item_name to $_POST to save it in items table.
349 138 *
350 139 * @since 5.2.02
351 140 *
352 - * @param array|string $value Field value.
353 - * @param object $field Field object.
141 + * @param object $field Field object.
354 142 */
355 143 private static function maybe_add_item_name( $value, $field ) {
356 144 $item_name = false;
357 145 if ( 'name' === $field->type ) {
@@ -395,11 +183,10 @@
395 183 }
396 184 }
397 185
398 186 public static function validate_phone_field( &$errors, $field, $value, $args ) {
399 - $format_value = FrmField::get_option( $field, 'format' );
187 + if ( $field->type == 'phone' || ( $field->type == 'text' && FrmField::is_option_true_in_object( $field, 'format' ) ) ) {
400 188
401 - if ( $field->type === 'phone' || ( $field->type === 'text' && $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ) ) ) {
402 189 $pattern = self::phone_format( $field );
403 190
404 191 if ( ! preg_match( $pattern, $value ) ) {
405 192 $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' );
@@ -413,11 +200,8 @@
413 200 } else {
414 201 $pattern = FrmField::get_option( $field, 'format' );
415 202 }
416 203
417 - // Ampersands are saved as &.
418 - // Reverse it here so we are checking for the correct character.
419 - $pattern = html_entity_decode( $pattern );
420 204 $pattern = apply_filters( 'frm_phone_pattern', $pattern, $field );
421 205
422 206 // Create a regexp if format is not already a regexp
423 207 if ( strpos( $pattern, '^' ) !== 0 ) {
@@ -474,36 +258,27 @@
474 258 return $pattern;
475 259 }
476 260
477 261 /**
478 - * Check for spam.
262 + * Check for spam
479 263 *
480 - * @param bool $exclude
264 + * @param boolean $exclude
481 265 * @param array $values
482 - * @param array $errors By reference.
266 + * @param array $errors by reference
483 267 */
484 268 public static function spam_check( $exclude, $values, &$errors ) {
485 - if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
486 - // Do not check spam on importing.
487 - return;
488 - }
489 -
490 - if ( ! empty( $exclude ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
269 + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) {
491 270 // only check spam if there are no other errors
492 271 return;
493 272 }
494 273
495 274 $antispam_check = self::is_antispam_check( $values['form_id'] );
496 - $spam_msg = FrmAntiSpamController::get_default_spam_message();
497 275 if ( is_string( $antispam_check ) ) {
498 276 $errors['spam'] = $antispam_check;
499 277 } elseif ( self::is_honeypot_spam( $values ) || self::is_spam_bot() ) {
500 - $errors['spam'] = $spam_msg;
501 - } else {
502 - $is_spam = FrmAntiSpamController::is_spam( $values );
503 - if ( $is_spam ) {
504 - $errors['spam'] = $is_spam;
505 - }
278 + $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' );
279 + } elseif ( self::blacklist_check( $values ) ) {
280 + $errors['spam'] = __( 'Your entry appears to be blocked spam!', 'formidable' );
506 281 }
507 282
508 283 if ( isset( $errors['spam'] ) || self::form_is_in_progress( $values ) ) {
509 284 return;
@@ -539,9 +314,9 @@
539 314 }
540 315
541 316 /**
542 317 * @param array $values
543 - * @return bool
318 + * @return boolean
544 319 */
545 320 private static function is_honeypot_spam( $values ) {
546 321 $honeypot = new FrmHoneypot( $values['form_id'] );
547 322 return ! $honeypot->validate();
@@ -547,9 +322,9 @@
547 322 return ! $honeypot->validate();
548 323 }
549 324
550 325 /**
551 - * @return bool
326 + * @return boolean
552 327 */
553 328 private static function is_spam_bot() {
554 329 $ip = FrmAppHelper::get_ip_address();
555 330
@@ -557,9 +332,9 @@
557 332 }
558 333
559 334 /**
560 335 * @param array $values
561 - * @return bool
336 + * @return boolean
562 337 */
563 338 private static function is_akismet_spam( $values ) {
564 339 global $wpcom_api_key;
565 340
@@ -575,23 +350,59 @@
575 350
576 351 return ( ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] !== 'logged' || ! is_user_logged_in() ) );
577 352 }
578 353
354 + public static function blacklist_check( $values ) {
355 + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) {
356 + return false;
357 + }
358 +
359 + $mod_keys = trim( self::get_disallowed_words() );
360 + if ( empty( $mod_keys ) ) {
361 + return false;
362 + }
363 +
364 + $content = FrmEntriesHelper::entry_array_to_string( $values );
365 +
366 + self::prepare_values_for_spam_check( $values );
367 + $ip = FrmAppHelper::get_ip_address();
368 + $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' );
369 + $user_info = self::get_spam_check_user_info( $values );
370 +
371 + return self::check_disallowed_words( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent );
372 + }
373 +
579 374 /**
580 - * Checks spam using WordPress disallowed words and Frm denylist.
375 + * For WP 5.5 compatibility.
581 376 *
582 - * @param array $values Entry values.
377 + * @since 4.06.02
378 + */
379 + private static function check_disallowed_words( $author, $email, $url, $content, $ip, $user_agent ) {
380 + if ( function_exists( 'wp_check_comment_disallowed_list' ) ) {
381 + return wp_check_comment_disallowed_list( $author, $email, $url, $content, $ip, $user_agent );
382 + } else {
383 + return wp_blacklist_check( $author, $email, $url, $content, $ip, $user_agent );
384 + }
385 + }
386 +
387 + /**
388 + * For WP 5.5 compatibility.
583 389 *
584 - * @return bool
390 + * @since 4.06.02
585 391 */
586 - public static function blacklist_check( $values ) {
587 - return FrmAntiSpamController::contains_wp_disallowed_words( $values ) || FrmAntiSpamController::is_denylist_spam( $values );
392 + private static function get_disallowed_words() {
393 + $keys = get_option( 'disallowed_keys' );
394 + if ( false === $keys ) {
395 + // Fallback for WP < 5.5.
396 + $keys = get_option( 'blacklist_keys' );
397 + }
398 + return $keys;
588 399 }
589 400
590 401 /**
591 402 * Check entries for Akismet spam
592 403 *
593 - * @return bool true if is spam
404 + * @return boolean true if is spam
594 405 */
595 406 public static function akismet( $values ) {
596 407 if ( empty( $values['item_meta'] ) ) {
597 408 return false;
@@ -613,9 +424,9 @@
613 424
614 425 $query_string = _http_build_query( $datas, '', '&' );
615 426 $response = Akismet::http_post( $query_string, 'comment-check' );
616 427
617 - return ( is_array( $response ) && $response[1] === 'true' );
428 + return ( is_array( $response ) && $response[1] == 'true' );
618 429 }
619 430
620 431 /**
621 432 * @since 2.0
@@ -624,9 +435,8 @@
624 435 self::add_site_info_to_akismet( $datas );
625 436 self::add_server_values_to_akismet( $datas );
626 437
627 438 self::prepare_values_for_spam_check( $values );
628 - self::skip_adding_values_to_akismet( $values );
629 439
630 440 self::add_user_info_to_akismet( $datas, $values );
631 441 self::add_comment_content_to_akismet( $datas, $values );
632 442 }
@@ -656,14 +466,13 @@
656 466 /**
657 467 * Gets user info for Akismet spam check.
658 468 *
659 469 * @since 5.0.13 Separate code for guest. Handle value of embedded|repeater.
660 - * @since 6.21 This changed from private to public.
661 470 *
662 471 * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}.
663 472 * @return array
664 473 */
665 - public static function get_spam_check_user_info( $values ) {
474 + private static function get_spam_check_user_info( $values ) {
666 475 if ( ! is_user_logged_in() ) {
667 476 return self::get_spam_check_user_info_for_guest( $values );
668 477 }
669 478
@@ -720,10 +529,9 @@
720 529 */
721 530 private static function recursive_add_akismet_guest_info( &$datas, $values, $custom_index = null ) {
722 531 foreach ( $values as $index => $value ) {
723 532 if ( ! $datas['missing_keys'] ) {
724 - // Found all info.
725 - return;
533 + return; // Found all info.
726 534 }
727 535
728 536 if ( is_array( $value ) ) {
729 537 self::recursive_add_akismet_guest_info( $datas, $value, $index );
@@ -731,9 +539,9 @@
731 539 }
732 540
733 541 $field_id = ! is_null( $custom_index ) ? $custom_index : $index;
734 542 foreach ( $datas['missing_keys'] as $key_index => $key ) {
735 - $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'], $values );
543 + $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'] );
736 544 if ( $found ) {
737 545 $datas[ $key ] = $value;
738 546 $datas['frm_duplicated'][] = $field_id;
739 547 unset( $datas['missing_keys'][ $key_index ] );
@@ -738,9 +546,9 @@
738 546 $datas['frm_duplicated'][] = $field_id;
739 547 unset( $datas['missing_keys'][ $key_index ] );
740 548 }
741 549 }
742 - }//end foreach
550 + }
743 551 }
744 552
745 553 /**
746 554 * Checks if given value is an akismet guest info.
@@ -750,13 +558,11 @@
750 558 * @param string $key Guest info key.
751 559 * @param string $value Value to check.
752 560 * @param int $field_id Field ID.
753 561 * @param array $name_field_ids Name field IDs.
754 - * @param array $values Array of posted values.
755 - *
756 562 * @return bool
757 563 */
758 - private static function is_akismet_guest_info_value( $key, &$value, $field_id, $name_field_ids, $values ) {
564 + private static function is_akismet_guest_info_value( $key, $value, $field_id, $name_field_ids ) {
759 565 if ( ! $value || is_numeric( $value ) ) {
760 566 return false;
761 567 }
762 568
@@ -767,62 +573,18 @@
767 573 case 'comment_author_url':
768 574 return 0 === strpos( $value, 'http' );
769 575
770 576 case 'comment_author':
771 - if ( $name_field_ids && in_array( $field_id, $name_field_ids, true ) ) {
577 + if ( $name_field_ids ) {
772 578 // If there is name field in the form, we should always use it as author name.
773 - return true;
579 + return in_array( $field_id, $name_field_ids, true );
774 580 }
775 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
776 - $fields = self::get_name_text_fields( $form_id );
581 + return strlen( $value ) < 200;
582 + }
777 583
778 - foreach ( $fields as $index => $field ) {
779 - if ( 'Name' !== $field->name ) {
780 - continue;
781 - }
782 - if ( isset( $fields[ $index + 1 ] ) && 'Last' === $fields[ $index + 1 ]->name ) {
783 - if ( empty( $values[ absint( $fields[ $index + 1 ]->id ) ] ) ) {
784 - continue;
785 - }
786 - $value .= ' ' . $values[ $fields[ $index + 1 ]->id ];
787 - return true;
788 - }
789 - }
790 - }//end switch
791 -
792 584 return false;
793 585 }
794 586
795 - /**
796 - * Returns fields that have 'Name' and 'Last' as their name.
797 - *
798 - * @since 6.17
799 - *
800 - * @param int $form_id
801 - * @return array
802 - */
803 - private static function get_name_text_fields( $form_id ) {
804 - $name_text_fields_is_initialized = is_array( self::$name_text_fields );
805 - if ( $name_text_fields_is_initialized && isset( self::$name_text_fields[ $form_id ] ) ) {
806 - return self::$name_text_fields[ $form_id ];
807 - }
808 - if ( ! $name_text_fields_is_initialized ) {
809 - self::$name_text_fields = array();
810 - }
811 - self::$name_text_fields[ $form_id ] = FrmDb::get_results(
812 - 'frm_fields',
813 - array(
814 - 'form_id' => $form_id,
815 - 'type' => 'text',
816 - 'name' => array( 'Name', 'Last' ),
817 - ),
818 - 'id,name',
819 - array( 'order_by' => 'field_order ASC' )
820 - );
821 -
822 - return self::$name_text_fields[ $form_id ];
823 - }
824 -
825 587 private static function add_server_values_to_akismet( &$datas ) {
826 588 foreach ( $_SERVER as $key => $value ) {
827 589 $include_value = is_string( $value ) && ! preg_match( '/^HTTP_COOKIE/', $key ) && preg_match( '/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/', $key );
828 590
@@ -853,8 +615,10 @@
853 615 }
854 616 unset( $datas['frm_duplicated'] );
855 617 }
856 618
619 + self::skip_adding_values_to_akismet( $values );
620 +
857 621 $datas['comment_content'] = FrmEntriesHelper::entry_array_to_string( $values );
858 622 }
859 623
860 624 /**
@@ -889,16 +653,14 @@
889 653 * @param array $values Entry values.
890 654 * @return bool
891 655 */
892 656 private static function should_really_skip_field( $field_data, $values ) {
893 - if ( empty( $field_data->options ) ) {
894 - // This is skipped field types.
657 + if ( empty( $field_data->options ) ) { // This is skipped field types.
895 658 return true;
896 659 }
897 660
898 661 FrmAppHelper::unserialize_or_decode( $field_data->options );
899 - if ( ! $field_data->options ) {
900 - // Check if an error happens when unserializing, or empty options.
662 + if ( ! $field_data->options ) { // Check if an error happens when unserializing, or empty options.
901 663 return true;
902 664 }
903 665
904 666 end( $field_data->options );
@@ -915,9 +677,9 @@
915 677 }
916 678
917 679 // Check if submitted value is same as one of field option.
918 680 foreach ( $field_data->options as $option ) {
919 - $option_value = ! is_array( $option ) ? $option : ( $option['value'] ?? '' );
681 + $option_value = ! is_array( $option ) ? $option : ( isset( $option['value'] ) ? $option['value'] : '' );
920 682 if ( $values['item_meta']['other'][ $field_data->id ] === $option_value ) {
921 683 return true;
922 684 }
923 685 }
@@ -956,13 +718,12 @@
956 718 /**
957 719 * Prepares values array for spam check.
958 720 *
959 721 * @since 5.0.13
960 - * @since 6.21 This changed from private to public.
961 722 *
962 723 * @param array $values Entry values.
963 724 */
964 - public static function prepare_values_for_spam_check( &$values ) {
725 + private static function prepare_values_for_spam_check( &$values ) {
965 726 $form_ids = self::get_all_form_ids_and_flatten_meta( $values );
966 727 $values['form_ids'] = $form_ids;
967 728 }
968 729
@@ -981,10 +742,9 @@
981 742
982 743 // Blacklist check for File field in the old version doesn't contain `form_id`.
983 744 $form_ids = isset( $values['form_id'] ) ? array( absint( $values['form_id'] ) ) : array();
984 745 foreach ( $values['item_meta'] as $field_id => $value ) {
985 - if ( ! is_numeric( $field_id ) ) {
986 - // Maybe `other`.
746 + if ( ! is_numeric( $field_id ) ) { // Maybe `other`.
987 747 continue;
988 748 }
989 749
990 750 // Convert name array to string.
@@ -1020,16 +780,46 @@
1020 780
1021 781 $values['name_field_ids'][] = $subsubindex;
1022 782 }
1023 783
1024 - if ( is_array( $values['item_meta'][ $subsubindex ] ) ) {
1025 - $values['item_meta'][ $subsubindex ][] = $subsubvalue;
1026 - }
784 + $values['item_meta'][ $subsubindex ][] = $subsubvalue;
1027 785 }
1028 - }//end foreach
786 + }
1029 787
1030 788 unset( $values['item_meta'][ $field_id ] );
1031 - }//end foreach
789 + }
1032 790
1033 791 return $form_ids;
792 + }
793 +
794 + /**
795 + * @deprecated 3.0
796 + * @codeCoverageIgnore
797 + */
798 + public static function validate_url_field( &$errors, $field, $value, $args ) {
799 + FrmDeprecated::validate_url_field( $errors, $field, $value, $args );
800 + }
801 +
802 + /**
803 + * @deprecated 3.0
804 + * @codeCoverageIgnore
805 + */
806 + public static function validate_email_field( &$errors, $field, $value, $args ) {
807 + FrmDeprecated::validate_email_field( $errors, $field, $value, $args );
808 + }
809 +
810 + /**
811 + * @deprecated 3.0
812 + * @codeCoverageIgnore
813 + */
814 + public static function validate_number_field( &$errors, $field, $value, $args ) {
815 + FrmDeprecated::validate_number_field( $errors, $field, $value, $args );
816 + }
817 +
818 + /**
819 + * @deprecated 3.0
820 + * @codeCoverageIgnore
821 + */
822 + public static function validate_recaptcha( &$errors, $field, $args ) {
823 + FrmDeprecated::validate_recaptcha( $errors, $field, $args );
1034 824 }
1035 825 }