PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.1
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 +60 -224 6.255.1 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
@@ -337,31 +250,19 @@
337 250
338 251 return $query_results;
339 252 }
340 253
341 - /**
342 - * Delete an entry.
343 - *
344 - * @param int|string $id
345 - * @return bool True on success, false if nothing was deleted.
346 - */
347 254 public static function destroy( $id ) {
348 255 global $wpdb;
349 256 $id = (int) $id;
350 257
351 - // Item meta is required for conditional logic in actions with 'delete' events.
352 - $entry = self::getOne( $id, true );
258 + $entry = self::getOne( $id );
353 259 if ( ! $entry ) {
354 260 $result = false;
261 +
355 262 return $result;
356 263 }
357 264
358 - /**
359 - * Trigger an action to run custom logic before the entry is deleted.
360 - *
361 - * @param int $id The id of the entry that was destroyed.
362 - * @param stdClass $entry The entry object.
363 - */
364 265 do_action( 'frm_before_destroy_entry', $id, $entry );
365 266
366 267 $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_item_metas WHERE item_id=%d', $id ) );
367 268 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
@@ -367,19 +268,8 @@
367 268 $result = $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . 'frm_items WHERE id=%d', $id ) );
368 269
369 270 self::clear_cache();
370 271
371 - /**
372 - * Trigger an action to run custom logic after the entry is deleted.
373 - * Use this hook if you need to update caching after an entry is deleted.
374 - *
375 - * @since 5.4.1
376 - *
377 - * @param int $id The id of the entry that was destroyed.
378 - * @param stdClass $entry The entry object.
379 - */
380 - do_action( 'frm_after_destroy_entry', $id, $entry );
381 -
382 272 return $result;
383 273 }
384 274
385 275 public static function update_form( $id, $value, $form_id ) {
@@ -412,9 +302,9 @@
412 302 *
413 303 * @since 2.0.11
414 304 */
415 305 public static function get_new_entry_name( $values, $default = '' ) {
416 - $name = $values['item_name'] ?? $values['name'] ?? $default;
306 + $name = isset( $values['item_name'] ) ? $values['item_name'] : ( isset( $values['name'] ) ? $values['name'] : $default );
417 307 if ( is_array( $name ) ) {
418 308 $name = reset( $name );
419 309 }
420 310
@@ -423,12 +313,11 @@
423 313
424 314 /**
425 315 * If $entry is numeric, get the entry object
426 316 *
317 + * @param int|object $entry by reference
318 + *
427 319 * @since 2.0.9
428 - *
429 - * @param int|object $entry By reference.
430 - * @return void
431 320 */
432 321 public static function maybe_get_entry( &$entry ) {
433 322 if ( $entry && is_numeric( $entry ) ) {
434 323 $entry = self::getOne( $entry );
@@ -442,9 +331,9 @@
442 331
443 332 $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it
444 333 LEFT OUTER JOIN {$wpdb->prefix}frm_forms fr ON it.form_id=fr.id WHERE ";
445 334
446 - $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
335 + $query .= is_numeric( $id ) ? 'it.id=%d' : 'it.item_key=%s';
447 336 $query_args = array( $id );
448 337 $query = $wpdb->prepare( $query, $query_args ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
449 338
450 339 if ( ! $meta ) {
@@ -476,10 +365,9 @@
476 365 return;
477 366 }
478 367
479 368 FrmAppHelper::unserialize_or_decode( $entry->description );
480 - // TODO: Remove slashes on input only, not output.
481 - $entry = wp_unslash( $entry );
369 + $entry = wp_unslash( $entry ); // TODO: Remove slashes on input only, not output.
482 370 }
483 371
484 372 /**
485 373 * @since 4.02.03
@@ -504,9 +392,9 @@
504 392 array(
505 393 'item_id' => $entry->id,
506 394 'field_id !' => 0,
507 395 ),
508 - 'field_id, meta_value, field_key, item_id, f.type'
396 + 'field_id, meta_value, field_key, item_id'
509 397 );
510 398
511 399 $entry->metas = array();
512 400
@@ -511,11 +399,10 @@
511 399 $entry->metas = array();
512 400
513 401 $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) );
514 402 foreach ( $metas as $meta_val ) {
515 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
516 -
517 403 if ( $meta_val->item_id == $entry->id ) {
404 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
518 405 $entry->metas[ $meta_val->field_id ] = $meta_val->meta_value;
519 406 if ( $include_key ) {
520 407 $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ];
521 408 }
@@ -526,8 +413,9 @@
526 413 if ( ! isset( $entry->metas[ $meta_val->field_id ] ) ) {
527 414 $entry->metas[ $meta_val->field_id ] = array();
528 415 }
529 416
417 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
530 418 $entry->metas[ $meta_val->field_id ][] = $meta_val->meta_value;
531 419
532 420 unset( $meta_val );
533 421 }
@@ -556,9 +444,9 @@
556 444 $where = array( 'item_key' => $id );
557 445 }
558 446 $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where );
559 447
560 - return $id && $id > 0;
448 + return ( $id && $id > 0 );
561 449 }
562 450
563 451 public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) {
564 452 global $wpdb;
@@ -568,14 +456,14 @@
568 456 $cache_key = FrmAppHelper::maybe_json_encode( $where ) . $order_by . $limit . $inc_form;
569 457 $entries = wp_cache_get( $cache_key, 'frm_entry' );
570 458
571 459 if ( false === $entries ) {
572 - $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';
460 + $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';
573 461 $table = $wpdb->prefix . 'frm_items it ';
574 462
575 463 if ( $inc_form ) {
576 464 $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 ';
465 + $table .= 'LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id ';
578 466 }
579 467
580 468 if ( preg_match( '/ meta_([0-9]+)/', $order_by, $order_matches ) ) {
581 469 $fields .= self::sort_by_field( $order_matches[1] );
@@ -588,9 +476,9 @@
588 476 $entries = $wpdb->get_results( $query, OBJECT_K ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
589 477 unset( $query );
590 478
591 479 FrmDb::set_cache( $cache_key, $entries, 'frm_entry' );
592 - }//end if
480 + }
593 481
594 482 if ( ! $meta || ! $entries ) {
595 483 self::prepare_entries( $entries );
596 484 return $entries;
@@ -607,13 +495,9 @@
607 495 } else {
608 496 $meta_where['item_id'] = array_keys( $entries );
609 497 }
610 498
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 - );
499 + $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 500
617 501 unset( $meta_where );
618 502
619 503 if ( ! $metas ) {
@@ -629,9 +513,9 @@
629 513 if ( ! isset( $entries[ $meta_val->item_id ]->metas ) ) {
630 514 $entries[ $meta_val->item_id ]->metas = array();
631 515 }
632 516
633 - FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type );
517 + FrmAppHelper::unserialize_or_decode( $meta_val->meta_value );
634 518 $entries[ $meta_val->item_id ]->metas[ $meta_val->field_id ] = $meta_val->meta_value;
635 519 unset( $m_key, $meta_val );
636 520 }
637 521
@@ -667,14 +551,13 @@
667 551 }
668 552
669 553 // Pagination Methods
670 554 /**
671 - * @param array|int|string $where If int, use the form id.
672 - * @return int|string
555 + * @param int|array|string If int, use the form id.
673 556 */
674 557 public static function getRecordCount( $where = '' ) {
675 558 global $wpdb;
676 - $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
559 + $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id';
677 560
678 561 if ( is_numeric( $where ) ) {
679 562 $table_join = 'frm_items';
680 563 $where = array( 'form_id' => $where );
@@ -690,12 +573,8 @@
690 573
691 574 return $count;
692 575 }
693 576
694 - /**
695 - * @param int|string $p_size
696 - * @return int
697 - */
698 577 public static function getPageCount( $p_size, $where = '' ) {
699 578 $p_size = (int) $p_size;
700 579 $count = 1;
701 580 if ( $p_size ) {
@@ -712,9 +591,9 @@
712 591 * Prepare the data before inserting it into the database
713 592 *
714 593 * @since 2.0.16
715 594 *
716 - * @param array $values
595 + * @param array $values
717 596 * @param string $type
718 597 *
719 598 * @return array $new_values
720 599 */
@@ -721,9 +600,9 @@
721 600 private static function before_insert_entry_in_database( &$values, $type ) {
722 601
723 602 self::sanitize_entry_post( $values );
724 603
725 - if ( $type !== 'xml' ) {
604 + if ( $type != 'xml' ) {
726 605 $values = apply_filters( 'frm_pre_create_entry', $values );
727 606 }
728 607
729 608 $new_values = self::package_entry_data( $values );
@@ -738,9 +617,9 @@
738 617 *
739 618 * @param array $values
740 619 * @param array $new_values
741 620 *
742 - * @return bool|int $entry_id
621 + * @return boolean|int $entry_id
743 622 */
744 623 private static function continue_to_create_entry( $values, $new_values ) {
745 624 $entry_id = self::insert_entry_into_database( $new_values );
746 625 if ( ! $entry_id ) {
@@ -756,9 +635,9 @@
756 635 * Sanitize the POST values before we use them
757 636 *
758 637 * @since 2.0
759 638 *
760 - * @param array $values The POST values by reference.
639 + * @param array $values The POST values by reference
761 640 */
762 641 public static function sanitize_entry_post( &$values ) {
763 642 $sanitize_method = array(
764 643 'form_id' => 'absint',
@@ -807,15 +686,15 @@
807 686 'description' => self::get_entry_description( $values ),
808 687 'user_id' => self::get_entry_user_id( $values ),
809 688 );
810 689
811 - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id'];
690 + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id'];
812 691
813 692 return $new_values;
814 693 }
815 694
816 695 private static function get_entry_value( $values, $name, $default ) {
817 - return $values[ $name ] ?? $default;
696 + return isset( $values[ $name ] ) ? $values[ $name ] : $default;
818 697 }
819 698
820 699 /**
821 700 * Get the ip for a new entry.
@@ -849,13 +728,9 @@
849 728 *
850 729 * @return int
851 730 */
852 731 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;
732 + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0;
858 733 }
859 734
860 735 /**
861 736 * Get the created_at value for a new entry
@@ -898,9 +773,9 @@
898 773 *
899 774 * @return string
900 775 */
901 776 private static function get_entry_description( $values ) {
902 - if ( ! empty( $values['description'] ) ) {
777 + if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) {
903 778 $description = FrmAppHelper::maybe_json_encode( $values['description'] );
904 779 } else {
905 780 $description = json_encode(
906 781 array(
@@ -939,9 +814,9 @@
939 814 * @since 2.0.16
940 815 *
941 816 * @param array $new_values
942 817 *
943 - * @return bool|int $entry_id
818 + * @return int | boolean $entry_id
944 819 */
945 820 private static function insert_entry_into_database( $new_values ) {
946 821 global $wpdb;
947 822
@@ -978,41 +853,19 @@
978 853 *
979 854 * @since 2.0.16
980 855 *
981 856 * @param array $values
982 - * @param int $entry_id
857 + * @param int $entry_id
983 858 * @return void
984 859 */
985 860 private static function maybe_add_entry_metas( $values, $entry_id ) {
986 861 if ( isset( $values['item_meta'] ) ) {
987 862 FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] );
988 - self::maybe_add_unique_id_meta( $values, $entry_id );
989 863 }
990 864 self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id );
991 865 }
992 866
993 867 /**
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 868 * @since 5.0.15
1016 869 *
1017 870 * @param int $form_id
1018 871 * @param int $entry_id
@@ -1030,15 +883,14 @@
1030 883 * Trigger frm_after_create_entry hooks
1031 884 *
1032 885 * @since 2.0.16
1033 886 *
1034 - * @param int $entry_id
1035 - * @param array $values
887 + * @param int $entry_id
1036 888 * @param array $new_values
1037 889 */
1038 890 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' );
891 + // this is a child entry
892 + $is_child = isset( $values['parent_form_id'] ) && isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' );
1041 893
1042 894 do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) );
1043 895 do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) );
1044 896 }
@@ -1049,9 +901,9 @@
1049 901 * @since 2.0.16
1050 902 *
1051 903 * @param array $values
1052 904 * @param array $new_values
1053 - * @param int $entry_id
905 + * @param int $entry_id
1054 906 */
1055 907 private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) {
1056 908
1057 909 self::add_new_entry_to_frm_vars( $entry_id );
@@ -1067,13 +919,13 @@
1067 919 * Perform some actions right before updating an entry
1068 920 *
1069 921 * @since 2.0.16
1070 922 *
1071 - * @param int $id
1072 - * @param array $values
923 + * @param int $id
924 + * @param array $values
1073 925 * @param string $update_type
1074 926 *
1075 - * @return bool $update
927 + * @return boolean $update
1076 928 */
1077 929 private static function before_update_entry( $id, &$values, $update_type ) {
1078 930 $update = true;
1079 931
@@ -1078,13 +930,13 @@
1078 930 $update = true;
1079 931
1080 932 global $frm_vars;
1081 933
1082 - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) {
934 + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) {
1083 935 $update = false;
1084 936 }
1085 937
1086 - if ( $update && $update_type !== 'xml' ) {
938 + if ( $update && $update_type != 'xml' ) {
1087 939 $values = apply_filters( 'frm_pre_update_entry', $values, $id );
1088 940 }
1089 941
1090 942 return $update;
@@ -1094,9 +946,9 @@
1094 946 * Package the entry data for updating
1095 947 *
1096 948 * @since 2.0.16
1097 949 *
1098 - * @param int $id
950 + * @param int $id
1099 951 * @param array $values
1100 952 *
1101 953 * @return array $new_values
1102 954 */
@@ -1107,9 +959,9 @@
1107 959 'name' => self::get_new_entry_name( $values ),
1108 960 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ),
1109 961 'is_draft' => self::get_is_draft_value( $values ),
1110 962 'updated_at' => current_time( 'mysql', 1 ),
1111 - 'updated_by' => $values['updated_by'] ?? get_current_user_id(),
963 + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(),
1112 964 );
1113 965
1114 966 if ( isset( $values['post_id'] ) ) {
1115 967 $new_values['post_id'] = (int) $values['post_id'];
@@ -1136,12 +988,12 @@
1136 988 * Perform some actions right after updating an entry
1137 989 *
1138 990 * @since 2.0.16
1139 991 *
1140 - * @param bool|int $query_results
1141 - * @param int $id
1142 - * @param array $values
1143 - * @param array $new_values
992 + * @param boolean|int $query_results
993 + * @param int $id
994 + * @param array $values
995 + * @param array $new_values
1144 996 */
1145 997 private static function after_update_entry( $query_results, $id, $values, $new_values ) {
1146 998 if ( $query_results ) {
1147 999 self::clear_cache();
@@ -1169,9 +1021,9 @@
1169 1021 * @since 2.0.16
1170 1022 *
1171 1023 * @param array $values
1172 1024 *
1173 - * @return bool|int $entry_id
1025 + * @return int | boolean $entry_id
1174 1026 */
1175 1027 public static function create_entry_from_xml( $values ) {
1176 1028 $entry_id = self::create_entry( $values, 'xml' );
1177 1029
@@ -1183,12 +1035,12 @@
1183 1035 * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals)
1184 1036 *
1185 1037 * @since 2.0.16
1186 1038 *
1187 - * @param int $id
1039 + * @param int $id
1188 1040 * @param array $values
1189 1041 *
1190 - * @return bool|int $updated
1042 + * @return int | boolean $updated
1191 1043 */
1192 1044 public static function update_entry_from_xml( $id, $values ) {
1193 1045 $updated = self::update_entry( $id, $values, 'xml' );
1194 1046
@@ -1203,22 +1055,6 @@
1203 1055 public static function get_id_by_key( $key ) {
1204 1056 $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) );
1205 1057
1206 1058 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 1059 }
1224 1060 }