| @@ -3,22 +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 | - * | |
| 19 | - * @return array | |
| 20 | - */ | |
| 21 | 7 | public static function validate( $values, $exclude = false ) { |
| 22 | 8 | FrmEntry::sanitize_entry_post( $values ); |
| 23 | 9 | $errors = array(); |
| 24 | 10 | |
| @@ -32,9 +18,8 @@ | ||
| 32 | 18 | $frm_settings = FrmAppHelper::get_settings(); |
| 33 | 19 | $errors['form'] = $frm_settings->admin_permission; |
| 34 | 20 | } |
| 35 | 21 | |
| 36 | - self::maybe_fix_item_meta(); | |
| 37 | 22 | self::set_item_key( $values ); |
| 38 | 23 | |
| 39 | 24 | $posted_fields = self::get_fields_to_validate( $values, $exclude ); |
| 40 | 25 | |
| @@ -58,39 +43,13 @@ | ||
| 58 | 43 | * @param array $errors Errors data. |
| 59 | 44 | * @param array $values Value data of the form. |
| 60 | 45 | * @param array $args Custom arguments. Contains `exclude` and `posted_fields`. |
| 61 | 46 | */ |
| 62 | - $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' ) ); | |
| 63 | 48 | |
| 64 | - if ( is_array( $filtered_errors ) ) { | |
| 65 | - $errors = $filtered_errors; | |
| 66 | - } else { | |
| 67 | - _doing_it_wrong( __METHOD__, 'Only arrays should be returned when using the frm_validate_entry filter.', '6.3' ); | |
| 68 | - } | |
| 69 | - | |
| 70 | 49 | return $errors; |
| 71 | 50 | } |
| 72 | 51 | |
| 73 | - /** | |
| 74 | - * In case $_POST['item_meta'] is not an array, change it to an empty array. | |
| 75 | - * This helps to avoid some warnings and errors when $_POST['item_meta'] is updated. | |
| 76 | - * | |
| 77 | - * @since 6.6 | |
| 78 | - * | |
| 79 | - * @return void | |
| 80 | - */ | |
| 81 | - private static function maybe_fix_item_meta() { | |
| 82 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 83 | - if ( ! isset( $_POST['item_meta'] ) || ! is_array( $_POST['item_meta'] ) ) { | |
| 84 | - $_POST['item_meta'] = array(); | |
| 85 | - } | |
| 86 | - } | |
| 87 | - | |
| 88 | - /** | |
| 89 | - * @param array $values | |
| 90 | - * | |
| 91 | - * @return void | |
| 92 | - */ | |
| 93 | 52 | private static function set_item_key( &$values ) { |
| 94 | 53 | if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
| 95 | 54 | global $wpdb; |
| 96 | 55 | $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
| @@ -97,14 +56,8 @@ | ||
| 97 | 56 | $_POST['item_key'] = $values['item_key']; |
| 98 | 57 | } |
| 99 | 58 | } |
| 100 | 59 | |
| 101 | - /** | |
| 102 | - * @param array $values | |
| 103 | - * @param array|string $exclude | |
| 104 | - * | |
| 105 | - * @return array | |
| 106 | - */ | |
| 107 | 60 | private static function get_fields_to_validate( $values, $exclude ) { |
| 108 | 61 | $where = apply_filters( 'frm_posted_field_ids', array( 'fi.form_id' => $values['form_id'] ) ); |
| 109 | 62 | |
| 110 | 63 | // Don't get subfields |
| @@ -127,31 +80,19 @@ | ||
| 127 | 80 | */ |
| 128 | 81 | return apply_filters( 'frm_fields_to_validate', $fields, compact( 'values', 'exclude', 'where' ) ); |
| 129 | 82 | } |
| 130 | 83 | |
| 131 | - /** | |
| 132 | - * @param object $posted_field | |
| 133 | - * @param array $errors | |
| 134 | - * @param array $values | |
| 135 | - * @param array $args | |
| 136 | - * | |
| 137 | - * @return void | |
| 138 | - */ | |
| 139 | 84 | public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
| 140 | 85 | $defaults = array( |
| 141 | 86 | 'id' => $posted_field->id, |
| 142 | - // The id of the repeat or embed form. | |
| 143 | - 'parent_field_id' => '', | |
| 144 | - // The pointer in the posted array. | |
| 145 | - 'key_pointer' => '', | |
| 146 | - // Exclude these field types from validation. | |
| 147 | - 'exclude' => array(), | |
| 148 | - | |
| 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 | |
| 149 | 90 | ); |
| 150 | - $args = wp_parse_args( $args, $defaults ); | |
| 91 | + $args = wp_parse_args( $args, $defaults ); | |
| 151 | 92 | |
| 152 | 93 | if ( empty( $args['parent_field_id'] ) ) { |
| 153 | - $value = $values['item_meta'][ $args['id'] ] ?? ''; | |
| 94 | + $value = isset( $values['item_meta'][ $args['id'] ] ) ? $values['item_meta'][ $args['id'] ] : ''; | |
| 154 | 95 | } else { |
| 155 | 96 | // value is from a nested form |
| 156 | 97 | $value = $values; |
| 157 | 98 | } |
| @@ -161,9 +102,8 @@ | ||
| 161 | 102 | |
| 162 | 103 | self::maybe_clear_value_for_default_blank_setting( $posted_field, $value ); |
| 163 | 104 | |
| 164 | 105 | $should_trim = is_array( $value ) && count( $value ) == 1 && isset( $value[0] ) && $posted_field->type !== 'checkbox'; |
| 165 | - | |
| 166 | 106 | if ( $should_trim ) { |
| 167 | 107 | $value = reset( $value ); |
| 168 | 108 | } |
| 169 | 109 | |
| @@ -178,9 +118,8 @@ | ||
| 178 | 118 | } |
| 179 | 119 | |
| 180 | 120 | FrmEntriesHelper::set_posted_value( $posted_field, $value, $args ); |
| 181 | 121 | |
| 182 | - self::validate_options( $errors, $posted_field, $value, $args ); | |
| 183 | 122 | self::validate_field_types( $errors, $posted_field, $value, $args ); |
| 184 | 123 | |
| 185 | 124 | // Field might want to modify value before other parts of the system |
| 186 | 125 | // e.g. trim off excess values like in the case of fields with limit. |
| @@ -191,208 +130,19 @@ | ||
| 191 | 130 | } |
| 192 | 131 | |
| 193 | 132 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 194 | 133 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
| 195 | - | |
| 196 | - if ( ! FrmAppHelper::pro_is_installed() && empty( $args['other'] ) ) { | |
| 197 | - FrmEntriesHelper::get_posted_value( $posted_field, $value, $args ); | |
| 198 | - } | |
| 199 | 134 | } |
| 200 | 135 | |
| 201 | 136 | /** |
| 202 | - * @since 6.21 | |
| 203 | - * | |
| 204 | - * @param array $errors | |
| 205 | - * @param object $posted_field | |
| 206 | - * @param array|string $value | |
| 207 | - * @param array $args | |
| 208 | - * | |
| 209 | - * @return void | |
| 210 | - */ | |
| 211 | - private static function validate_options( &$errors, $posted_field, $value, $args ) { | |
| 212 | - if ( empty( $posted_field->options ) ) { | |
| 213 | - return; | |
| 214 | - } | |
| 215 | - | |
| 216 | - $option_is_valid = self::option_is_valid( $posted_field, $value, $posted_field->options ); | |
| 217 | - | |
| 218 | - /** | |
| 219 | - * @since 6.21 | |
| 220 | - * | |
| 221 | - * @param bool $option_is_valid | |
| 222 | - * @param array|string $value | |
| 223 | - * @param object $field | |
| 224 | - */ | |
| 225 | - $option_is_valid = (bool) apply_filters( 'frm_option_is_valid', $option_is_valid, $value, $posted_field ); | |
| 226 | - | |
| 227 | - if ( ! $option_is_valid ) { | |
| 228 | - $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $posted_field, 'invalid' ); | |
| 229 | - } | |
| 230 | - } | |
| 231 | - | |
| 232 | - /** | |
| 233 | - * Validate that value matches one of the options for the field. | |
| 234 | - * | |
| 235 | - * @since 6.21 | |
| 236 | - * | |
| 237 | - * @param stdClass $field | |
| 238 | - * @param array|string $value | |
| 239 | - * @param array $options | |
| 240 | - * | |
| 241 | - * @return bool | |
| 242 | - */ | |
| 243 | - private static function option_is_valid( $field, $value, $options ) { | |
| 244 | - if ( '' === $value ) { | |
| 245 | - return true; | |
| 246 | - } | |
| 247 | - | |
| 248 | - $field_object = FrmFieldFactory::get_field_type( $field->type, $field ); | |
| 249 | - | |
| 250 | - if ( ! $field_object->field_type_has_options_settings() ) { | |
| 251 | - return true; | |
| 252 | - } | |
| 253 | - | |
| 254 | - if ( in_array( $field->type, array( 'likert', 'ranking' ), true ) ) { | |
| 255 | - // Ignore these field types automatically. | |
| 256 | - return true; | |
| 257 | - } | |
| 258 | - | |
| 259 | - if ( 'product' === $field->type && 'user_def' === FrmField::get_option( $field, 'data_type' ) ) { | |
| 260 | - return true; | |
| 261 | - } | |
| 262 | - | |
| 263 | - if ( ! empty( $field->field_options['post_field'] ) ) { | |
| 264 | - return true; | |
| 265 | - } | |
| 266 | - | |
| 267 | - $value = (array) $value; | |
| 268 | - | |
| 269 | - foreach ( $value as $current_value ) { | |
| 270 | - $match = false; | |
| 271 | - | |
| 272 | - foreach ( $options as $key => $option ) { | |
| 273 | - if ( strpos( $key, 'other_' ) === 0 ) { | |
| 274 | - // Always return true if an other option is found. | |
| 275 | - return true; | |
| 276 | - } | |
| 277 | - | |
| 278 | - if ( is_array( $option ) ) { | |
| 279 | - $separate_value = FrmField::get_option( $field, 'separate_value' ); | |
| 280 | - $option_value = $separate_value ? $option['value'] : $option['label']; | |
| 281 | - } else { | |
| 282 | - $option_value = $option; | |
| 283 | - } | |
| 284 | - | |
| 285 | - $match = trim( $current_value ) === trim( $option_value ); | |
| 286 | - | |
| 287 | - if ( $match ) { | |
| 288 | - break; | |
| 289 | - } | |
| 290 | - | |
| 291 | - $match = trim( $current_value ) === trim( do_shortcode( $option_value ) ); | |
| 292 | - | |
| 293 | - if ( $match ) { | |
| 294 | - break; | |
| 295 | - } | |
| 296 | - | |
| 297 | - $match = self::is_filtered_match( $current_value, $option_value ); | |
| 298 | - | |
| 299 | - if ( $match ) { | |
| 300 | - break; | |
| 301 | - } | |
| 302 | - | |
| 303 | - if ( is_numeric( $current_value ) ) { | |
| 304 | - $match = (int) $current_value === (int) $option_value; | |
| 305 | - | |
| 306 | - if ( $match ) { | |
| 307 | - break; | |
| 308 | - } | |
| 309 | - } | |
| 310 | - }//end foreach | |
| 311 | - | |
| 312 | - if ( ! $match ) { | |
| 313 | - return self::options_are_dynamic_based_on_hook( $field, $value ); | |
| 314 | - } | |
| 315 | - }//end foreach | |
| 316 | - | |
| 317 | - return true; | |
| 318 | - } | |
| 319 | - | |
| 320 | - /** | |
| 321 | - * Make an extra check after passing $option_value through the_content filter. | |
| 322 | - * This is to help catch cases where the option's formatting has been modified using | |
| 323 | - * the_content filter. | |
| 324 | - * | |
| 325 | - * @since 6.22 | |
| 326 | - * | |
| 327 | - * @param string $value | |
| 328 | - * @param string $option_value | |
| 329 | - * | |
| 330 | - * @return bool | |
| 331 | - */ | |
| 332 | - private static function is_filtered_match( $value, $option_value ) { | |
| 333 | - // First remove the wpautop filter so it doesn't add extra tags to $option_value. | |
| 334 | - $filter_priority = has_filter( 'the_content', 'wpautop' ); | |
| 335 | - | |
| 336 | - if ( is_numeric( $filter_priority ) ) { | |
| 337 | - remove_filter( 'the_content', 'wpautop', $filter_priority ); | |
| 338 | - } | |
| 339 | - | |
| 340 | - $filtered_option = apply_filters( 'the_content', $option_value ); | |
| 341 | - | |
| 342 | - if ( is_numeric( $filter_priority ) ) { | |
| 343 | - add_filter( 'the_content', 'wpautop', $filter_priority ); | |
| 344 | - } | |
| 345 | - return trim( $value ) === trim( $filtered_option ); | |
| 346 | - } | |
| 347 | - | |
| 348 | - /** | |
| 349 | - * Do not validate options if they have been modified with a hook. | |
| 350 | - * This is to help avoid issues where the options could be based on a URL param for example. | |
| 351 | - * | |
| 352 | - * @since 6.21 | |
| 353 | - * | |
| 354 | - * @param object $field_object The field object. | |
| 355 | - * @param array|string $value The value to validate. | |
| 356 | - * | |
| 357 | - * @return bool | |
| 358 | - */ | |
| 359 | - private static function options_are_dynamic_based_on_hook( $field_object, $value ) { | |
| 360 | - $values = (array) $field_object; | |
| 361 | - $values['value'] = $value; | |
| 362 | - FrmFieldsHelper::prepare_new_front_field( $values, $field_object ); | |
| 363 | - | |
| 364 | - $separate_value = FrmField::get_option( $field_object, 'separate_value' ); | |
| 365 | - $map_callback = function ( $option ) use ( $separate_value ) { | |
| 366 | - if ( is_array( $option ) ) { | |
| 367 | - $option_value = $separate_value ? $option['value'] : $option['label']; | |
| 368 | - } else { | |
| 369 | - $option_value = $option; | |
| 370 | - } | |
| 371 | - | |
| 372 | - $option_value = do_shortcode( $option_value ); | |
| 373 | - return $option_value; | |
| 374 | - }; | |
| 375 | - | |
| 376 | - $values_options = array_map( $map_callback, $values['options'] ); | |
| 377 | - $field_object_options = array_map( $map_callback, $field_object->options ); | |
| 378 | - | |
| 379 | - return $values_options !== $field_object_options; | |
| 380 | - } | |
| 381 | - | |
| 382 | - /** | |
| 383 | 137 | * Maybe add item_name to $_POST to save it in items table. |
| 384 | 138 | * |
| 385 | 139 | * @since 5.2.02 |
| 386 | 140 | * |
| 387 | - * @param array|string $value Field value. | |
| 388 | - * @param object $field Field object. | |
| 389 | - * | |
| 390 | - * @return void | |
| 141 | + * @param object $field Field object. | |
| 391 | 142 | */ |
| 392 | 143 | private static function maybe_add_item_name( $value, $field ) { |
| 393 | 144 | $item_name = false; |
| 394 | - | |
| 395 | 145 | if ( 'name' === $field->type ) { |
| 396 | 146 | $field_obj = FrmFieldFactory::get_field_object( $field ); |
| 397 | 147 | $item_name = $field_obj->get_display_value( $value ); |
| 398 | 148 | } elseif ( 'text' === $field->type ) { |
| @@ -399,10 +149,9 @@ | ||
| 399 | 149 | $item_name = $value; |
| 400 | 150 | } |
| 401 | 151 | |
| 402 | 152 | if ( false !== $item_name ) { |
| 403 | - // Item name has a max length of 255 characters so truncate it so it doesn't fail to save in the database. | |
| 404 | - $_POST['item_name'] = substr( $item_name, 0, 255 ); | |
| 153 | + $_POST['item_name'] = $item_name; | |
| 405 | 154 | } |
| 406 | 155 | } |
| 407 | 156 | |
| 408 | 157 | /** |
| @@ -409,14 +158,11 @@ | ||
| 409 | 158 | * Set $value to an empty string if it matches its label |
| 410 | 159 | * |
| 411 | 160 | * @param object $field |
| 412 | 161 | * @param string $value |
| 413 | - * | |
| 414 | - * @return void | |
| 415 | 162 | */ |
| 416 | 163 | private static function maybe_clear_value_for_default_blank_setting( $field, &$value ) { |
| 417 | 164 | $position = FrmField::get_option( $field, 'label' ); |
| 418 | - | |
| 419 | 165 | if ( ! $position ) { |
| 420 | 166 | $position = FrmStylesController::get_style_val( 'position', $field->form_id ); |
| 421 | 167 | } |
| 422 | 168 | |
| @@ -424,16 +170,8 @@ | ||
| 424 | 170 | $value = ''; |
| 425 | 171 | } |
| 426 | 172 | } |
| 427 | 173 | |
| 428 | - /** | |
| 429 | - * @param array $errors | |
| 430 | - * @param object $posted_field | |
| 431 | - * @param mixed $value | |
| 432 | - * @param array $args | |
| 433 | - * | |
| 434 | - * @return void | |
| 435 | - */ | |
| 436 | 174 | public static function validate_field_types( &$errors, $posted_field, $value, $args ) { |
| 437 | 175 | $field_obj = FrmFieldFactory::get_field_object( $posted_field ); |
| 438 | 176 | $args['value'] = $value; |
| 439 | 177 | $args['errors'] = $errors; |
| @@ -438,26 +176,16 @@ | ||
| 438 | 176 | $args['value'] = $value; |
| 439 | 177 | $args['errors'] = $errors; |
| 440 | 178 | |
| 441 | 179 | $new_errors = $field_obj->validate( $args ); |
| 442 | - | |
| 443 | 180 | if ( ! empty( $new_errors ) ) { |
| 444 | 181 | $errors = array_merge( $errors, $new_errors ); |
| 445 | 182 | } |
| 446 | 183 | } |
| 447 | 184 | |
| 448 | - /** | |
| 449 | - * @param array $errors | |
| 450 | - * @param object $field | |
| 451 | - * @param string $value | |
| 452 | - * @param array $args | |
| 453 | - * | |
| 454 | - * @return void | |
| 455 | - */ | |
| 456 | 185 | public static function validate_phone_field( &$errors, $field, $value, $args ) { |
| 457 | - $format_value = FrmField::get_option( $field, 'format' ); | |
| 186 | + if ( $field->type == 'phone' || ( $field->type == 'text' && FrmField::is_option_true_in_object( $field, 'format' ) ) ) { | |
| 458 | 187 | |
| 459 | - if ( $field->type === 'phone' || ( $field->type === 'text' && $format_value && ! FrmCurrencyHelper::is_currency_format( $format_value ) ) ) { | |
| 460 | 188 | $pattern = self::phone_format( $field ); |
| 461 | 189 | |
| 462 | 190 | if ( ! preg_match( $pattern, $value ) ) { |
| 463 | 191 | $errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $field, 'invalid' ); |
| @@ -464,13 +192,8 @@ | ||
| 464 | 192 | } |
| 465 | 193 | } |
| 466 | 194 | } |
| 467 | 195 | |
| 468 | - /** | |
| 469 | - * @param object $field | |
| 470 | - * | |
| 471 | - * @return string | |
| 472 | - */ | |
| 473 | 196 | public static function phone_format( $field ) { |
| 474 | 197 | if ( FrmField::is_option_empty( $field, 'format' ) ) { |
| 475 | 198 | $pattern = self::default_phone_format(); |
| 476 | 199 | } else { |
| @@ -476,11 +199,8 @@ | ||
| 476 | 199 | } else { |
| 477 | 200 | $pattern = FrmField::get_option( $field, 'format' ); |
| 478 | 201 | } |
| 479 | 202 | |
| 480 | - // Ampersands are saved as &. | |
| 481 | - // Reverse it here so we are checking for the correct character. | |
| 482 | - $pattern = html_entity_decode( $pattern ); | |
| 483 | 203 | $pattern = apply_filters( 'frm_phone_pattern', $pattern, $field ); |
| 484 | 204 | |
| 485 | 205 | // Create a regexp if format is not already a regexp |
| 486 | 206 | if ( strpos( $pattern, '^' ) !== 0 ) { |
| @@ -493,10 +213,8 @@ | ||
| 493 | 213 | } |
| 494 | 214 | |
| 495 | 215 | /** |
| 496 | 216 | * @since 3.01 |
| 497 | - * | |
| 498 | - * @return string | |
| 499 | 217 | */ |
| 500 | 218 | private static function default_phone_format() { |
| 501 | 219 | return '^((\+\d{1,3}(-|.| )?\(?\d\)?(-| |.)?\d{1,5})|(\(?\d{2,6}\)?))(-|.| )?(\d{3,4})(-|.| )?(\d{4})(( x| ext)\d{1,5}){0,1}$'; |
| 502 | 220 | } |
| @@ -525,9 +243,8 @@ | ||
| 525 | 243 | |
| 526 | 244 | if ( strpos( $pattern, '\?' ) !== false ) { |
| 527 | 245 | $parts = explode( '\?', $pattern ); |
| 528 | 246 | $pattern = ''; |
| 529 | - | |
| 530 | 247 | foreach ( $parts as $part ) { |
| 531 | 248 | if ( empty( $pattern ) ) { |
| 532 | 249 | $pattern .= $part; |
| 533 | 250 | } else { |
| @@ -534,9 +251,8 @@ | ||
| 534 | 251 | $pattern .= '(' . $part . ')?'; |
| 535 | 252 | } |
| 536 | 253 | } |
| 537 | 254 | } |
| 538 | - | |
| 539 | 255 | $pattern = '^' . $pattern . '$'; |
| 540 | 256 | |
| 541 | 257 | return $pattern; |
| 542 | 258 | } |
| @@ -541,40 +257,27 @@ | ||
| 541 | 257 | return $pattern; |
| 542 | 258 | } |
| 543 | 259 | |
| 544 | 260 | /** |
| 545 | - * Check for spam. | |
| 261 | + * Check for spam | |
| 546 | 262 | * |
| 547 | - * @param bool $exclude | |
| 263 | + * @param boolean $exclude | |
| 548 | 264 | * @param array $values |
| 549 | - * @param array $errors By reference. | |
| 550 | - * | |
| 551 | - * @return void | |
| 265 | + * @param array $errors by reference | |
| 552 | 266 | */ |
| 553 | 267 | public static function spam_check( $exclude, $values, &$errors ) { |
| 554 | - if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { | |
| 555 | - // Do not check spam on importing. | |
| 556 | - return; | |
| 557 | - } | |
| 558 | - | |
| 559 | - if ( ! empty( $exclude ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { | |
| 268 | + if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { | |
| 560 | 269 | // only check spam if there are no other errors |
| 561 | 270 | return; |
| 562 | 271 | } |
| 563 | 272 | |
| 564 | 273 | $antispam_check = self::is_antispam_check( $values['form_id'] ); |
| 565 | - $spam_msg = FrmAntiSpamController::get_default_spam_message(); | |
| 566 | - | |
| 567 | 274 | if ( is_string( $antispam_check ) ) { |
| 568 | 275 | $errors['spam'] = $antispam_check; |
| 569 | 276 | } elseif ( self::is_honeypot_spam( $values ) || self::is_spam_bot() ) { |
| 570 | - $errors['spam'] = $spam_msg; | |
| 571 | - } else { | |
| 572 | - $is_spam = FrmAntiSpamController::is_spam( $values ); | |
| 573 | - | |
| 574 | - if ( $is_spam ) { | |
| 575 | - $errors['spam'] = $is_spam; | |
| 576 | - } | |
| 277 | + $errors['spam'] = __( 'Your entry appears to be spam!', 'formidable' ); | |
| 278 | + } elseif ( self::blacklist_check( $values ) ) { | |
| 279 | + $errors['spam'] = __( 'Your entry appears to be blocked spam!', 'formidable' ); | |
| 577 | 280 | } |
| 578 | 281 | |
| 579 | 282 | if ( isset( $errors['spam'] ) || self::form_is_in_progress( $values ) ) { |
| 580 | 283 | return; |
| @@ -590,9 +293,8 @@ | ||
| 590 | 293 | * |
| 591 | 294 | * @since 5.0.13 |
| 592 | 295 | * |
| 593 | 296 | * @param array $values The values. |
| 594 | - * | |
| 595 | 297 | * @return bool |
| 596 | 298 | */ |
| 597 | 299 | private static function form_is_in_progress( $values ) { |
| 598 | 300 | return FrmAppHelper::pro_is_installed() && |
| @@ -601,10 +303,9 @@ | ||
| 601 | 303 | } |
| 602 | 304 | |
| 603 | 305 | /** |
| 604 | 306 | * @param int $form_id |
| 605 | - * | |
| 606 | - * @return bool|string | |
| 307 | + * @return boolean | |
| 607 | 308 | */ |
| 608 | 309 | private static function is_antispam_check( $form_id ) { |
| 609 | 310 | $aspm = new FrmAntiSpam( $form_id ); |
| 610 | 311 | return $aspm->validate(); |
| @@ -611,10 +312,9 @@ | ||
| 611 | 312 | } |
| 612 | 313 | |
| 613 | 314 | /** |
| 614 | 315 | * @param array $values |
| 615 | - * | |
| 616 | - * @return bool | |
| 316 | + * @return boolean | |
| 617 | 317 | */ |
| 618 | 318 | private static function is_honeypot_spam( $values ) { |
| 619 | 319 | $honeypot = new FrmHoneypot( $values['form_id'] ); |
| 620 | 320 | return ! $honeypot->validate(); |
| @@ -620,9 +320,9 @@ | ||
| 620 | 320 | return ! $honeypot->validate(); |
| 621 | 321 | } |
| 622 | 322 | |
| 623 | 323 | /** |
| 624 | - * @return bool | |
| 324 | + * @return boolean | |
| 625 | 325 | */ |
| 626 | 326 | private static function is_spam_bot() { |
| 627 | 327 | $ip = FrmAppHelper::get_ip_address(); |
| 628 | 328 | |
| @@ -630,10 +330,9 @@ | ||
| 630 | 330 | } |
| 631 | 331 | |
| 632 | 332 | /** |
| 633 | 333 | * @param array $values |
| 634 | - * | |
| 635 | - * @return bool | |
| 334 | + * @return boolean | |
| 636 | 335 | */ |
| 637 | 336 | private static function is_akismet_spam( $values ) { |
| 638 | 337 | global $wpcom_api_key; |
| 639 | 338 | |
| @@ -641,9 +340,8 @@ | ||
| 641 | 340 | } |
| 642 | 341 | |
| 643 | 342 | /** |
| 644 | 343 | * @param int $form_id |
| 645 | - * | |
| 646 | 344 | * @return bool |
| 647 | 345 | */ |
| 648 | 346 | private static function is_akismet_enabled_for_user( $form_id ) { |
| 649 | 347 | $form = FrmForm::getOne( $form_id ); |
| @@ -650,25 +348,62 @@ | ||
| 650 | 348 | |
| 651 | 349 | return ( ! empty( $form->options['akismet'] ) && ( $form->options['akismet'] !== 'logged' || ! is_user_logged_in() ) ); |
| 652 | 350 | } |
| 653 | 351 | |
| 352 | + public static function blacklist_check( $values ) { | |
| 353 | + if ( ! apply_filters( 'frm_check_blacklist', true, $values ) ) { | |
| 354 | + return false; | |
| 355 | + } | |
| 356 | + | |
| 357 | + $mod_keys = trim( self::get_disallowed_words() ); | |
| 358 | + if ( empty( $mod_keys ) ) { | |
| 359 | + return false; | |
| 360 | + } | |
| 361 | + | |
| 362 | + $content = FrmEntriesHelper::entry_array_to_string( $values ); | |
| 363 | + if ( empty( $content ) ) { | |
| 364 | + return false; | |
| 365 | + } | |
| 366 | + | |
| 367 | + self::prepare_values_for_spam_check( $values ); | |
| 368 | + $ip = FrmAppHelper::get_ip_address(); | |
| 369 | + $user_agent = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); | |
| 370 | + $user_info = self::get_spam_check_user_info( $values ); | |
| 371 | + | |
| 372 | + return self::check_disallowed_words( $user_info['comment_author'], $user_info['comment_author_email'], $user_info['comment_author_url'], $content, $ip, $user_agent ); | |
| 373 | + } | |
| 374 | + | |
| 654 | 375 | /** |
| 655 | - * Checks spam using WordPress disallowed words and Frm denylist. | |
| 376 | + * For WP 5.5 compatibility. | |
| 656 | 377 | * |
| 657 | - * @param array $values Entry values. | |
| 378 | + * @since 4.06.02 | |
| 379 | + */ | |
| 380 | + private static function check_disallowed_words( $author, $email, $url, $content, $ip, $user_agent ) { | |
| 381 | + if ( function_exists( 'wp_check_comment_disallowed_list' ) ) { | |
| 382 | + return wp_check_comment_disallowed_list( $author, $email, $url, $content, $ip, $user_agent ); | |
| 383 | + } else { | |
| 384 | + return wp_blacklist_check( $author, $email, $url, $content, $ip, $user_agent ); | |
| 385 | + } | |
| 386 | + } | |
| 387 | + | |
| 388 | + /** | |
| 389 | + * For WP 5.5 compatibility. | |
| 658 | 390 | * |
| 659 | - * @return bool | |
| 391 | + * @since 4.06.02 | |
| 660 | 392 | */ |
| 661 | - public static function blacklist_check( $values ) { | |
| 662 | - return FrmAntiSpamController::contains_wp_disallowed_words( $values ) || FrmAntiSpamController::is_denylist_spam( $values ); | |
| 393 | + private static function get_disallowed_words() { | |
| 394 | + $keys = get_option( 'disallowed_keys' ); | |
| 395 | + if ( false === $keys ) { | |
| 396 | + // Fallback for WP < 5.5. | |
| 397 | + $keys = get_option( 'blacklist_keys' ); | |
| 398 | + } | |
| 399 | + return $keys; | |
| 663 | 400 | } |
| 664 | 401 | |
| 665 | 402 | /** |
| 666 | 403 | * Check entries for Akismet spam |
| 667 | 404 | * |
| 668 | - * @param array $values Entry values. | |
| 669 | - * | |
| 670 | - * @return bool true if is spam | |
| 405 | + * @return boolean true if is spam | |
| 671 | 406 | */ |
| 672 | 407 | public static function akismet( $values ) { |
| 673 | 408 | if ( empty( $values['item_meta'] ) ) { |
| 674 | 409 | return false; |
| @@ -690,18 +425,13 @@ | ||
| 690 | 425 | |
| 691 | 426 | $query_string = _http_build_query( $datas, '', '&' ); |
| 692 | 427 | $response = Akismet::http_post( $query_string, 'comment-check' ); |
| 693 | 428 | |
| 694 | - return ( is_array( $response ) && $response[1] === 'true' ); | |
| 429 | + return ( is_array( $response ) && $response[1] == 'true' ); | |
| 695 | 430 | } |
| 696 | 431 | |
| 697 | 432 | /** |
| 698 | 433 | * @since 2.0 |
| 699 | - * | |
| 700 | - * @param array $datas The array of values being sent to Akismet. | |
| 701 | - * @param array $values Entry values. | |
| 702 | - * | |
| 703 | - * @return void | |
| 704 | 434 | */ |
| 705 | 435 | private static function parse_akismet_array( &$datas, $values ) { |
| 706 | 436 | self::add_site_info_to_akismet( $datas ); |
| 707 | 437 | self::add_server_values_to_akismet( $datas ); |
| @@ -706,19 +436,13 @@ | ||
| 706 | 436 | self::add_site_info_to_akismet( $datas ); |
| 707 | 437 | self::add_server_values_to_akismet( $datas ); |
| 708 | 438 | |
| 709 | 439 | self::prepare_values_for_spam_check( $values ); |
| 710 | - self::skip_adding_values_to_akismet( $values ); | |
| 711 | 440 | |
| 712 | 441 | self::add_user_info_to_akismet( $datas, $values ); |
| 713 | 442 | self::add_comment_content_to_akismet( $datas, $values ); |
| 714 | 443 | } |
| 715 | 444 | |
| 716 | - /** | |
| 717 | - * @param array $datas | |
| 718 | - * | |
| 719 | - * @return void | |
| 720 | - */ | |
| 721 | 445 | private static function add_site_info_to_akismet( &$datas ) { |
| 722 | 446 | $datas['blog'] = FrmAppHelper::site_url(); |
| 723 | 447 | $datas['user_ip'] = preg_replace( '/[^0-9., ]/', '', FrmAppHelper::get_ip_address() ); |
| 724 | 448 | $datas['user_agent'] = FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ); |
| @@ -730,14 +454,8 @@ | ||
| 730 | 454 | $datas['is_test'] = 'true'; |
| 731 | 455 | } |
| 732 | 456 | } |
| 733 | 457 | |
| 734 | - /** | |
| 735 | - * @param array $datas | |
| 736 | - * @param array $values | |
| 737 | - * | |
| 738 | - * @return void | |
| 739 | - */ | |
| 740 | 458 | private static function add_user_info_to_akismet( &$datas, $values ) { |
| 741 | 459 | $user_info = self::get_spam_check_user_info( $values ); |
| 742 | 460 | $datas = $datas + $user_info; |
| 743 | 461 | |
| @@ -749,15 +467,13 @@ | ||
| 749 | 467 | /** |
| 750 | 468 | * Gets user info for Akismet spam check. |
| 751 | 469 | * |
| 752 | 470 | * @since 5.0.13 Separate code for guest. Handle value of embedded|repeater. |
| 753 | - * @since 6.21 This changed from private to public. | |
| 754 | 471 | * |
| 755 | 472 | * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}. |
| 756 | - * | |
| 757 | 473 | * @return array |
| 758 | 474 | */ |
| 759 | - public static function get_spam_check_user_info( $values ) { | |
| 475 | + private static function get_spam_check_user_info( $values ) { | |
| 760 | 476 | if ( ! is_user_logged_in() ) { |
| 761 | 477 | return self::get_spam_check_user_info_for_guest( $values ); |
| 762 | 478 | } |
| 763 | 479 | |
| @@ -777,9 +493,8 @@ | ||
| 777 | 493 | * |
| 778 | 494 | * @since 5.0.13 |
| 779 | 495 | * |
| 780 | 496 | * @param array $values Entry values after flattened. |
| 781 | - * | |
| 782 | 497 | * @return array |
| 783 | 498 | */ |
| 784 | 499 | private static function get_spam_check_user_info_for_guest( $values ) { |
| 785 | 500 | $datas = array( |
| @@ -811,16 +526,13 @@ | ||
| 811 | 526 | * |
| 812 | 527 | * @param array $datas Guest data. |
| 813 | 528 | * @param array $values The values. |
| 814 | 529 | * @param int|null $custom_index Custom index (or field ID). |
| 815 | - * | |
| 816 | - * @return void | |
| 817 | 530 | */ |
| 818 | 531 | private static function recursive_add_akismet_guest_info( &$datas, $values, $custom_index = null ) { |
| 819 | 532 | foreach ( $values as $index => $value ) { |
| 820 | 533 | if ( ! $datas['missing_keys'] ) { |
| 821 | - // Found all info. | |
| 822 | - return; | |
| 534 | + return; // Found all info. | |
| 823 | 535 | } |
| 824 | 536 | |
| 825 | 537 | if ( is_array( $value ) ) { |
| 826 | 538 | self::recursive_add_akismet_guest_info( $datas, $value, $index ); |
| @@ -827,12 +539,10 @@ | ||
| 827 | 539 | continue; |
| 828 | 540 | } |
| 829 | 541 | |
| 830 | 542 | $field_id = ! is_null( $custom_index ) ? $custom_index : $index; |
| 831 | - | |
| 832 | 543 | foreach ( $datas['missing_keys'] as $key_index => $key ) { |
| 833 | - $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'], $values ); | |
| 834 | - | |
| 544 | + $found = self::is_akismet_guest_info_value( $key, $value, $field_id, $datas['name_field_ids'] ); | |
| 835 | 545 | if ( $found ) { |
| 836 | 546 | $datas[ $key ] = $value; |
| 837 | 547 | $datas['frm_duplicated'][] = $field_id; |
| 838 | 548 | unset( $datas['missing_keys'][ $key_index ] ); |
| @@ -837,9 +547,9 @@ | ||
| 837 | 547 | $datas['frm_duplicated'][] = $field_id; |
| 838 | 548 | unset( $datas['missing_keys'][ $key_index ] ); |
| 839 | 549 | } |
| 840 | 550 | } |
| 841 | - }//end foreach | |
| 551 | + } | |
| 842 | 552 | } |
| 843 | 553 | |
| 844 | 554 | /** |
| 845 | 555 | * Checks if given value is an akismet guest info. |
| @@ -849,13 +559,11 @@ | ||
| 849 | 559 | * @param string $key Guest info key. |
| 850 | 560 | * @param string $value Value to check. |
| 851 | 561 | * @param int $field_id Field ID. |
| 852 | 562 | * @param array $name_field_ids Name field IDs. |
| 853 | - * @param array $values Array of posted values. | |
| 854 | - * | |
| 855 | 563 | * @return bool |
| 856 | 564 | */ |
| 857 | - private static function is_akismet_guest_info_value( $key, &$value, $field_id, $name_field_ids, $values ) { | |
| 565 | + private static function is_akismet_guest_info_value( $key, $value, $field_id, $name_field_ids ) { | |
| 858 | 566 | if ( ! $value || is_numeric( $value ) ) { |
| 859 | 567 | return false; |
| 860 | 568 | } |
| 861 | 569 | |
| @@ -866,73 +574,18 @@ | ||
| 866 | 574 | case 'comment_author_url': |
| 867 | 575 | return 0 === strpos( $value, 'http' ); |
| 868 | 576 | |
| 869 | 577 | case 'comment_author': |
| 870 | - if ( $name_field_ids && in_array( $field_id, $name_field_ids, true ) ) { | |
| 578 | + if ( $name_field_ids ) { | |
| 871 | 579 | // If there is name field in the form, we should always use it as author name. |
| 872 | - return true; | |
| 580 | + return in_array( $field_id, $name_field_ids, true ); | |
| 873 | 581 | } |
| 582 | + return strlen( $value ) < 200; | |
| 583 | + } | |
| 874 | 584 | |
| 875 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 876 | - $fields = self::get_name_text_fields( $form_id ); | |
| 877 | - | |
| 878 | - foreach ( $fields as $index => $field ) { | |
| 879 | - if ( 'Name' !== $field->name ) { | |
| 880 | - continue; | |
| 881 | - } | |
| 882 | - | |
| 883 | - if ( isset( $fields[ $index + 1 ] ) && 'Last' === $fields[ $index + 1 ]->name ) { | |
| 884 | - if ( empty( $values[ absint( $fields[ $index + 1 ]->id ) ] ) ) { | |
| 885 | - continue; | |
| 886 | - } | |
| 887 | - | |
| 888 | - $value .= ' ' . $values[ $fields[ $index + 1 ]->id ]; | |
| 889 | - return true; | |
| 890 | - } | |
| 891 | - } | |
| 892 | - }//end switch | |
| 893 | - | |
| 894 | 585 | return false; |
| 895 | 586 | } |
| 896 | 587 | |
| 897 | - /** | |
| 898 | - * Returns fields that have 'Name' and 'Last' as their name. | |
| 899 | - * | |
| 900 | - * @since 6.17 | |
| 901 | - * | |
| 902 | - * @param int $form_id | |
| 903 | - * | |
| 904 | - * @return array | |
| 905 | - */ | |
| 906 | - private static function get_name_text_fields( $form_id ) { | |
| 907 | - $name_text_fields_is_initialized = is_array( self::$name_text_fields ); | |
| 908 | - | |
| 909 | - if ( $name_text_fields_is_initialized && isset( self::$name_text_fields[ $form_id ] ) ) { | |
| 910 | - return self::$name_text_fields[ $form_id ]; | |
| 911 | - } | |
| 912 | - | |
| 913 | - if ( ! $name_text_fields_is_initialized ) { | |
| 914 | - self::$name_text_fields = array(); | |
| 915 | - } | |
| 916 | - self::$name_text_fields[ $form_id ] = FrmDb::get_results( | |
| 917 | - 'frm_fields', | |
| 918 | - array( | |
| 919 | - 'form_id' => $form_id, | |
| 920 | - 'type' => 'text', | |
| 921 | - 'name' => array( 'Name', 'Last' ), | |
| 922 | - ), | |
| 923 | - 'id,name', | |
| 924 | - array( 'order_by' => 'field_order ASC' ) | |
| 925 | - ); | |
| 926 | - | |
| 927 | - return self::$name_text_fields[ $form_id ]; | |
| 928 | - } | |
| 929 | - | |
| 930 | - /** | |
| 931 | - * @param array $datas | |
| 932 | - * | |
| 933 | - * @return void | |
| 934 | - */ | |
| 935 | 588 | private static function add_server_values_to_akismet( &$datas ) { |
| 936 | 589 | foreach ( $_SERVER as $key => $value ) { |
| 937 | 590 | $include_value = is_string( $value ) && ! preg_match( '/^HTTP_COOKIE/', $key ) && preg_match( '/^(HTTP_|REMOTE_ADDR|REQUEST_URI|DOCUMENT_URI)/', $key ); |
| 938 | 591 | |
| @@ -950,10 +603,8 @@ | ||
| 950 | 603 | * @since 5.0.09 |
| 951 | 604 | * |
| 952 | 605 | * @param array $datas The array of values being sent to Akismet. |
| 953 | 606 | * @param array $values Entry values. |
| 954 | - * | |
| 955 | - * @return void | |
| 956 | 607 | */ |
| 957 | 608 | private static function add_comment_content_to_akismet( &$datas, $values ) { |
| 958 | 609 | if ( isset( $datas['frm_duplicated'] ) ) { |
| 959 | 610 | foreach ( $datas['frm_duplicated'] as $index ) { |
| @@ -965,8 +616,10 @@ | ||
| 965 | 616 | } |
| 966 | 617 | unset( $datas['frm_duplicated'] ); |
| 967 | 618 | } |
| 968 | 619 | |
| 620 | + self::skip_adding_values_to_akismet( $values ); | |
| 621 | + | |
| 969 | 622 | $datas['comment_content'] = FrmEntriesHelper::entry_array_to_string( $values ); |
| 970 | 623 | } |
| 971 | 624 | |
| 972 | 625 | /** |
| @@ -974,14 +627,11 @@ | ||
| 974 | 627 | * |
| 975 | 628 | * @since 5.0.09 |
| 976 | 629 | * |
| 977 | 630 | * @param array $values Entry values. |
| 978 | - * | |
| 979 | - * @return void | |
| 980 | 631 | */ |
| 981 | 632 | private static function skip_adding_values_to_akismet( &$values ) { |
| 982 | 633 | $skipped_fields = self::get_akismet_skipped_field_ids( $values ); |
| 983 | - | |
| 984 | 634 | foreach ( $skipped_fields as $skipped_field ) { |
| 985 | 635 | if ( ! isset( $values['item_meta'][ $skipped_field->id ] ) ) { |
| 986 | 636 | continue; |
| 987 | 637 | } |
| @@ -987,9 +637,8 @@ | ||
| 987 | 637 | } |
| 988 | 638 | |
| 989 | 639 | if ( self::should_really_skip_field( $skipped_field, $values ) ) { |
| 990 | 640 | unset( $values['item_meta'][ $skipped_field->id ] ); |
| 991 | - | |
| 992 | 641 | if ( isset( $values['item_meta']['other'][ $skipped_field->id ] ) ) { |
| 993 | 642 | unset( $values['item_meta']['other'][ $skipped_field->id ] ); |
| 994 | 643 | } |
| 995 | 644 | } |
| @@ -1002,21 +651,17 @@ | ||
| 1002 | 651 | * @since 5.02.04 |
| 1003 | 652 | * |
| 1004 | 653 | * @param object $field_data Object contains `id` and `options`. |
| 1005 | 654 | * @param array $values Entry values. |
| 1006 | - * | |
| 1007 | 655 | * @return bool |
| 1008 | 656 | */ |
| 1009 | 657 | private static function should_really_skip_field( $field_data, $values ) { |
| 1010 | - if ( empty( $field_data->options ) ) { | |
| 1011 | - // This is skipped field types. | |
| 658 | + if ( empty( $field_data->options ) ) { // This is skipped field types. | |
| 1012 | 659 | return true; |
| 1013 | 660 | } |
| 1014 | 661 | |
| 1015 | 662 | FrmAppHelper::unserialize_or_decode( $field_data->options ); |
| 1016 | - | |
| 1017 | - if ( ! $field_data->options ) { | |
| 1018 | - // Check if an error happens when unserializing, or empty options. | |
| 663 | + if ( ! $field_data->options ) { // Check if an error happens when unserializing, or empty options. | |
| 1019 | 664 | return true; |
| 1020 | 665 | } |
| 1021 | 666 | |
| 1022 | 667 | end( $field_data->options ); |
| @@ -1033,10 +678,9 @@ | ||
| 1033 | 678 | } |
| 1034 | 679 | |
| 1035 | 680 | // Check if submitted value is same as one of field option. |
| 1036 | 681 | foreach ( $field_data->options as $option ) { |
| 1037 | - $option_value = ! is_array( $option ) ? $option : ( $option['value'] ?? '' ); | |
| 1038 | - | |
| 682 | + $option_value = ! is_array( $option ) ? $option : ( isset( $option['value'] ) ? $option['value'] : '' ); | |
| 1039 | 683 | if ( $values['item_meta']['other'][ $field_data->id ] === $option_value ) { |
| 1040 | 684 | return true; |
| 1041 | 685 | } |
| 1042 | 686 | } |
| @@ -1051,9 +695,8 @@ | ||
| 1051 | 695 | * @since 5.0.13 Move out get_all_form_ids_and_flatten_meta() call and get `form_ids` from `$values`. |
| 1052 | 696 | * @since 5.2.04 This method returns array of object contains `id` and `options` instead of array of `id` only. |
| 1053 | 697 | * |
| 1054 | 698 | * @param array $values Entry values after running through {@see FrmEntryValidate::prepare_values_for_spam_check()}. |
| 1055 | - * | |
| 1056 | 699 | * @return array |
| 1057 | 700 | */ |
| 1058 | 701 | private static function get_akismet_skipped_field_ids( $values ) { |
| 1059 | 702 | if ( empty( $values['form_ids'] ) ) { |
| @@ -1076,15 +719,12 @@ | ||
| 1076 | 719 | /** |
| 1077 | 720 | * Prepares values array for spam check. |
| 1078 | 721 | * |
| 1079 | 722 | * @since 5.0.13 |
| 1080 | - * @since 6.21 This changed from private to public. | |
| 1081 | 723 | * |
| 1082 | 724 | * @param array $values Entry values. |
| 1083 | - * | |
| 1084 | - * @return void | |
| 1085 | 725 | */ |
| 1086 | - public static function prepare_values_for_spam_check( &$values ) { | |
| 726 | + private static function prepare_values_for_spam_check( &$values ) { | |
| 1087 | 727 | $form_ids = self::get_all_form_ids_and_flatten_meta( $values ); |
| 1088 | 728 | $values['form_ids'] = $form_ids; |
| 1089 | 729 | } |
| 1090 | 730 | |
| @@ -1095,9 +735,8 @@ | ||
| 1095 | 735 | * @since 5.0.09 |
| 1096 | 736 | * @since 5.0.13 Convert name field value to string. |
| 1097 | 737 | * |
| 1098 | 738 | * @param array $values Entry values. |
| 1099 | - * | |
| 1100 | 739 | * @return array Form IDs. |
| 1101 | 740 | */ |
| 1102 | 741 | private static function get_all_form_ids_and_flatten_meta( &$values ) { |
| 1103 | 742 | $values['name_field_ids'] = array(); |
| @@ -1103,12 +742,10 @@ | ||
| 1103 | 742 | $values['name_field_ids'] = array(); |
| 1104 | 743 | |
| 1105 | 744 | // Blacklist check for File field in the old version doesn't contain `form_id`. |
| 1106 | 745 | $form_ids = isset( $values['form_id'] ) ? array( absint( $values['form_id'] ) ) : array(); |
| 1107 | - | |
| 1108 | 746 | foreach ( $values['item_meta'] as $field_id => $value ) { |
| 1109 | - if ( ! is_numeric( $field_id ) ) { | |
| 1110 | - // Maybe `other`. | |
| 747 | + if ( ! is_numeric( $field_id ) ) { // Maybe `other`. | |
| 1111 | 748 | continue; |
| 1112 | 749 | } |
| 1113 | 750 | |
| 1114 | 751 | // Convert name array to string. |
| @@ -1144,16 +781,46 @@ | ||
| 1144 | 781 | |
| 1145 | 782 | $values['name_field_ids'][] = $subsubindex; |
| 1146 | 783 | } |
| 1147 | 784 | |
| 1148 | - if ( is_array( $values['item_meta'][ $subsubindex ] ) ) { | |
| 1149 | - $values['item_meta'][ $subsubindex ][] = $subsubvalue; | |
| 1150 | - } | |
| 785 | + $values['item_meta'][ $subsubindex ][] = $subsubvalue; | |
| 1151 | 786 | } |
| 1152 | - }//end foreach | |
| 787 | + } | |
| 1153 | 788 | |
| 1154 | 789 | unset( $values['item_meta'][ $field_id ] ); |
| 1155 | - }//end foreach | |
| 790 | + } | |
| 1156 | 791 | |
| 1157 | 792 | return $form_ids; |
| 793 | + } | |
| 794 | + | |
| 795 | + /** | |
| 796 | + * @deprecated 3.0 | |
| 797 | + * @codeCoverageIgnore | |
| 798 | + */ | |
| 799 | + public static function validate_url_field( &$errors, $field, $value, $args ) { | |
| 800 | + FrmDeprecated::validate_url_field( $errors, $field, $value, $args ); | |
| 801 | + } | |
| 802 | + | |
| 803 | + /** | |
| 804 | + * @deprecated 3.0 | |
| 805 | + * @codeCoverageIgnore | |
| 806 | + */ | |
| 807 | + public static function validate_email_field( &$errors, $field, $value, $args ) { | |
| 808 | + FrmDeprecated::validate_email_field( $errors, $field, $value, $args ); | |
| 809 | + } | |
| 810 | + | |
| 811 | + /** | |
| 812 | + * @deprecated 3.0 | |
| 813 | + * @codeCoverageIgnore | |
| 814 | + */ | |
| 815 | + public static function validate_number_field( &$errors, $field, $value, $args ) { | |
| 816 | + FrmDeprecated::validate_number_field( $errors, $field, $value, $args ); | |
| 817 | + } | |
| 818 | + | |
| 819 | + /** | |
| 820 | + * @deprecated 3.0 | |
| 821 | + * @codeCoverageIgnore | |
| 822 | + */ | |
| 823 | + public static function validate_recaptcha( &$errors, $field, $args ) { | |
| 824 | + FrmDeprecated::validate_recaptcha( $errors, $field, $args ); | |
| 1158 | 825 | } |
| 1159 | 826 | } |