PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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/FrmEntry.php +4 -114 6.256.16 View file →
@@ -5,15 +5,8 @@
5 5
6 6 class FrmEntry {
7 7
8 8 /**
9 - * @since 6.16.3
10 - *
11 - * @var array
12 - */
13 - private static $unique_id_match_checks = array();
14 -
15 - /**
16 9 * Create a new entry
17 10 *
18 11 * @param array $values
19 12 *
@@ -46,23 +39,8 @@
46 39 return $entry_id;
47 40 }
48 41
49 42 /**
50 - * Flag the memoized unique id check after a new entry is created.
51 - * This prevents possibly DB requests and helps avoid issues when creating repeater entries.
52 - *
53 - * @since 6.16.3
54 - *
55 - * @param string $unique_id
56 - * @return void
57 - */
58 - private static function flag_new_unique_key( $unique_id ) {
59 - if ( ! isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
60 - self::$unique_id_match_checks[ $unique_id ] = false;
61 - }
62 - }
63 -
64 - /**
65 43 * Check for duplicate entries created in the last minute
66 44 *
67 45 * @return bool
68 46 */
@@ -72,12 +50,8 @@
72 50 if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) {
73 51 return false;
74 52 }
75 53
76 - if ( self::maybe_check_for_unique_id_match( $values, $new_values['created_at'] ) ) {
77 - return true;
78 - }
79 -
80 54 $check_val = $new_values;
81 55 $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) );
82 56
83 57 unset( $check_val['created_at'], $check_val['updated_at'], $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
@@ -105,11 +79,8 @@
105 79 // make sure it's a duplicate
106 80 $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
107 81 $field_metas = array();
108 82 foreach ( $metas as $meta ) {
109 - if ( 0 === (int) $meta->field_id ) {
110 - continue;
111 - }
112 83 $field_metas[ $meta->field_id ] = $meta->meta_value;
113 84 }
114 85
115 86 $filtered_vals = array_filter( $values['item_meta'] );
@@ -152,67 +123,8 @@
152 123 return $is_duplicate;
153 124 }
154 125
155 126 /**
156 - * @since 6.16.3
157 - *
158 - * @param array $values POST request data.
159 - * @param string $created_at The timestamp of the entry we are checking for.
160 - * @return bool
161 - */
162 - private static function maybe_check_for_unique_id_match( $values, $created_at ) {
163 - if ( ! self::should_check_for_unique_id_match() ) {
164 - return false;
165 - }
166 -
167 - if ( empty( $values['unique_id'] ) ) {
168 - return false;
169 - }
170 -
171 - $unique_id = sanitize_key( $values['unique_id'] );
172 - if ( ! $unique_id ) {
173 - // Only continue if a unique ID was generated on form submit.
174 - return false;
175 - }
176 -
177 - if ( isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
178 - return self::$unique_id_match_checks[ $unique_id ];
179 - }
180 -
181 - $timestamp = strtotime( $created_at );
182 - if ( false === $timestamp ) {
183 - $timestamp = time();
184 - }
185 -
186 - self::$unique_id_match_checks[ $unique_id ] = (bool) FrmDb::get_var(
187 - 'frm_item_metas',
188 - array(
189 - 'field_id' => 0,
190 - 'meta_value' => serialize( compact( 'unique_id' ) ),
191 - 'created_at >' => gmdate( 'Y-m-d H:i:s', $timestamp - MONTH_IN_SECONDS ),
192 - ),
193 - 'id'
194 - );
195 -
196 - return self::$unique_id_match_checks[ $unique_id ];
197 - }
198 -
199 - /**
200 - * @since 6.16.3
201 - */
202 - private static function should_check_for_unique_id_match() {
203 - /**
204 - * Allow users to opt out of the DB query, in case it causes performance issues.
205 - *
206 - * @since 6.16.3
207 - *
208 - * @param bool $should_extend
209 - */
210 - $should_check = apply_filters( 'frm_check_for_unique_id_match', true );
211 - return (bool) $should_check;
212 - }
213 -
214 - /**
215 127 * Convert form data to the actual value that would be saved into the database.
216 128 * This is important for the duplicate check as something like 'a:2:{s:5:"typed";s:0:"";s:6:"output";s:0:"";}' (a signature value) is actually an empty string and does not get saved.
217 129 *
218 130 * @param array $filter_vals
@@ -412,9 +324,9 @@
412 324 *
413 325 * @since 2.0.11
414 326 */
415 327 public static function get_new_entry_name( $values, $default = '' ) {
416 - $name = $values['item_name'] ?? $values['name'] ?? $default;
328 + $name = isset( $values['item_name'] ) ? $values['item_name'] : ( isset( $values['name'] ) ? $values['name'] : $default );
417 329 if ( is_array( $name ) ) {
418 330 $name = reset( $name );
419 331 }
420 332
@@ -807,15 +719,15 @@
807 719 'description' => self::get_entry_description( $values ),
808 720 'user_id' => self::get_entry_user_id( $values ),
809 721 );
810 722
811 - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id'];
723 + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
812 724
813 725 return $new_values;
814 726 }
815 727
816 728 private static function get_entry_value( $values, $name, $default ) {
817 - return $values[ $name ] ?? $default;
729 + return isset( $values[ $name ] ) ? $values[ $name ] : $default;
818 730 }
819 731
820 732 /**
821 733 * Get the ip for a new entry.
@@ -984,35 +896,13 @@
984 896 */
985 897 private static function maybe_add_entry_metas( $values, $entry_id ) {
986 898 if ( isset( $values['item_meta'] ) ) {
987 899 FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
988 - self::maybe_add_unique_id_meta( $values, $entry_id );
989 900 }
990 901 self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id );
991 902 }
992 903
993 904 /**
994 - * @since 6.16.3
995 - *
996 - * @param array $values
997 - * @param int $entry_id
998 - * @return void
999 - */
1000 - private static function maybe_add_unique_id_meta( $values, $entry_id ) {
1001 - if ( ! empty( $values['parent_form_id'] ) || empty( $values['unique_id'] ) || ! self::should_check_for_unique_id_match() ) {
1002 - return;
1003 - }
1004 -
1005 - // This unique ID is inserted with JS on form submit.
1006 - // It is used to check for duplicate entries.
1007 - $unique_id = sanitize_key( $values['unique_id'] );
1008 - if ( $unique_id ) {
1009 - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) );
1010 - self::flag_new_unique_key( $unique_id );
1011 - }
1012 - }
1013 -
1014 - /**
1015 905 * @since 5.0.15
1016 906 *
1017 907 * @param int $form_id
1018 908 * @param int $entry_id
@@ -1107,9 +997,9 @@
1107 997 'name' => self::get_new_entry_name( $values ),
1108 998 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
1109 999 'is_draft' => self::get_is_draft_value( $values ),
1110 1000 'updated_at' => current_time( 'mysql', 1 ),
1111 - 'updated_by' => $values['updated_by'] ?? get_current_user_id(),
1001 + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
1112 1002 );
1113 1003
1114 1004 if ( isset( $values['post_id'] ) ) {
1115 1005 $new_values['post_id'] = (int) $values['post_id'];