PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.0
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.0
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 +59 -201 6.256.0 View file →
@@ -5,20 +5,13 @@
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 16 $entry_id = self::create_entry( $values, 'standard' );
24 17
@@ -27,18 +20,18 @@
27 20
28 21 /**
29 22 * Create a new entry with some differences depending on type
30 23 *
31 - * @param array $values
24 + * @param array $values
32 25 * @param string $type
33 26 *
34 - * @return bool|int $entry_id
27 + * @return int | boolean $entry_id
35 28 */
36 29 private static function create_entry( $values, $type ) {
37 30 $new_values = self::before_insert_entry_in_database( $values, $type );
38 31
39 32 // Don't check XML entries for duplicates
40 - if ( $type !== 'xml' && self::is_duplicate( $new_values, $values ) ) {
33 + if ( $type != 'xml' && self::is_duplicate( $new_values, $values ) ) {
41 34 return false;
42 35 }
43 36
44 37 $entry_id = self::continue_to_create_entry( $values, $new_values );
@@ -46,26 +39,11 @@
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 - * @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,14 +50,10 @@
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 59 if ( $new_values['item_key'] == $new_values['name'] ) {
@@ -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'] );
@@ -135,11 +106,12 @@
135 106 continue;
136 107 }
137 108
138 109 $diff = array_diff_assoc( $field_metas, $new_meta );
139 - foreach ( $diff as $meta_value ) {
110 + foreach ( $diff as $field_id => $meta_value ) {
140 111 if ( ! empty( $meta_value ) ) {
141 112 $is_duplicate = false;
113 + continue;
142 114 }
143 115 }
144 116
145 117 if ( $is_duplicate ) {
@@ -144,9 +116,9 @@
144 116
145 117 if ( $is_duplicate ) {
146 118 break;
147 119 }
148 - }//end foreach
120 + }
149 121
150 122 $frm_vars['checking_duplicates'] = false;
151 123
152 124 return $is_duplicate;
@@ -152,67 +124,8 @@
152 124 return $is_duplicate;
153 125 }
154 126
155 127 /**
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 128 * Convert form data to the actual value that would be saved into the database.
216 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.
217 130 *
218 131 * @param array $filter_vals
@@ -237,9 +150,9 @@
237 150 *
238 151 * @since 2.0.23
239 152 *
240 153 * @param array $values
241 - * @param int $duplicate_entry_time
154 + * @param int $duplicate_entry_time
242 155 *
243 156 * @return bool
244 157 */
245 158 private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
@@ -299,12 +212,12 @@
299 212
300 213 /**
301 214 * Update an entry (not via XML)
302 215 *
303 - * @param int $id
216 + * @param int $id
304 217 * @param array $values
305 218 *
306 - * @return bool|int $update_results
219 + * @return boolean|int $update_results
307 220 */
308 221 public static function update( $id, $values ) {
309 222 $update_results = self::update_entry( $id, $values, 'standard' );
310 223
@@ -315,12 +228,12 @@
315 228 * Update an entry with some differences depending on the update type
316 229 *
317 230 * @since 2.0.16
318 231 *
319 - * @param int $id
232 + * @param int $id
320 233 * @param array $values
321 234 *
322 - * @return bool|int $query_results
235 + * @return boolean|int $query_results
323 236 */
324 237 private static function update_entry( $id, $values, $update_type ) {
325 238 global $wpdb;
326 239
@@ -340,9 +253,9 @@
340 253
341 254 /**
342 255 * Delete an entry.
343 256 *
344 - * @param int|string $id
257 + * @param string|int $id
345 258 * @return bool True on success, false if nothing was deleted.
346 259 */
347 260 public static function destroy( $id ) {
348 261 global $wpdb;
@@ -347,10 +260,9 @@
347 260 public static function destroy( $id ) {
348 261 global $wpdb;
349 262 $id = (int) $id;
350 263
351 - // Item meta is required for conditional logic in actions with 'delete' events.
352 - $entry = self::getOne( $id, true );
264 + $entry = self::getOne( $id, true ); // Item meta is required for conditional logic in actions with 'delete' events.
353 265 if ( ! $entry ) {
354 266 $result = false;
355 267 return $result;
356 268 }
@@ -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
@@ -423,12 +335,11 @@
423 335
424 336 /**
425 337 * If $entry is numeric, get the entry object
426 338 *
339 + * @param int|object $entry by reference
340 + *
427 341 * @since 2.0.9
428 - *
429 - * @param int|object $entry By reference.
430 - * @return void
431 342 */
432 343 public static function maybe_get_entry( &$entry ) {
433 344 if ( $entry && is_numeric( $entry ) ) {
434 345 $entry = self::getOne( $entry );
@@ -442,9 +353,9 @@
442 353
443 354 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
444 355 LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
445 356
446 - $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
357 + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
447 358 $query_args = array( $id );
448 359 $query = $wpdb->prepare( $query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
449 360
450 361 if ( ! $meta ) {
@@ -476,10 +387,9 @@
476 387 return;
477 388 }
478 389
479 390 FrmAppHelper::unserialize_or_decode( $entry->description );
480 - // TODO: Remove slashes on input only, not output.
481 - $entry = wp_unslash( $entry );
391 + $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output.
482 392 }
483 393
484 394 /**
485 395 * @since 4.02.03
@@ -504,9 +414,9 @@
504 414 array(
505 415 'item_id' => $entry->id,
506 416 'field_id !' => 0,
507 417 ),
508 - 'field_id, meta_value, field_key, item_id, f.type'
418 + 'field_id, meta_value, field_key, item_id'
509 419 );
510 420
511 421 $entry->metas = array();
512 422
@@ -511,11 +421,10 @@
511 421 $entry->metas = array();
512 422
513 423 $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
514 424 foreach ( $metas as $meta_val ) {
515 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
516 -
517 425 if ( $meta_val->item_id == $entry->id ) {
426 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
518 427 $entry->metas[ $meta_val->field_id ] = $meta_val->meta_value;
519 428 if ( $include_key ) {
520 429 $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
521 430 }
@@ -526,8 +435,9 @@
526 435 if ( ! isset( $entry->metas[ $meta_val->field_id ] ) ) {
527 436 $entry->metas[ $meta_val->field_id ] = array();
528 437 }
529 438
439 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
530 440 $entry->metas[ $meta_val->field_id ][] = $meta_val->meta_value;
531 441
532 442 unset( $meta_val );
533 443 }
@@ -556,9 +466,9 @@
556 466 $where = array( 'item_key' => $id );
557 467 }
558 468 $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
559 469
560 - return $id && $id > 0;
470 + return ( $id && $id > 0 );
561 471 }
562 472
563 473 public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
564 474 global $wpdb;
@@ -573,9 +483,9 @@
573 483 $table = $wpdb->prefix . 'frm_items it ';
574 484
575 485 if ( $inc_form ) {
576 486 $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
577 - $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 ';
578 488 }
579 489
580 490 if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
581 491 $fields .= self::sort_by_field( $order_matches[1] );
@@ -588,9 +498,9 @@
588 498 $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
589 499 unset( $query );
590 500
591 501 FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
592 - }//end if
502 + }
593 503
594 504 if ( ! $meta || ! $entries ) {
595 505 self::prepare_entries( $entries );
596 506 return $entries;
@@ -607,13 +517,9 @@
607 517 } else {
608 518 $meta_where['item_id'] = array_keys( $entries );
609 519 }
610 520
611 - $metas = FrmDb::get_results(
612 - $wpdb->prefix . 'frm_item_metas it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_fields fi ON it.field_id = fi.id',
613 - $meta_where,
614 - 'item_id, meta_value, field_id, field_key, form_id, fi.type'
615 - );
521 + $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' );
616 522
617 523 unset( $meta_where );
618 524
619 525 if ( ! $metas ) {
@@ -629,9 +535,9 @@
629 535 if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
630 536 $entries[ $meta_val->item_id ]->metas = array();
631 537 }
632 538
633 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
539 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
634 540 $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = $meta_val->meta_value;
635 541 unset( $m_key, $meta_val );
636 542 }
637 543
@@ -667,14 +573,13 @@
667 573 }
668 574
669 575 // Pagination Methods
670 576 /**
671 - * @param array|int|string $where If int, use the form id.
672 - * @return int|string
577 + * @param int|array|string If int, use the form id.
673 578 */
674 579 public static function getRecordCount( $where = '' ) {
675 580 global $wpdb;
676 - $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
581 + $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
677 582
678 583 if ( is_numeric( $where ) ) {
679 584 $table_join = 'frm_items';
680 585 $where = array( 'form_id' => $where );
@@ -690,12 +595,8 @@
690 595
691 596 return $count;
692 597 }
693 598
694 - /**
695 - * @param int|string $p_size
696 - * @return int
697 - */
698 599 public static function getPageCount( $p_size, $where = '' ) {
699 600 $p_size = (int) $p_size;
700 601 $count = 1;
701 602 if ( $p_size ) {
@@ -712,9 +613,9 @@
712 613 * Prepare the data before inserting it into the database
713 614 *
714 615 * @since 2.0.16
715 616 *
716 - * @param array $values
617 + * @param array $values
717 618 * @param string $type
718 619 *
719 620 * @return array $new_values
720 621 */
@@ -721,9 +622,9 @@
721 622 private static function before_insert_entry_in_database( &$values, $type ) {
722 623
723 624 self::sanitize_entry_post( $values );
724 625
725 - if ( $type !== 'xml' ) {
626 + if ( $type != 'xml' ) {
726 627 $values = apply_filters( 'frm_pre_create_entry', $values );
727 628 }
728 629
729 630 $new_values = self::package_entry_data( $values );
@@ -738,9 +639,9 @@
738 639 *
739 640 * @param array $values
740 641 * @param array $new_values
741 642 *
742 - * @return bool|int $entry_id
643 + * @return boolean|int $entry_id
743 644 */
744 645 private static function continue_to_create_entry( $values, $new_values ) {
745 646 $entry_id = self::insert_entry_into_database( $new_values );
746 647 if ( ! $entry_id ) {
@@ -756,9 +657,9 @@
756 657 * Sanitize the POST values before we use them
757 658 *
758 659 * @since 2.0
759 660 *
760 - * @param array $values The POST values by reference.
661 + * @param array $values The POST values by reference
761 662 */
762 663 public static function sanitize_entry_post( &$values ) {
763 664 $sanitize_method = array(
764 665 'form_id' => 'absint',
@@ -807,15 +708,15 @@
807 708 'description' => self::get_entry_description( $values ),
808 709 'user_id' => self::get_entry_user_id( $values ),
809 710 );
810 711
811 - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id'];
712 + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
812 713
813 714 return $new_values;
814 715 }
815 716
816 717 private static function get_entry_value( $values, $name, $default ) {
817 - return $values[ $name ] ?? $default;
718 + return isset( $values[ $name ] ) ? $values[ $name ] : $default;
818 719 }
819 720
820 721 /**
821 722 * Get the ip for a new entry.
@@ -849,13 +750,9 @@
849 750 *
850 751 * @return int
851 752 */
852 753 private static function get_is_draft_value( $values ) {
853 - if ( isset( $values['frm_saving_draft'] ) && FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $values['frm_saving_draft'] ) {
854 - return FrmEntriesHelper::DRAFT_ENTRY_STATUS;
855 - }
856 -
857 - return isset( $values['is_draft'] ) ? absint( $values['is_draft'] ) : FrmEntriesHelper::SUBMITTED_ENTRY_STATUS;
754 + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
858 755 }
859 756
860 757 /**
861 758 * Get the created_at value for a new entry
@@ -898,9 +795,9 @@
898 795 *
899 796 * @return string
900 797 */
901 798 private static function get_entry_description( $values ) {
902 - if ( ! empty( $values['description'] ) ) {
799 + if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
903 800 $description = FrmAppHelper::maybe_json_encode( $values['description'] );
904 801 } else {
905 802 $description = json_encode(
906 803 array(
@@ -939,9 +836,9 @@
939 836 * @since 2.0.16
940 837 *
941 838 * @param array $new_values
942 839 *
943 - * @return bool|int $entry_id
840 + * @return int | boolean $entry_id
944 841 */
945 842 private static function insert_entry_into_database( $new_values ) {
946 843 global $wpdb;
947 844
@@ -978,41 +875,19 @@
978 875 *
979 876 * @since 2.0.16
980 877 *
981 878 * @param array $values
982 - * @param int $entry_id
879 + * @param int $entry_id
983 880 * @return void
984 881 */
985 882 private static function maybe_add_entry_metas( $values, $entry_id ) {
986 883 if ( isset( $values['item_meta'] ) ) {
987 884 FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
988 - self::maybe_add_unique_id_meta( $values, $entry_id );
989 885 }
990 886 self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id );
991 887 }
992 888
993 889 /**
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 890 * @since 5.0.15
1016 891 *
1017 892 * @param int $form_id
1018 893 * @param int $entry_id
@@ -1030,15 +905,14 @@
1030 905 * Trigger frm_after_create_entry hooks
1031 906 *
1032 907 * @since 2.0.16
1033 908 *
1034 - * @param int $entry_id
1035 - * @param array $values
909 + * @param int $entry_id
1036 910 * @param array $new_values
1037 911 */
1038 912 private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
1039 - // This is a child entry.
1040 - $is_child = isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
913 + // this is a child entry
914 + $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
1041 915
1042 916 do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
1043 917 do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
1044 918 }
@@ -1049,9 +923,9 @@
1049 923 * @since 2.0.16
1050 924 *
1051 925 * @param array $values
1052 926 * @param array $new_values
1053 - * @param int $entry_id
927 + * @param int $entry_id
1054 928 */
1055 929 private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
1056 930
1057 931 self::add_new_entry_to_frm_vars( $entry_id );
@@ -1067,13 +941,13 @@
1067 941 * Perform some actions right before updating an entry
1068 942 *
1069 943 * @since 2.0.16
1070 944 *
1071 - * @param int $id
1072 - * @param array $values
945 + * @param int $id
946 + * @param array $values
1073 947 * @param string $update_type
1074 948 *
1075 - * @return bool $update
949 + * @return boolean $update
1076 950 */
1077 951 private static function before_update_entry( $id, &$values, $update_type ) {
1078 952 $update = true;
1079 953
@@ -1078,13 +952,13 @@
1078 952 $update = true;
1079 953
1080 954 global $frm_vars;
1081 955
1082 - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) {
956 + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
1083 957 $update = false;
1084 958 }
1085 959
1086 - if ( $update && $update_type !== 'xml' ) {
960 + if ( $update && $update_type != 'xml' ) {
1087 961 $values = apply_filters( 'frm_pre_update_entry', $values, $id );
1088 962 }
1089 963
1090 964 return $update;
@@ -1094,9 +968,9 @@
1094 968 * Package the entry data for updating
1095 969 *
1096 970 * @since 2.0.16
1097 971 *
1098 - * @param int $id
972 + * @param int $id
1099 973 * @param array $values
1100 974 *
1101 975 * @return array $new_values
1102 976 */
@@ -1107,9 +981,9 @@
1107 981 'name' => self::get_new_entry_name( $values ),
1108 982 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
1109 983 'is_draft' => self::get_is_draft_value( $values ),
1110 984 'updated_at' => current_time( 'mysql', 1 ),
1111 - 'updated_by' => $values['updated_by'] ?? get_current_user_id(),
985 + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
1112 986 );
1113 987
1114 988 if ( isset( $values['post_id'] ) ) {
1115 989 $new_values['post_id'] = (int) $values['post_id'];
@@ -1136,12 +1010,12 @@
1136 1010 * Perform some actions right after updating an entry
1137 1011 *
1138 1012 * @since 2.0.16
1139 1013 *
1140 - * @param bool|int $query_results
1141 - * @param int $id
1142 - * @param array $values
1143 - * @param array $new_values
1014 + * @param boolean|int $query_results
1015 + * @param int $id
1016 + * @param array $values
1017 + * @param array $new_values
1144 1018 */
1145 1019 private static function after_update_entry( $query_results, $id, $values, $new_values ) {
1146 1020 if ( $query_results ) {
1147 1021 self::clear_cache();
@@ -1169,9 +1043,9 @@
1169 1043 * @since 2.0.16
1170 1044 *
1171 1045 * @param array $values
1172 1046 *
1173 - * @return bool|int $entry_id
1047 + * @return int | boolean $entry_id
1174 1048 */
1175 1049 public static function create_entry_from_xml( $values ) {
1176 1050 $entry_id = self::create_entry( $values, 'xml' );
1177 1051
@@ -1183,12 +1057,12 @@
1183 1057 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
1184 1058 *
1185 1059 * @since 2.0.16
1186 1060 *
1187 - * @param int $id
1061 + * @param int $id
1188 1062 * @param array $values
1189 1063 *
1190 - * @return bool|int $updated
1064 + * @return int | boolean $updated
1191 1065 */
1192 1066 public static function update_entry_from_xml( $id, $values ) {
1193 1067 $updated = self::update_entry( $id, $values, 'xml' );
1194 1068
@@ -1203,22 +1077,6 @@
1203 1077 public static function get_id_by_key( $key ) {
1204 1078 $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
1205 1079
1206 1080 return (int) $entry_id;
1207 - }
1208 -
1209 - /**
1210 - * Get entries count.
1211 - *
1212 - * @since 6.8
1213 - *
1214 - * @return int|string
1215 - */
1216 - public static function get_entries_count() {
1217 - $args = array(
1218 - 'or' => 1,
1219 - 'parent_form_id' => null,
1220 - 'parent_form_id <' => 1,
1221 - );
1222 - return self::getRecordCount( $args );
1223 1081 }
1224 1082 }