PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.08
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 +186 -493 6.324.08 View file →
@@ -5,67 +5,45 @@
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 *
20 - * @return bool|int Entry ID.
13 + * @return int | boolean $entry_id
21 14 */
22 15 public static function create( $values ) {
23 - return self::create_entry( $values, 'standard' );
16 + $entry_id = self::create_entry( $values, 'standard' );
17 +
18 + return $entry_id;
24 19 }
25 20
26 21 /**
27 22 * Create a new entry with some differences depending on type
28 23 *
29 - * @param array $values
24 + * @param array $values
30 25 * @param string $type
31 26 *
32 - * @return bool|int Entry ID.
27 + * @return int | boolean $entry_id
33 28 */
34 29 private static function create_entry( $values, $type ) {
35 30 $new_values = self::before_insert_entry_in_database( $values, $type );
36 31
37 32 // Don't check XML entries for duplicates
38 - if ( $type !== 'xml' && self::is_duplicate( $new_values, $values ) ) {
33 + if ( $type != 'xml' && self::is_duplicate( $new_values, $values ) ) {
39 34 return false;
40 35 }
41 36
42 - return self::continue_to_create_entry( $values, $new_values );
43 - }
37 + $entry_id = self::continue_to_create_entry( $values, $new_values );
44 38
45 - /**
46 - * Flag the memoized unique id check after a new entry is created.
47 - * This prevents possibly DB requests and helps avoid issues when creating repeater entries.
48 - *
49 - * @since 6.16.3
50 - *
51 - * @param string $unique_id
52 - *
53 - * @return void
54 - */
55 - private static function flag_new_unique_key( $unique_id ) {
56 - if ( ! isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
57 - self::$unique_id_match_checks[ $unique_id ] = false;
58 - }
39 + return $entry_id;
59 40 }
60 41
61 42 /**
62 43 * Check for duplicate entries created in the last minute
63 44 *
64 - * @param array $new_values New values.
65 - * @param array $values Values.
66 - *
67 - * @return bool
45 + * @return boolean
68 46 */
69 47 public static function is_duplicate( $new_values, $values ) {
70 48 $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
71 49
@@ -72,63 +50,44 @@
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 - $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) );
55 + $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', ( strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ) );
82 56
83 - unset( $check_val['created_at'], $check_val['updated_at'], $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
57 + unset( $check_val['created_at'], $check_val['updated_at'] );
58 + unset( $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
84 59
85 - // phpcs:ignore Universal.Operators.StrictComparisons
86 60 if ( $new_values['item_key'] == $new_values['name'] ) {
87 61 unset( $check_val['name'] );
88 62 }
89 63
90 - $check_val = apply_filters( 'frm_duplicate_check_val', $check_val );
64 + global $wpdb;
65 + $entry_exists = FrmDb::get_col( $wpdb->prefix . 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
91 66
92 - if ( ! isset( $values['item_meta'] ) ) {
67 + if ( ! $entry_exists || empty( $entry_exists ) || ! isset( $values['item_meta'] ) ) {
93 68 return false;
94 69 }
95 70
96 - $entry_exists = FrmDb::get_col( 'frm_items', $check_val, 'id', array( 'order_by' => 'created_at DESC' ) );
97 -
98 - if ( ! $entry_exists ) {
99 - return false;
100 - }
101 -
102 - global $frm_vars;
103 - $frm_vars['checking_duplicates'] = true;
104 - $is_duplicate = false;
105 -
71 + $is_duplicate = false;
106 72 foreach ( $entry_exists as $entry_exist ) {
107 73 $is_duplicate = true;
108 74
109 - // Make sure it's a duplicate
75 + // make sure it's a duplicate
110 76 $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist );
111 77 $field_metas = array();
112 -
113 78 foreach ( $metas as $meta ) {
114 - if ( 0 === (int) $meta->field_id ) {
115 - continue;
116 - }
117 -
118 79 $field_metas[ $meta->field_id ] = $meta->meta_value;
119 80 }
120 81
82 + // If prev entry is empty and current entry is not, they are not duplicates
121 83 $filtered_vals = array_filter( $values['item_meta'] );
122 - $filtered_vals = self::convert_values_to_their_saved_value( $filtered_vals, $entry_exist );
123 84 $field_metas = array_filter( $field_metas );
124 -
125 - // If prev entry is empty and current entry is not, they are not duplicates
126 - if ( ! $field_metas && $filtered_vals ) {
85 + if ( empty( $field_metas ) && ! empty( $filtered_vals ) ) {
127 86 return false;
128 87 }
129 88
130 - // Compare serialized values and not arrays
89 + // compare serialized values and not arrays
131 90 $new_meta = array_map( 'maybe_serialize', $filtered_vals );
132 91
133 92 if ( $field_metas === $new_meta ) {
134 93 $is_duplicate = true;
@@ -141,12 +100,12 @@
141 100 continue;
142 101 }
143 102
144 103 $diff = array_diff_assoc( $field_metas, $new_meta );
145 -
146 - foreach ( $diff as $meta_value ) {
147 - if ( $meta_value ) {
104 + foreach ( $diff as $field_id => $meta_value ) {
105 + if ( ! empty( $meta_value ) ) {
148 106 $is_duplicate = false;
107 + continue;
149 108 }
150 109 }
151 110
152 111 if ( $is_duplicate ) {
@@ -151,119 +110,26 @@
151 110
152 111 if ( $is_duplicate ) {
153 112 break;
154 113 }
155 - }//end foreach
114 + }
156 115
157 - $frm_vars['checking_duplicates'] = false;
158 -
159 116 return $is_duplicate;
160 117 }
161 118
162 119 /**
163 - * @since 6.16.3
164 - *
165 - * @param array $values POST request data.
166 - * @param string $created_at The timestamp of the entry we are checking for.
167 - *
168 - * @return bool
169 - */
170 - private static function maybe_check_for_unique_id_match( $values, $created_at ) {
171 - if ( ! self::should_check_for_unique_id_match() ) {
172 - return false;
173 - }
174 -
175 - if ( empty( $values['unique_id'] ) ) {
176 - return false;
177 - }
178 -
179 - $unique_id = sanitize_key( $values['unique_id'] );
180 -
181 - if ( ! $unique_id ) {
182 - // Only continue if a unique ID was generated on form submit.
183 - return false;
184 - }
185 -
186 - if ( isset( self::$unique_id_match_checks[ $unique_id ] ) ) {
187 - return self::$unique_id_match_checks[ $unique_id ];
188 - }
189 -
190 - $timestamp = strtotime( $created_at );
191 -
192 - if ( false === $timestamp ) {
193 - $timestamp = time();
194 - }
195 -
196 - self::$unique_id_match_checks[ $unique_id ] = (bool) FrmDb::get_var(
197 - 'frm_item_metas',
198 - array(
199 - 'field_id' => 0,
200 - 'meta_value' => serialize( compact( 'unique_id' ) ),
201 - 'created_at >' => gmdate( 'Y-m-d H:i:s', $timestamp - MONTH_IN_SECONDS ),
202 - ),
203 - 'id'
204 - );
205 -
206 - return self::$unique_id_match_checks[ $unique_id ];
207 - }
208 -
209 - /**
210 - * @since 6.16.3
211 - *
212 - * @return bool
213 - */
214 - private static function should_check_for_unique_id_match() {
215 - /**
216 - * Allow users to opt out of the DB query, in case it causes performance issues.
217 - *
218 - * @since 6.16.3
219 - *
220 - * @param bool $should_extend
221 - */
222 - $should_check = apply_filters( 'frm_check_for_unique_id_match', true );
223 - return (bool) $should_check;
224 - }
225 -
226 - /**
227 - * Convert form data to the actual value that would be saved into the database.
228 - *
229 - * This is important for the duplicate check as something like 'a:2:{s:5:"typed";s:0:"";s:6:"output";s:0:"";}'
230 - * (a signature value) is actually an empty string and does not get saved.
231 - *
232 - * @param array $filter_vals
233 - * @param int $entry_id
234 - *
235 - * @return array
236 - */
237 - private static function convert_values_to_their_saved_value( $filter_vals, $entry_id ) {
238 - $reduced = array();
239 -
240 - foreach ( $filter_vals as $field_id => $value ) {
241 - $field = FrmFieldFactory::get_field_object( $field_id );
242 - $reduced[ $field_id ] = $field->get_value_to_save( $value, array( 'entry_id' => $entry_id ) );
243 - $reduced[ $field_id ] = $field->set_value_before_save( $reduced[ $field_id ] );
244 -
245 - if ( '' === $reduced[ $field_id ] || array() === $reduced[ $field_id ] ) {
246 - unset( $reduced[ $field_id ] );
247 - }
248 - }
249 -
250 - return $reduced;
251 - }
252 -
253 - /**
254 120 * Determine if an entry needs to be checked as a possible duplicate
255 121 *
256 122 * @since 2.0.23
257 123 *
258 124 * @param array $values
259 - * @param int $duplicate_entry_time
125 + * @param int $duplicate_entry_time
260 126 *
261 127 * @return bool
262 128 */
263 129 private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
264 130 // If time for checking duplicates is set to an empty value, don't check for duplicates
265 - if ( ! $duplicate_entry_time ) {
131 + if ( empty( $duplicate_entry_time ) ) {
266 132 return false;
267 133 }
268 134
269 135 // If CSV is importing, don't check for duplicates
@@ -271,20 +137,20 @@
271 137 return false;
272 138 }
273 139
274 140 // If repeating field entries are getting created, don't check for duplicates
275 - return empty( $values['parent_form_id'] );
141 + if ( isset( $values['parent_form_id'] ) && $values['parent_form_id'] ) {
142 + return false;
143 + }
144 +
145 + return true;
276 146 }
277 147
278 - /**
279 - * @param int|string $id
280 - *
281 - * @return false|int
282 - */
283 148 public static function duplicate( $id ) {
284 149 global $wpdb;
285 150
286 - $values = self::getOne( $id );
151 + $values = self::getOne( $id );
152 +
287 153 $new_values = array();
288 154 $new_values['item_key'] = FrmAppHelper::get_unique_key( '', $wpdb->prefix . 'frm_items', 'item_key' );
289 155 $new_values['name'] = $values->name;
290 156 $new_values['is_draft'] = $values->is_draft;
@@ -294,9 +160,8 @@
294 160 $new_values['created_at'] = current_time( 'mysql', 1 );
295 161 $new_values['updated_at'] = $new_values['created_at'];
296 162
297 163 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
298 -
299 164 if ( ! $query_results ) {
300 165 return false;
301 166 }
302 167
@@ -302,9 +167,8 @@
302 167
303 168 $entry_id = $wpdb->insert_id;
304 169
305 170 global $frm_vars;
306 -
307 171 if ( ! isset( $frm_vars['saved_entries'] ) ) {
308 172 $frm_vars['saved_entries'] = array();
309 173 }
310 174 $frm_vars['saved_entries'][] = (int) $entry_id;
@@ -319,15 +183,17 @@
319 183
320 184 /**
321 185 * Update an entry (not via XML)
322 186 *
323 - * @param int $id
187 + * @param int $id
324 188 * @param array $values
325 189 *
326 - * @return bool|int Update results.
190 + * @return boolean|int $update_results
327 191 */
328 192 public static function update( $id, $values ) {
329 - return self::update_entry( $id, $values, 'standard' );
193 + $update_results = self::update_entry( $id, $values, 'standard' );
194 +
195 + return $update_results;
330 196 }
331 197
332 198 /**
333 199 * Update an entry with some differences depending on the update type
@@ -333,24 +199,23 @@
333 199 * Update an entry with some differences depending on the update type
334 200 *
335 201 * @since 2.0.16
336 202 *
337 - * @param int $id
338 - * @param array $values
339 - * @param string $update_type
203 + * @param int $id
204 + * @param array $values
340 205 *
341 - * @return bool|int Query results.
206 + * @return boolean|int $query_results
342 207 */
343 208 private static function update_entry( $id, $values, $update_type ) {
344 209 global $wpdb;
345 210
346 211 $update = self::before_update_entry( $id, $values, $update_type );
347 -
348 212 if ( ! $update ) {
349 213 return false;
350 214 }
351 215
352 - $new_values = self::package_entry_to_update( $id, $values );
216 + $new_values = self::package_entry_to_update( $id, $values );
217 +
353 218 $query_results = $wpdb->update( $wpdb->prefix . 'frm_items', $new_values, compact( 'id' ) );
354 219
355 220 self::after_update_entry( $query_results, $id, $values, $new_values );
356 221
@@ -356,32 +221,19 @@
356 221
357 222 return $query_results;
358 223 }
359 224
360 - /**
361 - * Delete an entry.
362 - *
363 - * @param int|string $id
364 - *
365 - * @return bool True on success, false if nothing was deleted.
366 - */
367 225 public static function destroy( $id ) {
368 226 global $wpdb;
369 227 $id = (int) $id;
370 228
371 - // Item meta is required for conditional logic in actions with 'delete' events.
372 - $entry = self::getOne( $id, true );
229 + $entry = self::getOne( $id );
230 + if ( ! $entry ) {
231 + $result = false;
373 232
374 - if ( ! $entry ) {
375 - return false;
233 + return $result;
376 234 }
377 235
378 - /**
379 - * Trigger an action to run custom logic before the entry is deleted.
380 - *
381 - * @param int $id The id of the entry that was destroyed.
382 - * @param stdClass $entry The entry object.
383 - */
384 236 do_action( 'frm_before_destroy_entry', $id, $entry );
385 237
386 238 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
387 239 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -387,34 +239,15 @@
387 239 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
388 240
389 241 self::clear_cache();
390 242
391 - /**
392 - * Trigger an action to run custom logic after the entry is deleted.
393 - * Use this hook if you need to update caching after an entry is deleted.
394 - *
395 - * @since 5.4.1
396 - *
397 - * @param int $id The id of the entry that was destroyed.
398 - * @param stdClass $entry The entry object.
399 - */
400 - do_action( 'frm_after_destroy_entry', $id, $entry );
401 -
402 243 return $result;
403 244 }
404 245
405 - /**
406 - * @param int $id
407 - * @param mixed $value
408 - * @param int|string $form_id
409 - *
410 - * @return false|int
411 - */
412 246 public static function update_form( $id, $value, $form_id ) {
413 247 global $wpdb;
414 248 $form_id = isset( $value ) ? $form_id : null;
415 249 $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) );
416 -
417 250 if ( $result ) {
418 251 self::clear_cache();
419 252 }
420 253
@@ -425,10 +258,8 @@
425 258 * Clear entry caching
426 259 * Called when an entry is changed
427 260 *
428 261 * @since 2.0.5
429 - *
430 - * @return void
431 262 */
432 263 public static function clear_cache() {
433 264 FrmDb::cache_delete_group( 'frm_entry' );
434 265 FrmDb::cache_delete_group( 'frm_item' );
@@ -440,42 +271,33 @@
440 271 * After switching to the wp_loaded hook for processing entries,
441 272 * we can no longer use 'name', but check it as a fallback
442 273 *
443 274 * @since 2.0.11
444 - *
445 - * @param array $values
446 - * @param array|string $default
447 - *
448 - * @return string
449 275 */
450 276 public static function get_new_entry_name( $values, $default = '' ) {
451 - $name = $values['item_name'] ?? $values['name'] ?? $default;
452 - return is_array( $name ) ? reset( $name ) : $name;
277 + $name = isset( $values['item_name'] ) ? $values['item_name'] : ( isset( $values['name'] ) ? $values['name'] : $default );
278 + if ( is_array( $name ) ) {
279 + $name = reset( $name );
280 + }
281 +
282 + return $name;
453 283 }
454 284
455 285 /**
456 286 * If $entry is numeric, get the entry object
457 287 *
288 + * @param int|object $entry by reference
289 + *
458 290 * @since 2.0.9
459 - *
460 - * @param int|object|string $entry By reference.
461 - *
462 - * @return void
463 291 */
464 292 public static function maybe_get_entry( &$entry ) {
465 293 if ( $entry && is_numeric( $entry ) ) {
466 294 $entry = self::getOne( $entry );
467 - } elseif ( ! $entry || 'false' === $entry ) {
295 + } elseif ( empty( $entry ) || 'false' === $entry ) {
468 296 $entry = false;
469 297 }
470 298 }
471 299
472 - /**
473 - * @param int|string $id
474 - * @param bool $meta
475 - *
476 - * @return object|null
477 - */
478 300 public static function getOne( $id, $meta = false ) {
479 301 global $wpdb;
480 302
481 303 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
@@ -480,11 +302,11 @@
480 302
481 303 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
482 304 LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
483 305
484 - $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
306 + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
485 307 $query_args = array( $id );
486 - $query = $wpdb->prepare( $query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
308 + $query = $wpdb->prepare( $query, $query_args ); // WPCS: unprepared SQL ok.
487 309
488 310 if ( ! $meta ) {
489 311 $entry = FrmDb::check_cache( $id . '_nometa', 'frm_entry', $query, 'get_row' );
490 312 self::prepare_entry( $entry );
@@ -491,15 +313,14 @@
491 313 return $entry;
492 314 }
493 315
494 316 $entry = FrmDb::check_cache( $id, 'frm_entry' );
495 -
496 317 if ( $entry !== false ) {
497 318 self::prepare_entry( $entry );
498 319 return $entry;
499 320 }
500 321
501 - $entry = $wpdb->get_row( $query ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
322 + $entry = $wpdb->get_row( $query ); // WPCS: unprepared SQL ok.
502 323 $entry = self::get_meta( $entry );
503 324 self::prepare_entry( $entry );
504 325
505 326 return $entry;
@@ -508,19 +329,16 @@
508 329 /**
509 330 * @since 4.02.03
510 331 *
511 332 * @param object $entry
512 - *
513 - * @return void
514 333 */
515 334 private static function prepare_entry( &$entry ) {
516 - if ( ! $entry ) {
335 + if ( empty( $entry ) ) {
517 336 return;
518 337 }
519 338
520 339 FrmAppHelper::unserialize_or_decode( $entry->description );
521 - // TODO: Remove slashes on input only, not output.
522 - $entry = wp_unslash( $entry );
340 + $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output.
523 341 }
524 342
525 343 /**
526 344 * @since 4.02.03
@@ -525,10 +343,8 @@
525 343 /**
526 344 * @since 4.02.03
527 345 *
528 346 * @param array $entries
529 - *
530 - * @return void
531 347 */
532 348 private static function prepare_entries( &$entries ) {
533 349 foreach ( $entries as $k => $entry ) {
534 350 self::prepare_entry( $entry );
@@ -535,13 +351,8 @@
535 351 $entries[ $k ] = $entry;
536 352 }
537 353 }
538 354
539 - /**
540 - * @param object|null $entry
541 - *
542 - * @return object|null
543 - */
544 355 public static function get_meta( $entry ) {
545 356 if ( ! $entry ) {
546 357 return $entry;
547 358 }
@@ -552,21 +363,18 @@
552 363 array(
553 364 'item_id' => $entry->id,
554 365 'field_id !' => 0,
555 366 ),
556 - 'field_id, meta_value, field_key, item_id, f.type'
367 + 'field_id, meta_value, field_key, item_id'
557 368 );
558 369
559 370 $entry->metas = array();
560 371
561 372 $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
562 -
563 373 foreach ( $metas as $meta_val ) {
564 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
565 -
566 - if ( (int) $meta_val->item_id === (int) $entry->id ) {
374 + if ( $meta_val->item_id == $entry->id ) {
375 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
567 376 $entry->metas[ $meta_val->field_id ] = $meta_val->meta_value;
568 -
569 377 if ( $include_key ) {
570 378 $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
571 379 }
572 380 continue;
@@ -571,17 +379,18 @@
571 379 }
572 380 continue;
573 381 }
574 382
575 - // Include sub entries in an array
576 - if ( ! isset( $entry->metas[ $meta_val->field_id ] ) ) {
383 + // include sub entries in an array
384 + if ( ! isset( $entry_metas[ $meta_val->field_id ] ) ) {
577 385 $entry->metas[ $meta_val->field_id ] = array();
578 386 }
579 387
388 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
580 389 $entry->metas[ $meta_val->field_id ][] = $meta_val->meta_value;
581 390
582 391 unset( $meta_val );
583 - }//end foreach
392 + }
584 393 unset( $metas );
585 394
586 395 FrmDb::set_cache( $entry->id, $entry, 'frm_entry' );
587 396
@@ -589,60 +398,60 @@
589 398 }
590 399
591 400 /**
592 401 * @param string $id
593 - *
594 - * @return bool
595 402 */
596 403 public static function exists( $id ) {
404 + global $wpdb;
405 +
597 406 if ( FrmDb::check_cache( $id, 'frm_entry' ) ) {
598 - return true;
407 + $exists = true;
408 +
409 + return $exists;
599 410 }
600 411
601 - $where = is_numeric( $id ) ? array( 'id' => $id ) : array( 'item_key' => $id );
602 - $id = FrmDb::get_var( 'frm_items', $where );
412 + if ( is_numeric( $id ) ) {
413 + $where = array( 'id' => $id );
414 + } else {
415 + $where = array( 'item_key' => $id );
416 + }
417 + $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
603 418
604 - return $id && $id > 0;
419 + return ( $id && $id > 0 );
605 420 }
606 421
607 - /**
608 - * @param array|string $where
609 - * @param string $order_by
610 - * @param string $limit
611 - * @param bool $meta
612 - * @param bool $inc_form
613 - *
614 - * @return array
615 - */
616 422 public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
617 423 global $wpdb;
618 424
619 - $limit = FrmDb::esc_limit( $limit );
425 + $limit = FrmDb::esc_limit( $limit );
426 +
620 427 $cache_key = FrmAppHelper::maybe_json_encode( $where ) . $order_by . $limit . $inc_form;
621 428 $entries = wp_cache_get( $cache_key, 'frm_entry' );
622 429
623 430 if ( false === $entries ) {
624 - $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft, it.description'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
431 + $fields = 'it.id, it.item_key, it.name, it.ip, it.form_id, it.post_id, it.user_id, it.parent_item_id, it.updated_by, it.created_at, it.updated_at, it.is_draft';
625 432 $table = $wpdb->prefix . 'frm_items it ';
626 433
627 434 if ( $inc_form ) {
628 435 $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
629 - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
436 + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
630 437 }
631 438
632 439 if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
633 - $fields .= self::sort_by_field( $order_matches[1] );
634 - unset( $order_matches );
440 + // sort by a requested field
441 + $field_id = (int) $order_matches[1];
442 + $fields .= ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
443 + unset( $order_matches, $field_id );
635 444 }
636 445
637 - // Prepare the query
446 + // prepare the query
638 447 $query = 'SELECT ' . $fields . ' FROM ' . $table . FrmDb::prepend_and_or_where( ' WHERE ', $where ) . $order_by . $limit;
639 448
640 - $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
449 + $entries = $wpdb->get_results( $query, OBJECT_K ); // WPCS: unprepared SQL ok.
641 450 unset( $query );
642 451
643 452 FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
644 - }//end if
453 + }
645 454
646 455 if ( ! $meta || ! $entries ) {
647 456 self::prepare_entries( $entries );
648 457 return $entries;
@@ -653,21 +462,15 @@
653 462 $where = array( 'it.form_id' => substr( $where, 11 ) );
654 463 }
655 464
656 465 $meta_where = array( 'field_id !' => 0 );
657 -
658 - // phpcs:ignore Universal.Operators.StrictComparisons
659 - if ( $limit == '' && is_array( $where ) && count( $where ) === 1 && isset( $where['it.form_id'] ) ) {
466 + if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) {
660 467 $meta_where['fi.form_id'] = $where['it.form_id'];
661 468 } else {
662 469 $meta_where['item_id'] = array_keys( $entries );
663 470 }
664 471
665 - $metas = FrmDb::get_results(
666 - $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id = fi.id',
667 - $meta_where,
668 - 'item_id, meta_value, field_id, field_key, form_id, fi.type'
669 - );
472 + $metas = FrmDb::get_results( $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON (it.field_id = fi.id)', $meta_where, 'item_id, meta_value, field_id, field_key, form_id' );
670 473
671 474 unset( $meta_where );
672 475
673 476 if ( ! $metas ) {
@@ -683,9 +486,9 @@
683 486 if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
684 487 $entries[ $meta_val->item_id ]->metas = array();
685 488 }
686 489
687 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
490 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
688 491 $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = $meta_val->meta_value;
689 492 unset( $m_key, $meta_val );
690 493 }
691 494
@@ -699,37 +502,15 @@
699 502 self::prepare_entries( $entries );
700 503 return $entries;
701 504 }
702 505
703 - /**
704 - * @param int|string $field_id
705 - *
706 - * @return string
707 - */
708 - private static function sort_by_field( $field_id ) {
709 - global $wpdb;
710 - $field_id = (int) $field_id;
711 - $field_options = FrmDb::get_var( 'frm_fields', array( 'id' => $field_id ), 'field_options' );
712 - FrmAppHelper::unserialize_or_decode( $field_options );
713 -
714 - if ( empty( $field_options['post_field'] ) ) {
715 - $sort = ', (SELECT meta_value FROM ' . $wpdb->prefix . 'frm_item_metas WHERE field_id = ' . $field_id . ' AND item_id = it.id) as meta_' . $field_id;
716 - } else {
717 - $sort = '';
718 - }
719 -
720 - return apply_filters( 'frm_handle_field_column_sort', $sort, $field_id, $field_options );
721 - }
722 -
723 506 // Pagination Methods
724 507 /**
725 - * @param array|int|string $where If int, use the form id.
726 - *
727 - * @return int|string
508 + * @param int|array|string If int, use the form id.
728 509 */
729 510 public static function getRecordCount( $where = '' ) {
730 511 global $wpdb;
731 - $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
512 + $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
732 513
733 514 if ( is_numeric( $where ) ) {
734 515 $table_join = 'frm_items';
735 516 $where = array( 'form_id' => $where );
@@ -735,35 +516,29 @@
735 516 $where = array( 'form_id' => $where );
736 517 }
737 518
738 519 if ( is_array( $where ) ) {
739 - return FrmDb::get_count( $table_join, $where );
520 + $count = FrmDb::get_count( $table_join, $where );
521 + } else {
522 + $cache_key = 'count_' . FrmAppHelper::maybe_json_encode( $where );
523 + $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
524 + $count = FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
740 525 }
741 526
742 - $cache_key = 'count_' . FrmAppHelper::maybe_json_encode( $where );
743 - $query = 'SELECT COUNT(*) FROM ' . $table_join . FrmDb::prepend_and_or_where( ' WHERE ', $where );
744 -
745 - return FrmDb::check_cache( $cache_key, 'frm_entry', $query, 'get_var' );
527 + return $count;
746 528 }
747 529
748 - /**
749 - * @param int|string $p_size
750 - * @param array|int|string $where
751 - *
752 - * @return int
753 - */
754 530 public static function getPageCount( $p_size, $where = '' ) {
755 531 $p_size = (int) $p_size;
756 -
532 + $count = 1;
757 533 if ( $p_size ) {
758 534 if ( ! is_numeric( $where ) ) {
759 535 $where = self::getRecordCount( $where );
760 536 }
761 -
762 - return ceil( (int) $where / $p_size );
537 + $count = ceil( (int) $where / $p_size );
763 538 }
764 539
765 - return 1;
540 + return $count;
766 541 }
767 542
768 543 /**
769 544 * Prepare the data before inserting it into the database
@@ -769,21 +544,24 @@
769 544 * Prepare the data before inserting it into the database
770 545 *
771 546 * @since 2.0.16
772 547 *
773 - * @param array $values
548 + * @param array $values
774 549 * @param string $type
775 550 *
776 - * @return array New values.
551 + * @return array $new_values
777 552 */
778 553 private static function before_insert_entry_in_database( &$values, $type ) {
554 +
779 555 self::sanitize_entry_post( $values );
780 556
781 - if ( $type !== 'xml' ) {
557 + if ( $type != 'xml' ) {
782 558 $values = apply_filters( 'frm_pre_create_entry', $values );
783 559 }
784 560
785 - return self::package_entry_data( $values );
561 + $new_values = self::package_entry_data( $values );
562 +
563 + return $new_values;
786 564 }
787 565
788 566 /**
789 567 * Create an entry and perform after create actions
@@ -792,13 +570,12 @@
792 570 *
793 571 * @param array $values
794 572 * @param array $new_values
795 573 *
796 - * @return bool|int Entry ID.
574 + * @return boolean|int $entry_id
797 575 */
798 576 private static function continue_to_create_entry( $values, $new_values ) {
799 577 $entry_id = self::insert_entry_into_database( $new_values );
800 -
801 578 if ( ! $entry_id ) {
802 579 return false;
803 580 }
804 581
@@ -811,11 +588,9 @@
811 588 * Sanitize the POST values before we use them
812 589 *
813 590 * @since 2.0
814 591 *
815 - * @param array $values The POST values by reference.
816 - *
817 - * @return void
592 + * @param array $values The POST values by reference
818 593 */
819 594 public static function sanitize_entry_post( &$values ) {
820 595 $sanitize_method = array(
821 596 'form_id' => 'absint',
@@ -840,9 +615,9 @@
840 615 * @since 2.0.16
841 616 *
842 617 * @param array $values
843 618 *
844 - * @return array New values.
619 + * @return array $new_values
845 620 */
846 621 private static function package_entry_data( &$values ) {
847 622 global $wpdb;
848 623
@@ -852,9 +627,9 @@
852 627
853 628 $item_name = self::get_new_entry_name( $values, $values['item_key'] );
854 629 $new_values = array(
855 630 'item_key' => FrmAppHelper::get_unique_key( $values['item_key'], $wpdb->prefix . 'frm_items', 'item_key' ),
856 - 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '', true ),
631 + 'name' => FrmAppHelper::truncate( $item_name, 255, 1, '' ),
857 632 'ip' => self::get_ip( $values ),
858 633 'is_draft' => self::get_is_draft_value( $values ),
859 634 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
860 635 'post_id' => (int) self::get_entry_value( $values, 'post_id', 0 ),
@@ -864,22 +639,15 @@
864 639 'description' => self::get_entry_description( $values ),
865 640 'user_id' => self::get_entry_user_id( $values ),
866 641 );
867 642
868 - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id'];
643 + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
869 644
870 645 return $new_values;
871 646 }
872 647
873 - /**
874 - * @param array $values
875 - * @param string $name
876 - * @param mixed $default
877 - *
878 - * @return mixed
879 - */
880 648 private static function get_entry_value( $values, $name, $default ) {
881 - return $values[ $name ] ?? $default;
649 + return isset( $values[ $name ] ) ? $values[ $name ] : $default;
882 650 }
883 651
884 652 /**
885 653 * Get the ip for a new entry.
@@ -896,11 +664,10 @@
896 664 return '';
897 665 }
898 666
899 667 $ip = FrmAppHelper::get_ip_address();
900 -
901 668 if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) {
902 - return self::get_entry_value( $values, 'ip', $ip );
669 + $ip = self::get_entry_value( $values, 'ip', $ip );
903 670 }
904 671
905 672 return $ip;
906 673 }
@@ -914,13 +681,9 @@
914 681 *
915 682 * @return int
916 683 */
917 684 private static function get_is_draft_value( $values ) {
918 - if ( isset( $values['frm_saving_draft'] ) && FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $values['frm_saving_draft'] ) {
919 - return FrmEntriesHelper::DRAFT_ENTRY_STATUS;
920 - }
921 -
922 - return isset( $values['is_draft'] ) ? absint( $values['is_draft'] ) : FrmEntriesHelper::SUBMITTED_ENTRY_STATUS;
685 + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
923 686 }
924 687
925 688 /**
926 689 * Get the created_at value for a new entry
@@ -944,9 +707,15 @@
944 707 *
945 708 * @return string
946 709 */
947 710 private static function get_updated_at( $values ) {
948 - return $values['updated_at'] ?? self::get_created_at( $values );
711 + if ( isset( $values['updated_at'] ) ) {
712 + $updated_at = $values['updated_at'];
713 + } else {
714 + $updated_at = self::get_created_at( $values );
715 + }
716 +
717 + return $updated_at;
949 718 }
950 719
951 720 /**
952 721 * Get the description value for a new entry
@@ -957,18 +726,20 @@
957 726 *
958 727 * @return string
959 728 */
960 729 private static function get_entry_description( $values ) {
961 - if ( ! empty( $values['description'] ) ) {
962 - return FrmAppHelper::maybe_json_encode( $values['description'] );
730 + if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
731 + $description = FrmAppHelper::maybe_json_encode( $values['description'] );
732 + } else {
733 + $description = json_encode(
734 + array(
735 + 'browser' => FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ),
736 + 'referrer' => FrmAppHelper::get_server_value( 'HTTP_REFERER' ),
737 + )
738 + );
963 739 }
964 740
965 - return json_encode(
966 - array(
967 - 'browser' => FrmAppHelper::get_server_value( 'HTTP_USER_AGENT' ),
968 - 'referrer' => FrmAppHelper::get_server_value( 'HTTP_REFERER' ),
969 - )
970 - );
741 + return $description;
971 742 }
972 743
973 744 /**
974 745 * Get the user_id value for a new entry
@@ -980,13 +751,15 @@
980 751 * @return int
981 752 */
982 753 private static function get_entry_user_id( $values ) {
983 754 if ( isset( $values['frm_user_id'] ) && ( is_numeric( $values['frm_user_id'] ) || FrmAppHelper::is_admin() ) ) {
984 - return $values['frm_user_id'];
755 + $user_id = $values['frm_user_id'];
756 + } else {
757 + $current_user_id = get_current_user_id();
758 + $user_id = $current_user_id ? $current_user_id : 0;
985 759 }
986 760
987 - $current_user_id = get_current_user_id();
988 - return $current_user_id ? $current_user_id : 0;
761 + return $user_id;
989 762 }
990 763
991 764 /**
992 765 * Insert new entry into the database
@@ -994,9 +767,9 @@
994 767 * @since 2.0.16
995 768 *
996 769 * @param array $new_values
997 770 *
998 - * @return bool|int Entry ID.
771 + * @return int | boolean $entry_id
999 772 */
1000 773 private static function insert_entry_into_database( $new_values ) {
1001 774 global $wpdb;
1002 775
@@ -1001,9 +774,15 @@
1001 774 global $wpdb;
1002 775
1003 776 $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values );
1004 777
1005 - return $query_results ? $wpdb->insert_id : false;
778 + if ( ! $query_results ) {
779 + $entry_id = false;
780 + } else {
781 + $entry_id = $wpdb->insert_id;
782 + }
783 +
784 + return $entry_id;
1006 785 }
1007 786
1008 787 /**
1009 788 * Add the new entry to global $frm_vars
@@ -1009,11 +788,9 @@
1009 788 * Add the new entry to global $frm_vars
1010 789 *
1011 790 * @since 2.0.16
1012 791 *
1013 - * @param int|string $entry_id
1014 - *
1015 - * @return void
792 + * @param int $entry_id
1016 793 */
1017 794 private static function add_new_entry_to_frm_vars( $entry_id ) {
1018 795 global $frm_vars;
1019 796
@@ -1028,92 +805,31 @@
1028 805 * Add entry metas, if there are any
1029 806 *
1030 807 * @since 2.0.16
1031 808 *
1032 - * @param array $values
1033 - * @param int|string $entry_id
1034 - *
1035 - * @return void
809 + * @param array $values
810 + * @param int $entry_id
1036 811 */
1037 812 private static function maybe_add_entry_metas( $values, $entry_id ) {
1038 813 if ( isset( $values['item_meta'] ) ) {
1039 814 FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
1040 - self::maybe_add_unique_id_meta( $values, $entry_id );
1041 815 }
1042 - self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id );
1043 816 }
1044 817
1045 818 /**
1046 - * @since 6.16.3
1047 - *
1048 - * @param array $values
1049 - * @param int $entry_id
1050 - *
1051 - * @return void
1052 - */
1053 - private static function maybe_add_unique_id_meta( $values, $entry_id ) {
1054 - if ( ! empty( $values['parent_form_id'] ) || empty( $values['unique_id'] ) || ! self::should_check_for_unique_id_match() ) {
1055 - return;
1056 - }
1057 -
1058 - // This unique ID is inserted with JS on form submit.
1059 - // It is used to check for duplicate entries.
1060 - $unique_id = sanitize_key( $values['unique_id'] );
1061 -
1062 - if ( ! $unique_id ) {
1063 - return;
1064 - }
1065 -
1066 - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) );
1067 - self::flag_new_unique_key( $unique_id );
1068 - }
1069 -
1070 - /**
1071 - * @since 5.0.15
1072 - *
1073 - * @param int $form_id
1074 - * @param int $entry_id
1075 - *
1076 - * @return void
1077 - */
1078 - private static function maybe_add_captcha_meta( $form_id, $entry_id ) {
1079 - global $frm_vars;
1080 -
1081 - if ( ! array_key_exists( 'captcha_scores', $frm_vars ) || ! array_key_exists( $form_id, $frm_vars['captcha_scores'] ) ) {
1082 - return;
1083 - }
1084 -
1085 - $captcha_score_meta = array( 'captcha_score' => $frm_vars['captcha_scores'][ $form_id ] );
1086 - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', maybe_serialize( $captcha_score_meta ) );
1087 - }
1088 -
1089 - /**
1090 819 * Trigger frm_after_create_entry hooks
1091 820 *
1092 821 * @since 2.0.16
1093 822 *
1094 - * @param int $entry_id
1095 - * @param array $values
823 + * @param int $entry_id
1096 824 * @param array $new_values
1097 - *
1098 - * @return void
1099 825 */
1100 826 private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
1101 - // This is a child entry.
1102 - $is_child = isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
827 + // this is a child entry
828 + $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
1103 829
1104 830 do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
1105 831 do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
1106 -
1107 - if ( ! empty( $values['form_key'] ) ) {
1108 - /**
1109 - * @since 6.30
1110 - *
1111 - * @param int $entry_id
1112 - * @param array $is_child
1113 - */
1114 - do_action( 'frm_after_create_entry_' . $values['form_key'], $entry_id, compact( 'is_child' ) );
1115 - }
1116 832 }
1117 833
1118 834 /**
1119 835 * Actions to perform immediately after an entry is inserted in the frm_items database
@@ -1121,13 +837,12 @@
1121 837 * @since 2.0.16
1122 838 *
1123 839 * @param array $values
1124 840 * @param array $new_values
1125 - * @param int $entry_id
1126 - *
1127 - * @return void
841 + * @param int $entry_id
1128 842 */
1129 843 private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
844 +
1130 845 self::add_new_entry_to_frm_vars( $entry_id );
1131 846
1132 847 self::maybe_add_entry_metas( $values, $entry_id );
1133 848
@@ -1140,13 +855,13 @@
1140 855 * Perform some actions right before updating an entry
1141 856 *
1142 857 * @since 2.0.16
1143 858 *
1144 - * @param int|string $id
1145 - * @param array $values
1146 - * @param string $update_type
859 + * @param int $id
860 + * @param array $values
861 + * @param string $update_type
1147 862 *
1148 - * @return bool Update.
863 + * @return boolean $update
1149 864 */
1150 865 private static function before_update_entry( $id, &$values, $update_type ) {
1151 866 $update = true;
1152 867
@@ -1151,14 +866,13 @@
1151 866 $update = true;
1152 867
1153 868 global $frm_vars;
1154 869
1155 - // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
1156 - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) {
870 + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
1157 871 $update = false;
1158 872 }
1159 873
1160 - if ( $update && $update_type !== 'xml' ) {
874 + if ( $update && $update_type != 'xml' ) {
1161 875 $values = apply_filters( 'frm_pre_update_entry', $values, $id );
1162 876 }
1163 877
1164 878 return $update;
@@ -1168,22 +882,22 @@
1168 882 * Package the entry data for updating
1169 883 *
1170 884 * @since 2.0.16
1171 885 *
1172 - * @param int $id
886 + * @param int $id
1173 887 * @param array $values
1174 888 *
1175 - * @return array New values.
889 + * @return array $new_values
1176 890 */
1177 891 private static function package_entry_to_update( $id, $values ) {
1178 892 global $wpdb;
1179 893
1180 894 $new_values = array(
1181 - 'name' => FrmAppHelper::truncate( self::get_new_entry_name( $values ), 255, 1, '', true ),
895 + 'name' => self::get_new_entry_name( $values ),
1182 896 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
1183 897 'is_draft' => self::get_is_draft_value( $values ),
1184 898 'updated_at' => current_time( 'mysql', 1 ),
1185 - 'updated_by' => $values['updated_by'] ?? get_current_user_id(),
899 + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
1186 900 );
1187 901
1188 902 if ( isset( $values['post_id'] ) ) {
1189 903 $new_values['post_id'] = (int) $values['post_id'];
@@ -1200,9 +914,11 @@
1200 914 if ( isset( $values['frm_user_id'] ) && is_numeric( $values['frm_user_id'] ) ) {
1201 915 $new_values['user_id'] = $values['frm_user_id'];
1202 916 }
1203 917
1204 - return apply_filters( 'frm_update_entry', $new_values, $id );
918 + $new_values = apply_filters( 'frm_update_entry', $new_values, $id );
919 +
920 + return $new_values;
1205 921 }
1206 922
1207 923 /**
1208 924 * Perform some actions right after updating an entry
@@ -1208,14 +924,12 @@
1208 924 * Perform some actions right after updating an entry
1209 925 *
1210 926 * @since 2.0.16
1211 927 *
1212 - * @param bool|int $query_results
1213 - * @param int|string $id
1214 - * @param array $values
1215 - * @param array $new_values
1216 - *
1217 - * @return void
928 + * @param boolean|int $query_results
929 + * @param int $id
930 + * @param array $values
931 + * @param array $new_values
1218 932 */
1219 933 private static function after_update_entry( $query_results, $id, $values, $new_values ) {
1220 934 if ( $query_results ) {
1221 935 self::clear_cache();
@@ -1221,9 +935,8 @@
1221 935 self::clear_cache();
1222 936 }
1223 937
1224 938 global $frm_vars;
1225 -
1226 939 if ( ! isset( $frm_vars['saved_entries'] ) ) {
1227 940 $frm_vars['saved_entries'] = array();
1228 941 }
1229 942
@@ -1234,17 +947,8 @@
1234 947 }
1235 948
1236 949 do_action( 'frm_after_update_entry', $id, $new_values['form_id'] );
1237 950 do_action( 'frm_after_update_entry_' . $new_values['form_id'], $id );
1238 -
1239 - if ( ! empty( $values['form_key'] ) ) {
1240 - /**
1241 - * @since 6.30
1242 - *
1243 - * @param int $entry_id
1244 - */
1245 - do_action( 'frm_after_update_entry_' . $values['form_key'], $id );
1246 - }
1247 951 }
1248 952
1249 953 /**
1250 954 * Create entry from an XML import
@@ -1253,12 +957,14 @@
1253 957 * @since 2.0.16
1254 958 *
1255 959 * @param array $values
1256 960 *
1257 - * @return bool|int Entry ID.
961 + * @return int | boolean $entry_id
1258 962 */
1259 963 public static function create_entry_from_xml( $values ) {
1260 - return self::create_entry( $values, 'xml' );
964 + $entry_id = self::create_entry( $values, 'xml' );
965 +
966 + return $entry_id;
1261 967 }
1262 968
1263 969 /**
1264 970 * Update entry from an XML import
@@ -1265,15 +971,17 @@
1265 971 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
1266 972 *
1267 973 * @since 2.0.16
1268 974 *
1269 - * @param int $id
975 + * @param int $id
1270 976 * @param array $values
1271 977 *
1272 - * @return bool|int Updated.
978 + * @return int | boolean $updated
1273 979 */
1274 980 public static function update_entry_from_xml( $id, $values ) {
1275 - return self::update_entry( $id, $values, 'xml' );
981 + $updated = self::update_entry( $id, $values, 'xml' );
982 +
983 + return $updated;
1276 984 }
1277 985
1278 986 /**
1279 987 * @param string $key
@@ -1281,23 +989,8 @@
1281 989 * @return int entry_id
1282 990 */
1283 991 public static function get_id_by_key( $key ) {
1284 992 $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
993 +
1285 994 return (int) $entry_id;
1286 - }
1287 -
1288 - /**
1289 - * Get entries count.
1290 - *
1291 - * @since 6.8
1292 - *
1293 - * @return int|string
1294 - */
1295 - public static function get_entries_count() {
1296 - $args = array(
1297 - 'or' => 1,
1298 - 'parent_form_id' => null,
1299 - 'parent_form_id <' => 1,
1300 - );
1301 - return self::getRecordCount( $args );
1302 995 }
1303 996 }