| @@ -24,8 +24,9 @@ | ||
| 24 | 24 | $frm_settings = FrmAppHelper::get_settings(); |
| 25 | 25 | $errors['form'] = $frm_settings->admin_permission; |
| 26 | 26 | } |
| 27 | 27 | |
| 28 | + self::maybe_fix_item_meta(); | |
| 28 | 29 | self::set_item_key( $values ); |
| 29 | 30 | |
| 30 | 31 | $posted_fields = self::get_fields_to_validate( $values, $exclude ); |
| 31 | 32 | |
| @@ -60,8 +61,23 @@ | ||
| 60 | 61 | |
| 61 | 62 | return $errors; |
| 62 | 63 | } |
| 63 | 64 | |
| 65 | + /** | |
| 66 | + * In case $_POST['item_meta'] is not an array, change it to an empty array. | |
| 67 | + * This helps to avoid some warnings and errors when $_POST['item_meta'] is updated. | |
| 68 | + * | |
| 69 | + * @since 6.6 | |
| 70 | + * | |
| 71 | + * @return void | |
| 72 | + */ | |
| 73 | + private static function maybe_fix_item_meta() { | |
| 74 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 75 | + if ( ! isset( $_POST['item_meta'] ) || ! is_array( $_POST['item_meta'] ) ) { | |
| 76 | + $_POST['item_meta'] = array(); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 64 | 80 | private static function set_item_key( &$values ) { |
| 65 | 81 | if ( ! isset( $values['item_key'] ) || $values['item_key'] == '' ) { |
| 66 | 82 | global $wpdb; |
| 67 | 83 | $values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' ); |
| @@ -95,11 +111,15 @@ | ||
| 95 | 111 | |
| 96 | 112 | public static function validate_field( $posted_field, &$errors, $values, $args = array() ) { |
| 97 | 113 | $defaults = array( |
| 98 | 114 | 'id' => $posted_field->id, |
| 99 | - 'parent_field_id' => '', // the id of the repeat or embed form | |
| 100 | - 'key_pointer' => '', // the pointer in the posted array | |
| 101 | - 'exclude' => array(), // exclude these field types from validation | |
| 115 | + // The id of the repeat or embed form. | |
| 116 | + 'parent_field_id' => '', | |
| 117 | + // The pointer in the posted array. | |
| 118 | + 'key_pointer' => '', | |
| 119 | + // Exclude these field types from validation. | |
| 120 | + 'exclude' => array(), | |
| 121 | + | |
| 102 | 122 | ); |
| 103 | 123 | $args = wp_parse_args( $args, $defaults ); |
| 104 | 124 | |
| 105 | 125 | if ( empty( $args['parent_field_id'] ) ) { |
| @@ -142,8 +162,12 @@ | ||
| 142 | 162 | } |
| 143 | 163 | |
| 144 | 164 | $errors = apply_filters( 'frm_validate_' . $posted_field->type . '_field_entry', $errors, $posted_field, $value, $args ); |
| 145 | 165 | $errors = apply_filters( 'frm_validate_field_entry', $errors, $posted_field, $value, $args ); |
| 166 | + | |
| 167 | + if ( ! FrmAppHelper::pro_is_installed() && empty( $args['other'] ) ) { | |
| 168 | + FrmEntriesHelper::get_posted_value( $posted_field, $value, $args ); | |
| 169 | + } | |
| 146 | 170 | } |
| 147 | 171 | |
| 148 | 172 | /** |
| 149 | 173 | * Maybe add item_name to $_POST to save it in items table. |
| @@ -149,9 +173,10 @@ | ||
| 149 | 173 | * Maybe add item_name to $_POST to save it in items table. |
| 150 | 174 | * |
| 151 | 175 | * @since 5.2.02 |
| 152 | 176 | * |
| 153 | - * @param object $field Field object. | |
| 177 | + * @param string|array $value Field value. | |
| 178 | + * @param object $field Field object. | |
| 154 | 179 | */ |
| 155 | 180 | private static function maybe_add_item_name( $value, $field ) { |
| 156 | 181 | $item_name = false; |
| 157 | 182 | if ( 'name' === $field->type ) { |
| @@ -273,10 +298,10 @@ | ||
| 273 | 298 | /** |
| 274 | 299 | * Check for spam |
| 275 | 300 | * |
| 276 | 301 | * @param boolean $exclude |
| 277 | - * @param array $values | |
| 278 | - * @param array $errors by reference | |
| 302 | + * @param array $values | |
| 303 | + * @param array $errors By reference. | |
| 279 | 304 | */ |
| 280 | 305 | public static function spam_check( $exclude, $values, &$errors ) { |
| 281 | 306 | if ( ! empty( $exclude ) || ! isset( $values['item_meta'] ) || empty( $values['item_meta'] ) || ! empty( $errors ) ) { |
| 282 | 307 | // only check spam if there are no other errors |
| @@ -541,9 +566,10 @@ | ||
| 541 | 566 | */ |
| 542 | 567 | private static function recursive_add_akismet_guest_info( &$datas, $values, $custom_index = null ) { |
| 543 | 568 | foreach ( $values as $index => $value ) { |
| 544 | 569 | if ( ! $datas['missing_keys'] ) { |
| 545 | - return; // Found all info. | |
| 570 | + // Found all info. | |
| 571 | + return; | |
| 546 | 572 | } |
| 547 | 573 | |
| 548 | 574 | if ( is_array( $value ) ) { |
| 549 | 575 | self::recursive_add_akismet_guest_info( $datas, $value, $index ); |
| @@ -558,9 +584,9 @@ | ||
| 558 | 584 | $datas['frm_duplicated'][] = $field_id; |
| 559 | 585 | unset( $datas['missing_keys'][ $key_index ] ); |
| 560 | 586 | } |
| 561 | 587 | } |
| 562 | - } | |
| 588 | + }//end foreach | |
| 563 | 589 | } |
| 564 | 590 | |
| 565 | 591 | /** |
| 566 | 592 | * Checks if given value is an akismet guest info. |
| @@ -665,14 +691,16 @@ | ||
| 665 | 691 | * @param array $values Entry values. |
| 666 | 692 | * @return bool |
| 667 | 693 | */ |
| 668 | 694 | private static function should_really_skip_field( $field_data, $values ) { |
| 669 | - if ( empty( $field_data->options ) ) { // This is skipped field types. | |
| 695 | + if ( empty( $field_data->options ) ) { | |
| 696 | + // This is skipped field types. | |
| 670 | 697 | return true; |
| 671 | 698 | } |
| 672 | 699 | |
| 673 | 700 | FrmAppHelper::unserialize_or_decode( $field_data->options ); |
| 674 | - if ( ! $field_data->options ) { // Check if an error happens when unserializing, or empty options. | |
| 701 | + if ( ! $field_data->options ) { | |
| 702 | + // Check if an error happens when unserializing, or empty options. | |
| 675 | 703 | return true; |
| 676 | 704 | } |
| 677 | 705 | |
| 678 | 706 | end( $field_data->options ); |
| @@ -754,9 +782,10 @@ | ||
| 754 | 782 | |
| 755 | 783 | // Blacklist check for File field in the old version doesn't contain `form_id`. |
| 756 | 784 | $form_ids = isset( $values['form_id'] ) ? array( absint( $values['form_id'] ) ) : array(); |
| 757 | 785 | foreach ( $values['item_meta'] as $field_id => $value ) { |
| 758 | - if ( ! is_numeric( $field_id ) ) { // Maybe `other`. | |
| 786 | + if ( ! is_numeric( $field_id ) ) { | |
| 787 | + // Maybe `other`. | |
| 759 | 788 | continue; |
| 760 | 789 | } |
| 761 | 790 | |
| 762 | 791 | // Convert name array to string. |
| @@ -794,12 +823,12 @@ | ||
| 794 | 823 | } |
| 795 | 824 | |
| 796 | 825 | $values['item_meta'][ $subsubindex ][] = $subsubvalue; |
| 797 | 826 | } |
| 798 | - } | |
| 827 | + }//end foreach | |
| 799 | 828 | |
| 800 | 829 | unset( $values['item_meta'][ $field_id ] ); |
| 801 | - } | |
| 830 | + }//end foreach | |
| 802 | 831 | |
| 803 | 832 | return $form_ids; |
| 804 | 833 | } |
| 805 | 834 | |