PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +78 -50 6.36.13 View file →
@@ -9,9 +9,9 @@
9 9 * Create a new entry
10 10 *
11 11 * @param array $values
12 12 *
13 - * @return int | boolean $entry_id
13 + * @return bool|int $entry_id
14 14 */
15 15 public static function create( $values ) {
16 16 $entry_id = self::create_entry( $values, 'standard' );
17 17
@@ -20,18 +20,18 @@
20 20
21 21 /**
22 22 * Create a new entry with some differences depending on type
23 23 *
24 - * @param array $values
24 + * @param array $values
25 25 * @param string $type
26 26 *
27 - * @return int | boolean $entry_id
27 + * @return bool|int $entry_id
28 28 */
29 29 private static function create_entry( $values, $type ) {
30 30 $new_values = self::before_insert_entry_in_database( $values, $type );
31 31
32 32 // Don't check XML entries for duplicates
33 - if ( $type != 'xml' && self::is_duplicate( $new_values, $values ) ) {
33 + if ( $type !== 'xml' && self::is_duplicate( $new_values, $values ) ) {
34 34 return false;
35 35 }
36 36
37 37 $entry_id = self::continue_to_create_entry( $values, $new_values );
@@ -41,9 +41,9 @@
41 41
42 42 /**
43 43 * Check for duplicate entries created in the last minute
44 44 *
45 - * @return boolean
45 + * @return bool
46 46 */
47 47 public static function is_duplicate( $new_values, $values ) {
48 48 $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values );
49 49
@@ -51,9 +51,9 @@
51 51 return false;
52 52 }
53 53
54 54 $check_val = $new_values;
55 - $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 ) );
56 56
57 57 unset( $check_val['created_at'], $check_val['updated_at'], $check_val['is_draft'], $check_val['id'], $check_val['item_key'] );
58 58
59 59 if ( $new_values['item_key'] == $new_values['name'] ) {
@@ -106,12 +106,11 @@
106 106 continue;
107 107 }
108 108
109 109 $diff = array_diff_assoc( $field_metas, $new_meta );
110 - foreach ( $diff as $field_id => $meta_value ) {
110 + foreach ( $diff as $meta_value ) {
111 111 if ( ! empty( $meta_value ) ) {
112 112 $is_duplicate = false;
113 - continue;
114 113 }
115 114 }
116 115
117 116 if ( $is_duplicate ) {
@@ -116,9 +115,9 @@
116 115
117 116 if ( $is_duplicate ) {
118 117 break;
119 118 }
120 - }
119 + }//end foreach
121 120
122 121 $frm_vars['checking_duplicates'] = false;
123 122
124 123 return $is_duplicate;
@@ -150,9 +149,9 @@
150 149 *
151 150 * @since 2.0.23
152 151 *
153 152 * @param array $values
154 - * @param int $duplicate_entry_time
153 + * @param int $duplicate_entry_time
155 154 *
156 155 * @return bool
157 156 */
158 157 private static function is_duplicate_check_needed( $values, $duplicate_entry_time ) {
@@ -212,12 +211,12 @@
212 211
213 212 /**
214 213 * Update an entry (not via XML)
215 214 *
216 - * @param int $id
215 + * @param int $id
217 216 * @param array $values
218 217 *
219 - * @return boolean|int $update_results
218 + * @return bool|int $update_results
220 219 */
221 220 public static function update( $id, $values ) {
222 221 $update_results = self::update_entry( $id, $values, 'standard' );
223 222
@@ -228,12 +227,12 @@
228 227 * Update an entry with some differences depending on the update type
229 228 *
230 229 * @since 2.0.16
231 230 *
232 - * @param int $id
231 + * @param int $id
233 232 * @param array $values
234 233 *
235 - * @return boolean|int $query_results
234 + * @return bool|int $query_results
236 235 */
237 236 private static function update_entry( $id, $values, $update_type ) {
238 237 global $wpdb;
239 238
@@ -253,9 +252,9 @@
253 252
254 253 /**
255 254 * Delete an entry.
256 255 *
257 - * @param string|int $id
256 + * @param int|string $id
258 257 * @return bool True on success, false if nothing was deleted.
259 258 */
260 259 public static function destroy( $id ) {
261 260 global $wpdb;
@@ -260,9 +259,10 @@
260 259 public static function destroy( $id ) {
261 260 global $wpdb;
262 261 $id = (int) $id;
263 262
264 - $entry = self::getOne( $id, true ); // Item meta is required for conditional logic in actions with 'delete' events.
263 + // Item meta is required for conditional logic in actions with 'delete' events.
264 + $entry = self::getOne( $id, true );
265 265 if ( ! $entry ) {
266 266 $result = false;
267 267 return $result;
268 268 }
@@ -335,11 +335,12 @@
335 335
336 336 /**
337 337 * If $entry is numeric, get the entry object
338 338 *
339 - * @param int|object $entry by reference
339 + * @since 2.0.9
340 340 *
341 - * @since 2.0.9
341 + * @param int|object $entry By reference.
342 + * @return void
342 343 */
343 344 public static function maybe_get_entry( &$entry ) {
344 345 if ( $entry && is_numeric( $entry ) ) {
345 346 $entry = self::getOne( $entry );
@@ -353,9 +354,9 @@
353 354
354 355 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
355 356 LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
356 357
357 - $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
358 + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
358 359 $query_args = array( $id );
359 360 $query = $wpdb->prepare( $query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
360 361
361 362 if ( ! $meta ) {
@@ -387,9 +388,10 @@
387 388 return;
388 389 }
389 390
390 391 FrmAppHelper::unserialize_or_decode( $entry->description );
391 - $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output.
392 + // TODO: Remove slashes on input only, not output.
393 + $entry = wp_unslash( $entry );
392 394 }
393 395
394 396 /**
395 397 * @since 4.02.03
@@ -466,9 +468,9 @@
466 468 $where = array( 'item_key' => $id );
467 469 }
468 470 $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
469 471
470 - return ( $id && $id > 0 );
472 + return $id && $id > 0;
471 473 }
472 474
473 475 public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
474 476 global $wpdb;
@@ -483,9 +485,9 @@
483 485 $table = $wpdb->prefix . 'frm_items it ';
484 486
485 487 if ( $inc_form ) {
486 488 $fields = 'it.*, fr.name as form_name,fr.form_key as form_key';
487 - $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
489 + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
488 490 }
489 491
490 492 if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
491 493 $fields .= self::sort_by_field( $order_matches[1] );
@@ -498,9 +500,9 @@
498 500 $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
499 501 unset( $query );
500 502
501 503 FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
502 - }
504 + }//end if
503 505
504 506 if ( ! $meta || ! $entries ) {
505 507 self::prepare_entries( $entries );
506 508 return $entries;
@@ -577,13 +579,14 @@
577 579 }
578 580
579 581 // Pagination Methods
580 582 /**
581 - * @param int|array|string If int, use the form id.
583 + * @param array|int|string $where If int, use the form id.
584 + * @return int|string
582 585 */
583 586 public static function getRecordCount( $where = '' ) {
584 587 global $wpdb;
585 - $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
588 + $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
586 589
587 590 if ( is_numeric( $where ) ) {
588 591 $table_join = 'frm_items';
589 592 $where = array( 'form_id' => $where );
@@ -599,8 +602,12 @@
599 602
600 603 return $count;
601 604 }
602 605
606 + /**
607 + * @param int|string $p_size
608 + * @return int
609 + */
603 610 public static function getPageCount( $p_size, $where = '' ) {
604 611 $p_size = (int) $p_size;
605 612 $count = 1;
606 613 if ( $p_size ) {
@@ -617,9 +624,9 @@
617 624 * Prepare the data before inserting it into the database
618 625 *
619 626 * @since 2.0.16
620 627 *
621 - * @param array $values
628 + * @param array $values
622 629 * @param string $type
623 630 *
624 631 * @return array $new_values
625 632 */
@@ -626,9 +633,9 @@
626 633 private static function before_insert_entry_in_database( &$values, $type ) {
627 634
628 635 self::sanitize_entry_post( $values );
629 636
630 - if ( $type != 'xml' ) {
637 + if ( $type !== 'xml' ) {
631 638 $values = apply_filters( 'frm_pre_create_entry', $values );
632 639 }
633 640
634 641 $new_values = self::package_entry_data( $values );
@@ -643,9 +650,9 @@
643 650 *
644 651 * @param array $values
645 652 * @param array $new_values
646 653 *
647 - * @return boolean|int $entry_id
654 + * @return bool|int $entry_id
648 655 */
649 656 private static function continue_to_create_entry( $values, $new_values ) {
650 657 $entry_id = self::insert_entry_into_database( $new_values );
651 658 if ( ! $entry_id ) {
@@ -661,9 +668,9 @@
661 668 * Sanitize the POST values before we use them
662 669 *
663 670 * @since 2.0
664 671 *
665 - * @param array $values The POST values by reference
672 + * @param array $values The POST values by reference.
666 673 */
667 674 public static function sanitize_entry_post( &$values ) {
668 675 $sanitize_method = array(
669 676 'form_id' => 'absint',
@@ -754,9 +761,13 @@
754 761 *
755 762 * @return int
756 763 */
757 764 private static function get_is_draft_value( $values ) {
758 - return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
765 + if ( isset( $values['frm_saving_draft'] ) && FrmEntriesHelper::DRAFT_ENTRY_STATUS === (int) $values['frm_saving_draft'] ) {
766 + return FrmEntriesHelper::DRAFT_ENTRY_STATUS;
767 + }
768 +
769 + return isset( $values['is_draft'] ) ? absint( $values['is_draft'] ) : FrmEntriesHelper::SUBMITTED_ENTRY_STATUS;
759 770 }
760 771
761 772 /**
762 773 * Get the created_at value for a new entry
@@ -799,9 +810,9 @@
799 810 *
800 811 * @return string
801 812 */
802 813 private static function get_entry_description( $values ) {
803 - if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
814 + if ( ! empty( $values['description'] ) ) {
804 815 $description = FrmAppHelper::maybe_json_encode( $values['description'] );
805 816 } else {
806 817 $description = json_encode(
807 818 array(
@@ -840,9 +851,9 @@
840 851 * @since 2.0.16
841 852 *
842 853 * @param array $new_values
843 854 *
844 - * @return int | boolean $entry_id
855 + * @return bool|int $entry_id
845 856 */
846 857 private static function insert_entry_into_database( $new_values ) {
847 858 global $wpdb;
848 859
@@ -879,9 +890,9 @@
879 890 *
880 891 * @since 2.0.16
881 892 *
882 893 * @param array $values
883 - * @param int $entry_id
894 + * @param int $entry_id
884 895 * @return void
885 896 */
886 897 private static function maybe_add_entry_metas( $values, $entry_id ) {
887 898 if ( isset( $values['item_meta'] ) ) {
@@ -909,14 +920,15 @@
909 920 * Trigger frm_after_create_entry hooks
910 921 *
911 922 * @since 2.0.16
912 923 *
913 - * @param int $entry_id
924 + * @param int $entry_id
925 + * @param array $values
914 926 * @param array $new_values
915 927 */
916 928 private static function after_entry_created_actions( $entry_id, $values, $new_values ) {
917 - // this is a child entry
918 - $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
929 + // This is a child entry.
930 + $is_child = isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
919 931
920 932 do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
921 933 do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
922 934 }
@@ -927,9 +939,9 @@
927 939 * @since 2.0.16
928 940 *
929 941 * @param array $values
930 942 * @param array $new_values
931 - * @param int $entry_id
943 + * @param int $entry_id
932 944 */
933 945 private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
934 946
935 947 self::add_new_entry_to_frm_vars( $entry_id );
@@ -945,13 +957,13 @@
945 957 * Perform some actions right before updating an entry
946 958 *
947 959 * @since 2.0.16
948 960 *
949 - * @param int $id
950 - * @param array $values
961 + * @param int $id
962 + * @param array $values
951 963 * @param string $update_type
952 964 *
953 - * @return boolean $update
965 + * @return bool $update
954 966 */
955 967 private static function before_update_entry( $id, &$values, $update_type ) {
956 968 $update = true;
957 969
@@ -956,13 +968,13 @@
956 968 $update = true;
957 969
958 970 global $frm_vars;
959 971
960 - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
972 + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) {
961 973 $update = false;
962 974 }
963 975
964 - if ( $update && $update_type != 'xml' ) {
976 + if ( $update && $update_type !== 'xml' ) {
965 977 $values = apply_filters( 'frm_pre_update_entry', $values, $id );
966 978 }
967 979
968 980 return $update;
@@ -972,9 +984,9 @@
972 984 * Package the entry data for updating
973 985 *
974 986 * @since 2.0.16
975 987 *
976 - * @param int $id
988 + * @param int $id
977 989 * @param array $values
978 990 *
979 991 * @return array $new_values
980 992 */
@@ -1014,12 +1026,12 @@
1014 1026 * Perform some actions right after updating an entry
1015 1027 *
1016 1028 * @since 2.0.16
1017 1029 *
1018 - * @param boolean|int $query_results
1019 - * @param int $id
1020 - * @param array $values
1021 - * @param array $new_values
1030 + * @param bool|int $query_results
1031 + * @param int $id
1032 + * @param array $values
1033 + * @param array $new_values
1022 1034 */
1023 1035 private static function after_update_entry( $query_results, $id, $values, $new_values ) {
1024 1036 if ( $query_results ) {
1025 1037 self::clear_cache();
@@ -1047,9 +1059,9 @@
1047 1059 * @since 2.0.16
1048 1060 *
1049 1061 * @param array $values
1050 1062 *
1051 - * @return int | boolean $entry_id
1063 + * @return bool|int $entry_id
1052 1064 */
1053 1065 public static function create_entry_from_xml( $values ) {
1054 1066 $entry_id = self::create_entry( $values, 'xml' );
1055 1067
@@ -1061,12 +1073,12 @@
1061 1073 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
1062 1074 *
1063 1075 * @since 2.0.16
1064 1076 *
1065 - * @param int $id
1077 + * @param int $id
1066 1078 * @param array $values
1067 1079 *
1068 - * @return int | boolean $updated
1080 + * @return bool|int $updated
1069 1081 */
1070 1082 public static function update_entry_from_xml( $id, $values ) {
1071 1083 $updated = self::update_entry( $id, $values, 'xml' );
1072 1084
@@ -1081,6 +1093,22 @@
1081 1093 public static function get_id_by_key( $key ) {
1082 1094 $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
1083 1095
1084 1096 return (int) $entry_id;
1097 + }
1098 +
1099 + /**
1100 + * Get entries count.
1101 + *
1102 + * @since 6.8
1103 + *
1104 + * @return int|string
1105 + */
1106 + public static function get_entries_count() {
1107 + $args = array(
1108 + 'or' => 1,
1109 + 'parent_form_id' => null,
1110 + 'parent_form_id <' => 1,
1111 + );
1112 + return self::getRecordCount( $args );
1085 1113 }
1086 1114 }