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