| @@ -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 |
| @@ -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; |
| @@ -667,14 +577,13 @@ | ||
| 667 | 577 | } |
| 668 | 578 | |
| 669 | 579 | // Pagination Methods |
| 670 | 580 | /** |
| 671 | - * @param array|int|string $where If int, use the form id. | |
| 672 | - * @return int|string | |
| 581 | + * @param int|array|string If int, use the form id. | |
| 673 | 582 | */ |
| 674 | 583 | public static function getRecordCount( $where = '' ) { |
| 675 | 584 | global $wpdb; |
| 676 | - $table_join = $wpdb->prefix . 'frm_items it JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; | |
| 585 | + $table_join = $wpdb->prefix . 'frm_items it LEFT OUTER JOIN ' . $wpdb->prefix . 'frm_forms fr ON it.form_id=fr.id'; | |
| 677 | 586 | |
| 678 | 587 | if ( is_numeric( $where ) ) { |
| 679 | 588 | $table_join = 'frm_items'; |
| 680 | 589 | $where = array( 'form_id' => $where ); |
| @@ -690,12 +599,8 @@ | ||
| 690 | 599 | |
| 691 | 600 | return $count; |
| 692 | 601 | } |
| 693 | 602 | |
| 694 | - /** | |
| 695 | - * @param int|string $p_size | |
| 696 | - * @return int | |
| 697 | - */ | |
| 698 | 603 | public static function getPageCount( $p_size, $where = '' ) { |
| 699 | 604 | $p_size = (int) $p_size; |
| 700 | 605 | $count = 1; |
| 701 | 606 | if ( $p_size ) { |
| @@ -712,9 +617,9 @@ | ||
| 712 | 617 | * Prepare the data before inserting it into the database |
| 713 | 618 | * |
| 714 | 619 | * @since 2.0.16 |
| 715 | 620 | * |
| 716 | - * @param array $values | |
| 621 | + * @param array $values | |
| 717 | 622 | * @param string $type |
| 718 | 623 | * |
| 719 | 624 | * @return array $new_values |
| 720 | 625 | */ |
| @@ -721,9 +626,9 @@ | ||
| 721 | 626 | private static function before_insert_entry_in_database( &$values, $type ) { |
| 722 | 627 | |
| 723 | 628 | self::sanitize_entry_post( $values ); |
| 724 | 629 | |
| 725 | - if ( $type !== 'xml' ) { | |
| 630 | + if ( $type != 'xml' ) { | |
| 726 | 631 | $values = apply_filters( 'frm_pre_create_entry', $values ); |
| 727 | 632 | } |
| 728 | 633 | |
| 729 | 634 | $new_values = self::package_entry_data( $values ); |
| @@ -738,9 +643,9 @@ | ||
| 738 | 643 | * |
| 739 | 644 | * @param array $values |
| 740 | 645 | * @param array $new_values |
| 741 | 646 | * |
| 742 | - * @return bool|int $entry_id | |
| 647 | + * @return boolean|int $entry_id | |
| 743 | 648 | */ |
| 744 | 649 | private static function continue_to_create_entry( $values, $new_values ) { |
| 745 | 650 | $entry_id = self::insert_entry_into_database( $new_values ); |
| 746 | 651 | if ( ! $entry_id ) { |
| @@ -756,9 +661,9 @@ | ||
| 756 | 661 | * Sanitize the POST values before we use them |
| 757 | 662 | * |
| 758 | 663 | * @since 2.0 |
| 759 | 664 | * |
| 760 | - * @param array $values The POST values by reference. | |
| 665 | + * @param array $values The POST values by reference | |
| 761 | 666 | */ |
| 762 | 667 | public static function sanitize_entry_post( &$values ) { |
| 763 | 668 | $sanitize_method = array( |
| 764 | 669 | 'form_id' => 'absint', |
| @@ -807,15 +712,15 @@ | ||
| 807 | 712 | 'description' => self::get_entry_description( $values ), |
| 808 | 713 | 'user_id' => self::get_entry_user_id( $values ), |
| 809 | 714 | ); |
| 810 | 715 | |
| 811 | - $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']; | |
| 812 | 717 | |
| 813 | 718 | return $new_values; |
| 814 | 719 | } |
| 815 | 720 | |
| 816 | 721 | private static function get_entry_value( $values, $name, $default ) { |
| 817 | - return $values[ $name ] ?? $default; | |
| 722 | + return isset( $values[ $name ] ) ? $values[ $name ] : $default; | |
| 818 | 723 | } |
| 819 | 724 | |
| 820 | 725 | /** |
| 821 | 726 | * Get the ip for a new entry. |
| @@ -849,13 +754,9 @@ | ||
| 849 | 754 | * |
| 850 | 755 | * @return int |
| 851 | 756 | */ |
| 852 | 757 | 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; | |
| 758 | + return ( ( isset( $values['frm_saving_draft'] ) && $values['frm_saving_draft'] == 1 ) || ( isset( $values['is_draft'] ) && $values['is_draft'] == 1 ) ) ? 1 : 0; | |
| 858 | 759 | } |
| 859 | 760 | |
| 860 | 761 | /** |
| 861 | 762 | * Get the created_at value for a new entry |
| @@ -898,9 +799,9 @@ | ||
| 898 | 799 | * |
| 899 | 800 | * @return string |
| 900 | 801 | */ |
| 901 | 802 | private static function get_entry_description( $values ) { |
| 902 | - if ( ! empty( $values['description'] ) ) { | |
| 803 | + if ( isset( $values['description'] ) && ! empty( $values['description'] ) ) { | |
| 903 | 804 | $description = FrmAppHelper::maybe_json_encode( $values['description'] ); |
| 904 | 805 | } else { |
| 905 | 806 | $description = json_encode( |
| 906 | 807 | array( |
| @@ -939,9 +840,9 @@ | ||
| 939 | 840 | * @since 2.0.16 |
| 940 | 841 | * |
| 941 | 842 | * @param array $new_values |
| 942 | 843 | * |
| 943 | - * @return bool|int $entry_id | |
| 844 | + * @return int | boolean $entry_id | |
| 944 | 845 | */ |
| 945 | 846 | private static function insert_entry_into_database( $new_values ) { |
| 946 | 847 | global $wpdb; |
| 947 | 848 | |
| @@ -978,41 +879,19 @@ | ||
| 978 | 879 | * |
| 979 | 880 | * @since 2.0.16 |
| 980 | 881 | * |
| 981 | 882 | * @param array $values |
| 982 | - * @param int $entry_id | |
| 883 | + * @param int $entry_id | |
| 983 | 884 | * @return void |
| 984 | 885 | */ |
| 985 | 886 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 986 | 887 | if ( isset( $values['item_meta'] ) ) { |
| 987 | 888 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
| 988 | - self::maybe_add_unique_id_meta( $values, $entry_id ); | |
| 989 | 889 | } |
| 990 | 890 | self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id ); |
| 991 | 891 | } |
| 992 | 892 | |
| 993 | 893 | /** |
| 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 | 894 | * @since 5.0.15 |
| 1016 | 895 | * |
| 1017 | 896 | * @param int $form_id |
| 1018 | 897 | * @param int $entry_id |
| @@ -1030,15 +909,14 @@ | ||
| 1030 | 909 | * Trigger frm_after_create_entry hooks |
| 1031 | 910 | * |
| 1032 | 911 | * @since 2.0.16 |
| 1033 | 912 | * |
| 1034 | - * @param int $entry_id | |
| 1035 | - * @param array $values | |
| 913 | + * @param int $entry_id | |
| 1036 | 914 | * @param array $new_values |
| 1037 | 915 | */ |
| 1038 | 916 | 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' ); | |
| 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' ); | |
| 1041 | 919 | |
| 1042 | 920 | do_action( 'frm_after_create_entry', $entry_id, $new_values['form_id'], compact( 'is_child' ) ); |
| 1043 | 921 | do_action( 'frm_after_create_entry_' . $new_values['form_id'], $entry_id, compact( 'is_child' ) ); |
| 1044 | 922 | } |
| @@ -1049,9 +927,9 @@ | ||
| 1049 | 927 | * @since 2.0.16 |
| 1050 | 928 | * |
| 1051 | 929 | * @param array $values |
| 1052 | 930 | * @param array $new_values |
| 1053 | - * @param int $entry_id | |
| 931 | + * @param int $entry_id | |
| 1054 | 932 | */ |
| 1055 | 933 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 1056 | 934 | |
| 1057 | 935 | self::add_new_entry_to_frm_vars( $entry_id ); |
| @@ -1067,13 +945,13 @@ | ||
| 1067 | 945 | * Perform some actions right before updating an entry |
| 1068 | 946 | * |
| 1069 | 947 | * @since 2.0.16 |
| 1070 | 948 | * |
| 1071 | - * @param int $id | |
| 1072 | - * @param array $values | |
| 949 | + * @param int $id | |
| 950 | + * @param array $values | |
| 1073 | 951 | * @param string $update_type |
| 1074 | 952 | * |
| 1075 | - * @return bool $update | |
| 953 | + * @return boolean $update | |
| 1076 | 954 | */ |
| 1077 | 955 | private static function before_update_entry( $id, &$values, $update_type ) { |
| 1078 | 956 | $update = true; |
| 1079 | 957 | |
| @@ -1078,13 +956,13 @@ | ||
| 1078 | 956 | $update = true; |
| 1079 | 957 | |
| 1080 | 958 | global $frm_vars; |
| 1081 | 959 | |
| 1082 | - if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, $frm_vars['saved_entries'] ) ) { | |
| 960 | + if ( isset( $frm_vars['saved_entries'] ) && is_array( $frm_vars['saved_entries'] ) && in_array( (int) $id, (array) $frm_vars['saved_entries'] ) ) { | |
| 1083 | 961 | $update = false; |
| 1084 | 962 | } |
| 1085 | 963 | |
| 1086 | - if ( $update && $update_type !== 'xml' ) { | |
| 964 | + if ( $update && $update_type != 'xml' ) { | |
| 1087 | 965 | $values = apply_filters( 'frm_pre_update_entry', $values, $id ); |
| 1088 | 966 | } |
| 1089 | 967 | |
| 1090 | 968 | return $update; |
| @@ -1094,9 +972,9 @@ | ||
| 1094 | 972 | * Package the entry data for updating |
| 1095 | 973 | * |
| 1096 | 974 | * @since 2.0.16 |
| 1097 | 975 | * |
| 1098 | - * @param int $id | |
| 976 | + * @param int $id | |
| 1099 | 977 | * @param array $values |
| 1100 | 978 | * |
| 1101 | 979 | * @return array $new_values |
| 1102 | 980 | */ |
| @@ -1107,9 +985,9 @@ | ||
| 1107 | 985 | 'name' => self::get_new_entry_name( $values ), |
| 1108 | 986 | 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ), |
| 1109 | 987 | 'is_draft' => self::get_is_draft_value( $values ), |
| 1110 | 988 | 'updated_at' => current_time( 'mysql', 1 ), |
| 1111 | - 'updated_by' => $values['updated_by'] ?? get_current_user_id(), | |
| 989 | + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(), | |
| 1112 | 990 | ); |
| 1113 | 991 | |
| 1114 | 992 | if ( isset( $values['post_id'] ) ) { |
| 1115 | 993 | $new_values['post_id'] = (int) $values['post_id']; |
| @@ -1136,12 +1014,12 @@ | ||
| 1136 | 1014 | * Perform some actions right after updating an entry |
| 1137 | 1015 | * |
| 1138 | 1016 | * @since 2.0.16 |
| 1139 | 1017 | * |
| 1140 | - * @param bool|int $query_results | |
| 1141 | - * @param int $id | |
| 1142 | - * @param array $values | |
| 1143 | - * @param array $new_values | |
| 1018 | + * @param boolean|int $query_results | |
| 1019 | + * @param int $id | |
| 1020 | + * @param array $values | |
| 1021 | + * @param array $new_values | |
| 1144 | 1022 | */ |
| 1145 | 1023 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 1146 | 1024 | if ( $query_results ) { |
| 1147 | 1025 | self::clear_cache(); |
| @@ -1169,9 +1047,9 @@ | ||
| 1169 | 1047 | * @since 2.0.16 |
| 1170 | 1048 | * |
| 1171 | 1049 | * @param array $values |
| 1172 | 1050 | * |
| 1173 | - * @return bool|int $entry_id | |
| 1051 | + * @return int | boolean $entry_id | |
| 1174 | 1052 | */ |
| 1175 | 1053 | public static function create_entry_from_xml( $values ) { |
| 1176 | 1054 | $entry_id = self::create_entry( $values, 'xml' ); |
| 1177 | 1055 | |
| @@ -1183,12 +1061,12 @@ | ||
| 1183 | 1061 | * Certain actions aren't necessary when importing (like saving sub entries and modifying other vals) |
| 1184 | 1062 | * |
| 1185 | 1063 | * @since 2.0.16 |
| 1186 | 1064 | * |
| 1187 | - * @param int $id | |
| 1065 | + * @param int $id | |
| 1188 | 1066 | * @param array $values |
| 1189 | 1067 | * |
| 1190 | - * @return bool|int $updated | |
| 1068 | + * @return int | boolean $updated | |
| 1191 | 1069 | */ |
| 1192 | 1070 | public static function update_entry_from_xml( $id, $values ) { |
| 1193 | 1071 | $updated = self::update_entry( $id, $values, 'xml' ); |
| 1194 | 1072 | |
| @@ -1203,22 +1081,6 @@ | ||
| 1203 | 1081 | public static function get_id_by_key( $key ) { |
| 1204 | 1082 | $entry_id = FrmDb::get_var( 'frm_items', array( 'item_key' => sanitize_title( $key ) ) ); |
| 1205 | 1083 | |
| 1206 | 1084 | 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 | 1085 | } |
| 1224 | 1086 | } |