| @@ -5,15 +5,8 @@ | ||
| 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 | * |
| @@ -46,29 +39,10 @@ | ||
| 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 | - * | |
| 57 | - * @return void | |
| 58 | - */ | |
| 59 | - private static function flag_new_unique_key( $unique_id ) { | |
| 60 | - if ( ! isset( self::$unique_id_match_checks[ $unique_id ] ) ) { | |
| 61 | - self::$unique_id_match_checks[ $unique_id ] = false; | |
| 62 | - } | |
| 63 | - } | |
| 64 | - | |
| 65 | - /** | |
| 66 | 43 | * Check for duplicate entries created in the last minute |
| 67 | 44 | * |
| 68 | - * @param array $new_values New values. | |
| 69 | - * @param array $values Values. | |
| 70 | - * | |
| 71 | 45 | * @return bool |
| 72 | 46 | */ |
| 73 | 47 | public static function is_duplicate( $new_values, $values ) { |
| 74 | 48 | $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); |
| @@ -76,12 +50,8 @@ | ||
| 76 | 50 | if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) { |
| 77 | 51 | return false; |
| 78 | 52 | } |
| 79 | 53 | |
| 80 | - if ( self::maybe_check_for_unique_id_match( $values, $new_values['created_at'] ) ) { | |
| 81 | - return true; | |
| 82 | - } | |
| 83 | - | |
| 84 | 54 | $check_val = $new_values; |
| 85 | 55 | $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ); |
| 86 | 56 | |
| 87 | 57 | unset( $check_val['created_at'], $check_val['updated_at'], $check_val['is_draft'], $check_val['id'], $check_val['item_key'] ); |
| @@ -102,9 +72,8 @@ | ||
| 102 | 72 | global $frm_vars; |
| 103 | 73 | $frm_vars['checking_duplicates'] = true; |
| 104 | 74 | |
| 105 | 75 | $is_duplicate = false; |
| 106 | - | |
| 107 | 76 | foreach ( $entry_exists as $entry_exist ) { |
| 108 | 77 | $is_duplicate = true; |
| 109 | 78 | |
| 110 | 79 | // make sure it's a duplicate |
| @@ -109,13 +78,9 @@ | ||
| 109 | 78 | |
| 110 | 79 | // make sure it's a duplicate |
| 111 | 80 | $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); |
| 112 | 81 | $field_metas = array(); |
| 113 | - | |
| 114 | 82 | foreach ( $metas as $meta ) { |
| 115 | - if ( 0 === (int) $meta->field_id ) { | |
| 116 | - continue; | |
| 117 | - } | |
| 118 | 83 | $field_metas[ $meta->field_id ] = $meta->meta_value; |
| 119 | 84 | } |
| 120 | 85 | |
| 121 | 86 | $filtered_vals = array_filter( $values['item_meta'] ); |
| @@ -141,9 +106,8 @@ | ||
| 141 | 106 | continue; |
| 142 | 107 | } |
| 143 | 108 | |
| 144 | 109 | $diff = array_diff_assoc( $field_metas, $new_meta ); |
| 145 | - | |
| 146 | 110 | foreach ( $diff as $meta_value ) { |
| 147 | 111 | if ( ! empty( $meta_value ) ) { |
| 148 | 112 | $is_duplicate = false; |
| 149 | 113 | } |
| @@ -159,88 +123,21 @@ | ||
| 159 | 123 | return $is_duplicate; |
| 160 | 124 | } |
| 161 | 125 | |
| 162 | 126 | /** |
| 163 | - * @since 6.16.3 | |
| 164 | - * | |
| 165 | - * @param array $values POST request data. | |
| 166 | - * @param string $created_at The timestamp of the entry we are checking for. | |
| 167 | - * | |
| 168 | - * @return bool | |
| 169 | - */ | |
| 170 | - private static function maybe_check_for_unique_id_match( $values, $created_at ) { | |
| 171 | - if ( ! self::should_check_for_unique_id_match() ) { | |
| 172 | - return false; | |
| 173 | - } | |
| 174 | - | |
| 175 | - if ( empty( $values['unique_id'] ) ) { | |
| 176 | - return false; | |
| 177 | - } | |
| 178 | - | |
| 179 | - $unique_id = sanitize_key( $values['unique_id'] ); | |
| 180 | - | |
| 181 | - if ( ! $unique_id ) { | |
| 182 | - // Only continue if a unique ID was generated on form submit. | |
| 183 | - return false; | |
| 184 | - } | |
| 185 | - | |
| 186 | - if ( isset( self::$unique_id_match_checks[ $unique_id ] ) ) { | |
| 187 | - return self::$unique_id_match_checks[ $unique_id ]; | |
| 188 | - } | |
| 189 | - | |
| 190 | - $timestamp = strtotime( $created_at ); | |
| 191 | - | |
| 192 | - if ( false === $timestamp ) { | |
| 193 | - $timestamp = time(); | |
| 194 | - } | |
| 195 | - | |
| 196 | - self::$unique_id_match_checks[ $unique_id ] = (bool) FrmDb::get_var( | |
| 197 | - 'frm_item_metas', | |
| 198 | - array( | |
| 199 | - 'field_id' => 0, | |
| 200 | - 'meta_value' => serialize( compact( 'unique_id' ) ), | |
| 201 | - 'created_at >' => gmdate( 'Y-m-d H:i:s', $timestamp - MONTH_IN_SECONDS ), | |
| 202 | - ), | |
| 203 | - 'id' | |
| 204 | - ); | |
| 205 | - | |
| 206 | - return self::$unique_id_match_checks[ $unique_id ]; | |
| 207 | - } | |
| 208 | - | |
| 209 | - /** | |
| 210 | - * @since 6.16.3 | |
| 211 | - * | |
| 212 | - * @return bool | |
| 213 | - */ | |
| 214 | - private static function should_check_for_unique_id_match() { | |
| 215 | - /** | |
| 216 | - * Allow users to opt out of the DB query, in case it causes performance issues. | |
| 217 | - * | |
| 218 | - * @since 6.16.3 | |
| 219 | - * | |
| 220 | - * @param bool $should_extend | |
| 221 | - */ | |
| 222 | - $should_check = apply_filters( 'frm_check_for_unique_id_match', true ); | |
| 223 | - return (bool) $should_check; | |
| 224 | - } | |
| 225 | - | |
| 226 | - /** | |
| 227 | 127 | * Convert form data to the actual value that would be saved into the database. |
| 228 | 128 | * 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. |
| 229 | 129 | * |
| 230 | 130 | * @param array $filter_vals |
| 231 | 131 | * @param int $entry_id |
| 232 | - * | |
| 233 | 132 | * @return array |
| 234 | 133 | */ |
| 235 | 134 | private static function convert_values_to_their_saved_value( $filter_vals, $entry_id ) { |
| 236 | 135 | $reduced = array(); |
| 237 | - | |
| 238 | 136 | foreach ( $filter_vals as $field_id => $value ) { |
| 239 | 137 | $field = FrmFieldFactory::get_field_object( $field_id ); |
| 240 | 138 | $reduced[ $field_id ] = $field->get_value_to_save( $value, array( 'entry_id' => $entry_id ) ); |
| 241 | 139 | $reduced[ $field_id ] = $field->set_value_before_save( $reduced[ $field_id ] ); |
| 242 | - | |
| 243 | 140 | if ( '' === $reduced[ $field_id ] || ( is_array( $reduced[ $field_id ] ) && 0 === count( $reduced[ $field_id ] ) ) ) { |
| 244 | 141 | unset( $reduced[ $field_id ] ); |
| 245 | 142 | } |
| 246 | 143 | } |
| @@ -275,13 +172,8 @@ | ||
| 275 | 172 | |
| 276 | 173 | return true; |
| 277 | 174 | } |
| 278 | 175 | |
| 279 | - /** | |
| 280 | - * @param int|string $id | |
| 281 | - * | |
| 282 | - * @return false|int | |
| 283 | - */ | |
| 284 | 176 | public static function duplicate( $id ) { |
| 285 | 177 | global $wpdb; |
| 286 | 178 | |
| 287 | 179 | $values = self::getOne( $id ); |
| @@ -296,9 +188,8 @@ | ||
| 296 | 188 | $new_values['created_at'] = current_time( 'mysql', 1 ); |
| 297 | 189 | $new_values['updated_at'] = $new_values['created_at']; |
| 298 | 190 | |
| 299 | 191 | $query_results = $wpdb->insert( $wpdb->prefix . 'frm_items', $new_values ); |
| 300 | - | |
| 301 | 192 | if ( ! $query_results ) { |
| 302 | 193 | return false; |
| 303 | 194 | } |
| 304 | 195 | |
| @@ -304,9 +195,8 @@ | ||
| 304 | 195 | |
| 305 | 196 | $entry_id = $wpdb->insert_id; |
| 306 | 197 | |
| 307 | 198 | global $frm_vars; |
| 308 | - | |
| 309 | 199 | if ( ! isset( $frm_vars['saved_entries'] ) ) { |
| 310 | 200 | $frm_vars['saved_entries'] = array(); |
| 311 | 201 | } |
| 312 | 202 | $frm_vars['saved_entries'][] = (int) $entry_id; |
| @@ -337,11 +227,10 @@ | ||
| 337 | 227 | * Update an entry with some differences depending on the update type |
| 338 | 228 | * |
| 339 | 229 | * @since 2.0.16 |
| 340 | 230 | * |
| 341 | - * @param int $id | |
| 342 | - * @param array $values | |
| 343 | - * @param string $update_type | |
| 231 | + * @param int $id | |
| 232 | + * @param array $values | |
| 344 | 233 | * |
| 345 | 234 | * @return bool|int $query_results |
| 346 | 235 | */ |
| 347 | 236 | private static function update_entry( $id, $values, $update_type ) { |
| @@ -347,9 +236,8 @@ | ||
| 347 | 236 | private static function update_entry( $id, $values, $update_type ) { |
| 348 | 237 | global $wpdb; |
| 349 | 238 | |
| 350 | 239 | $update = self::before_update_entry( $id, $values, $update_type ); |
| 351 | - | |
| 352 | 240 | if ( ! $update ) { |
| 353 | 241 | return false; |
| 354 | 242 | } |
| 355 | 243 | |
| @@ -365,9 +253,8 @@ | ||
| 365 | 253 | /** |
| 366 | 254 | * Delete an entry. |
| 367 | 255 | * |
| 368 | 256 | * @param int|string $id |
| 369 | - * | |
| 370 | 257 | * @return bool True on success, false if nothing was deleted. |
| 371 | 258 | */ |
| 372 | 259 | public static function destroy( $id ) { |
| 373 | 260 | global $wpdb; |
| @@ -374,9 +261,8 @@ | ||
| 374 | 261 | $id = (int) $id; |
| 375 | 262 | |
| 376 | 263 | // Item meta is required for conditional logic in actions with 'delete' events. |
| 377 | 264 | $entry = self::getOne( $id, true ); |
| 378 | - | |
| 379 | 265 | if ( ! $entry ) { |
| 380 | 266 | $result = false; |
| 381 | 267 | return $result; |
| 382 | 268 | } |
| @@ -407,20 +293,12 @@ | ||
| 407 | 293 | |
| 408 | 294 | return $result; |
| 409 | 295 | } |
| 410 | 296 | |
| 411 | - /** | |
| 412 | - * @param int $id | |
| 413 | - * @param mixed $value | |
| 414 | - * @param int|string $form_id | |
| 415 | - * | |
| 416 | - * @return false|int | |
| 417 | - */ | |
| 418 | 297 | public static function update_form( $id, $value, $form_id ) { |
| 419 | 298 | global $wpdb; |
| 420 | 299 | $form_id = isset( $value ) ? $form_id : null; |
| 421 | 300 | $result = $wpdb->update( $wpdb->prefix . 'frm_items', array( 'form_id' => $form_id ), array( 'id' => $id ) ); |
| 422 | - | |
| 423 | 301 | if ( $result ) { |
| 424 | 302 | self::clear_cache(); |
| 425 | 303 | } |
| 426 | 304 | |
| @@ -431,10 +309,8 @@ | ||
| 431 | 309 | * Clear entry caching |
| 432 | 310 | * Called when an entry is changed |
| 433 | 311 | * |
| 434 | 312 | * @since 2.0.5 |
| 435 | - * | |
| 436 | - * @return void | |
| 437 | 313 | */ |
| 438 | 314 | public static function clear_cache() { |
| 439 | 315 | FrmDb::cache_delete_group( 'frm_entry' ); |
| 440 | 316 | FrmDb::cache_delete_group( 'frm_item' ); |
| @@ -446,17 +322,11 @@ | ||
| 446 | 322 | * After switching to the wp_loaded hook for processing entries, |
| 447 | 323 | * we can no longer use 'name', but check it as a fallback |
| 448 | 324 | * |
| 449 | 325 | * @since 2.0.11 |
| 450 | - * | |
| 451 | - * @param array $values | |
| 452 | - * @param array|string $default | |
| 453 | - * | |
| 454 | - * @return string | |
| 455 | 326 | */ |
| 456 | 327 | public static function get_new_entry_name( $values, $default = '' ) { |
| 457 | - $name = $values['item_name'] ?? $values['name'] ?? $default; | |
| 458 | - | |
| 328 | + $name = isset( $values['item_name'] ) ? $values['item_name'] : ( isset( $values['name'] ) ? $values['name'] : $default ); | |
| 459 | 329 | if ( is_array( $name ) ) { |
| 460 | 330 | $name = reset( $name ); |
| 461 | 331 | } |
| 462 | 332 | |
| @@ -468,9 +338,8 @@ | ||
| 468 | 338 | * |
| 469 | 339 | * @since 2.0.9 |
| 470 | 340 | * |
| 471 | 341 | * @param int|object $entry By reference. |
| 472 | - * | |
| 473 | 342 | * @return void |
| 474 | 343 | */ |
| 475 | 344 | public static function maybe_get_entry( &$entry ) { |
| 476 | 345 | if ( $entry && is_numeric( $entry ) ) { |
| @@ -479,14 +348,8 @@ | ||
| 479 | 348 | $entry = false; |
| 480 | 349 | } |
| 481 | 350 | } |
| 482 | 351 | |
| 483 | - /** | |
| 484 | - * @param int|string $id | |
| 485 | - * @param bool $meta | |
| 486 | - * | |
| 487 | - * @return object|null | |
| 488 | - */ | |
| 489 | 352 | public static function getOne( $id, $meta = false ) { |
| 490 | 353 | global $wpdb; |
| 491 | 354 | |
| 492 | 355 | $query = "SELECT it.*, fr.name as form_name, fr.form_key as form_key FROM {$wpdb->prefix}frm_items it |
| @@ -502,9 +365,8 @@ | ||
| 502 | 365 | return $entry; |
| 503 | 366 | } |
| 504 | 367 | |
| 505 | 368 | $entry = FrmDb::check_cache( $id, 'frm_entry' ); |
| 506 | - | |
| 507 | 369 | if ( $entry !== false ) { |
| 508 | 370 | self::prepare_entry( $entry ); |
| 509 | 371 | return $entry; |
| 510 | 372 | } |
| @@ -519,10 +381,8 @@ | ||
| 519 | 381 | /** |
| 520 | 382 | * @since 4.02.03 |
| 521 | 383 | * |
| 522 | 384 | * @param object $entry |
| 523 | - * | |
| 524 | - * @return void | |
| 525 | 385 | */ |
| 526 | 386 | private static function prepare_entry( &$entry ) { |
| 527 | 387 | if ( empty( $entry ) ) { |
| 528 | 388 | return; |
| @@ -536,10 +396,8 @@ | ||
| 536 | 396 | /** |
| 537 | 397 | * @since 4.02.03 |
| 538 | 398 | * |
| 539 | 399 | * @param array $entries |
| 540 | - * | |
| 541 | - * @return void | |
| 542 | 400 | */ |
| 543 | 401 | private static function prepare_entries( &$entries ) { |
| 544 | 402 | foreach ( $entries as $k => $entry ) { |
| 545 | 403 | self::prepare_entry( $entry ); |
| @@ -546,13 +404,8 @@ | ||
| 546 | 404 | $entries[ $k ] = $entry; |
| 547 | 405 | } |
| 548 | 406 | } |
| 549 | 407 | |
| 550 | - /** | |
| 551 | - * @param object|null $entry | |
| 552 | - * | |
| 553 | - * @return object|null | |
| 554 | - */ | |
| 555 | 408 | public static function get_meta( $entry ) { |
| 556 | 409 | if ( ! $entry ) { |
| 557 | 410 | return $entry; |
| 558 | 411 | } |
| @@ -569,15 +422,13 @@ | ||
| 569 | 422 | |
| 570 | 423 | $entry->metas = array(); |
| 571 | 424 | |
| 572 | 425 | $include_key = apply_filters( 'frm_include_meta_keys', false, array( 'form_id' => $entry->form_id ) ); |
| 573 | - | |
| 574 | 426 | foreach ( $metas as $meta_val ) { |
| 575 | 427 | FrmFieldsHelper::prepare_field_value( $meta_val->meta_value, $meta_val->type ); |
| 576 | 428 | |
| 577 | 429 | if ( $meta_val->item_id == $entry->id ) { |
| 578 | 430 | $entry->metas[ $meta_val->field_id ] = $meta_val->meta_value; |
| 579 | - | |
| 580 | 431 | if ( $include_key ) { |
| 581 | 432 | $entry->metas[ $meta_val->field_key ] = $entry->metas[ $meta_val->field_id ]; |
| 582 | 433 | } |
| 583 | 434 | continue; |
| @@ -590,9 +441,9 @@ | ||
| 590 | 441 | |
| 591 | 442 | $entry->metas[ $meta_val->field_id ][] = $meta_val->meta_value; |
| 592 | 443 | |
| 593 | 444 | unset( $meta_val ); |
| 594 | - }//end foreach | |
| 445 | + } | |
| 595 | 446 | unset( $metas ); |
| 596 | 447 | |
| 597 | 448 | FrmDb::set_cache( $entry->id, $entry, 'frm_entry' ); |
| 598 | 449 | |
| @@ -600,10 +451,8 @@ | ||
| 600 | 451 | } |
| 601 | 452 | |
| 602 | 453 | /** |
| 603 | 454 | * @param string $id |
| 604 | - * | |
| 605 | - * @return bool | |
| 606 | 455 | */ |
| 607 | 456 | public static function exists( $id ) { |
| 608 | 457 | global $wpdb; |
| 609 | 458 | |
| @@ -617,23 +466,13 @@ | ||
| 617 | 466 | $where = array( 'id' => $id ); |
| 618 | 467 | } else { |
| 619 | 468 | $where = array( 'item_key' => $id ); |
| 620 | 469 | } |
| 621 | - | |
| 622 | 470 | $id = FrmDb::get_var( $wpdb->prefix . 'frm_items', $where ); |
| 623 | 471 | |
| 624 | 472 | return $id && $id > 0; |
| 625 | 473 | } |
| 626 | 474 | |
| 627 | - /** | |
| 628 | - * @param array|string $where | |
| 629 | - * @param string $order_by | |
| 630 | - * @param string $limit | |
| 631 | - * @param bool $meta | |
| 632 | - * @param bool $inc_form | |
| 633 | - * | |
| 634 | - * @return array | |
| 635 | - */ | |
| 636 | 475 | public static function getAll( $where, $order_by = '', $limit = '', $meta = false, $inc_form = true ) { |
| 637 | 476 | global $wpdb; |
| 638 | 477 | |
| 639 | 478 | $limit = FrmDb::esc_limit( $limit ); |
| @@ -674,9 +513,8 @@ | ||
| 674 | 513 | $where = array( 'it.form_id' => substr( $where, 11 ) ); |
| 675 | 514 | } |
| 676 | 515 | |
| 677 | 516 | $meta_where = array( 'field_id !' => 0 ); |
| 678 | - | |
| 679 | 517 | if ( $limit == '' && is_array( $where ) && count( $where ) == 1 && isset( $where['it.form_id'] ) ) { |
| 680 | 518 | $meta_where['fi.form_id'] = $where['it.form_id']; |
| 681 | 519 | } else { |
| 682 | 520 | $meta_where['item_id'] = array_keys( $entries ); |
| @@ -720,10 +558,9 @@ | ||
| 720 | 558 | return $entries; |
| 721 | 559 | } |
| 722 | 560 | |
| 723 | 561 | /** |
| 724 | - * @param int|string $field_id | |
| 725 | - * | |
| 562 | + * @param int $field_id | |
| 726 | 563 | * @return string |
| 727 | 564 | */ |
| 728 | 565 | private static function sort_by_field( $field_id ) { |
| 729 | 566 | global $wpdb; |
| @@ -743,9 +580,8 @@ | ||
| 743 | 580 | |
| 744 | 581 | // Pagination Methods |
| 745 | 582 | /** |
| 746 | 583 | * @param array|int|string $where If int, use the form id. |
| 747 | - * | |
| 748 | 584 | * @return int|string |
| 749 | 585 | */ |
| 750 | 586 | public static function getRecordCount( $where = '' ) { |
| 751 | 587 | global $wpdb; |
| @@ -767,22 +603,18 @@ | ||
| 767 | 603 | return $count; |
| 768 | 604 | } |
| 769 | 605 | |
| 770 | 606 | /** |
| 771 | - * @param int|string $p_size | |
| 772 | - * @param array|int|string $where | |
| 773 | - * | |
| 607 | + * @param int|string $p_size | |
| 774 | 608 | * @return int |
| 775 | 609 | */ |
| 776 | 610 | public static function getPageCount( $p_size, $where = '' ) { |
| 777 | 611 | $p_size = (int) $p_size; |
| 778 | 612 | $count = 1; |
| 779 | - | |
| 780 | 613 | if ( $p_size ) { |
| 781 | 614 | if ( ! is_numeric( $where ) ) { |
| 782 | 615 | $where = self::getRecordCount( $where ); |
| 783 | 616 | } |
| 784 | - | |
| 785 | 617 | $count = ceil( (int) $where / $p_size ); |
| 786 | 618 | } |
| 787 | 619 | |
| 788 | 620 | return $count; |
| @@ -822,9 +654,8 @@ | ||
| 822 | 654 | * @return bool|int $entry_id |
| 823 | 655 | */ |
| 824 | 656 | private static function continue_to_create_entry( $values, $new_values ) { |
| 825 | 657 | $entry_id = self::insert_entry_into_database( $new_values ); |
| 826 | - | |
| 827 | 658 | if ( ! $entry_id ) { |
| 828 | 659 | return false; |
| 829 | 660 | } |
| 830 | 661 | |
| @@ -838,10 +669,8 @@ | ||
| 838 | 669 | * |
| 839 | 670 | * @since 2.0 |
| 840 | 671 | * |
| 841 | 672 | * @param array $values The POST values by reference. |
| 842 | - * | |
| 843 | - * @return void | |
| 844 | 673 | */ |
| 845 | 674 | public static function sanitize_entry_post( &$values ) { |
| 846 | 675 | $sanitize_method = array( |
| 847 | 676 | 'form_id' => 'absint', |
| @@ -890,22 +719,15 @@ | ||
| 890 | 719 | 'description' => self::get_entry_description( $values ), |
| 891 | 720 | 'user_id' => self::get_entry_user_id( $values ), |
| 892 | 721 | ); |
| 893 | 722 | |
| 894 | - $new_values['updated_by'] = $values['updated_by'] ?? $new_values['user_id']; | |
| 723 | + $new_values['updated_by'] = isset( $values['updated_by'] ) ? $values['updated_by'] : $new_values['user_id']; | |
| 895 | 724 | |
| 896 | 725 | return $new_values; |
| 897 | 726 | } |
| 898 | 727 | |
| 899 | - /** | |
| 900 | - * @param array $values | |
| 901 | - * @param string $name | |
| 902 | - * @param mixed $default | |
| 903 | - * | |
| 904 | - * @return mixed | |
| 905 | - */ | |
| 906 | 728 | private static function get_entry_value( $values, $name, $default ) { |
| 907 | - return $values[ $name ] ?? $default; | |
| 729 | + return isset( $values[ $name ] ) ? $values[ $name ] : $default; | |
| 908 | 730 | } |
| 909 | 731 | |
| 910 | 732 | /** |
| 911 | 733 | * Get the ip for a new entry. |
| @@ -922,9 +744,8 @@ | ||
| 922 | 744 | return ''; |
| 923 | 745 | } |
| 924 | 746 | |
| 925 | 747 | $ip = FrmAppHelper::get_ip_address(); |
| 926 | - | |
| 927 | 748 | if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING ) { |
| 928 | 749 | $ip = self::get_entry_value( $values, 'ip', $ip ); |
| 929 | 750 | } |
| 930 | 751 | |
| @@ -1051,11 +872,9 @@ | ||
| 1051 | 872 | * Add the new entry to global $frm_vars |
| 1052 | 873 | * |
| 1053 | 874 | * @since 2.0.16 |
| 1054 | 875 | * |
| 1055 | - * @param int|string $entry_id | |
| 1056 | - * | |
| 1057 | - * @return void | |
| 876 | + * @param int $entry_id | |
| 1058 | 877 | */ |
| 1059 | 878 | private static function add_new_entry_to_frm_vars( $entry_id ) { |
| 1060 | 879 | global $frm_vars; |
| 1061 | 880 | |
| @@ -1070,55 +889,28 @@ | ||
| 1070 | 889 | * Add entry metas, if there are any |
| 1071 | 890 | * |
| 1072 | 891 | * @since 2.0.16 |
| 1073 | 892 | * |
| 1074 | - * @param array $values | |
| 1075 | - * @param int|string $entry_id | |
| 1076 | - * | |
| 893 | + * @param array $values | |
| 894 | + * @param int $entry_id | |
| 1077 | 895 | * @return void |
| 1078 | 896 | */ |
| 1079 | 897 | private static function maybe_add_entry_metas( $values, $entry_id ) { |
| 1080 | 898 | if ( isset( $values['item_meta'] ) ) { |
| 1081 | 899 | FrmEntryMeta::update_entry_metas( $entry_id, $values['item_meta'] ); |
| 1082 | - self::maybe_add_unique_id_meta( $values, $entry_id ); | |
| 1083 | 900 | } |
| 1084 | 901 | self::maybe_add_captcha_meta( (int) $values['form_id'], (int) $entry_id ); |
| 1085 | 902 | } |
| 1086 | 903 | |
| 1087 | 904 | /** |
| 1088 | - * @since 6.16.3 | |
| 1089 | - * | |
| 1090 | - * @param array $values | |
| 1091 | - * @param int $entry_id | |
| 1092 | - * | |
| 1093 | - * @return void | |
| 1094 | - */ | |
| 1095 | - private static function maybe_add_unique_id_meta( $values, $entry_id ) { | |
| 1096 | - if ( ! empty( $values['parent_form_id'] ) || empty( $values['unique_id'] ) || ! self::should_check_for_unique_id_match() ) { | |
| 1097 | - return; | |
| 1098 | - } | |
| 1099 | - | |
| 1100 | - // This unique ID is inserted with JS on form submit. | |
| 1101 | - // It is used to check for duplicate entries. | |
| 1102 | - $unique_id = sanitize_key( $values['unique_id'] ); | |
| 1103 | - | |
| 1104 | - if ( $unique_id ) { | |
| 1105 | - FrmEntryMeta::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) ); | |
| 1106 | - self::flag_new_unique_key( $unique_id ); | |
| 1107 | - } | |
| 1108 | - } | |
| 1109 | - | |
| 1110 | - /** | |
| 1111 | 905 | * @since 5.0.15 |
| 1112 | 906 | * |
| 1113 | 907 | * @param int $form_id |
| 1114 | 908 | * @param int $entry_id |
| 1115 | - * | |
| 1116 | 909 | * @return void |
| 1117 | 910 | */ |
| 1118 | 911 | private static function maybe_add_captcha_meta( $form_id, $entry_id ) { |
| 1119 | 912 | global $frm_vars; |
| 1120 | - | |
| 1121 | 913 | if ( array_key_exists( 'captcha_scores', $frm_vars ) && array_key_exists( $form_id, $frm_vars['captcha_scores'] ) ) { |
| 1122 | 914 | $captcha_score_meta = array( 'captcha_score' => $frm_vars['captcha_scores'][ $form_id ] ); |
| 1123 | 915 | FrmEntryMeta::add_entry_meta( $entry_id, 0, '', maybe_serialize( $captcha_score_meta ) ); |
| 1124 | 916 | } |
| @@ -1131,10 +923,8 @@ | ||
| 1131 | 923 | * |
| 1132 | 924 | * @param int $entry_id |
| 1133 | 925 | * @param array $values |
| 1134 | 926 | * @param array $new_values |
| 1135 | - * | |
| 1136 | - * @return void | |
| 1137 | 927 | */ |
| 1138 | 928 | private static function after_entry_created_actions( $entry_id, $values, $new_values ) { |
| 1139 | 929 | // This is a child entry. |
| 1140 | 930 | $is_child = isset( $values['parent_nonce'] ) && ! empty( $values['parent_form_id'] ) && wp_verify_nonce( $values['parent_nonce'], 'parent' ); |
| @@ -1150,10 +940,8 @@ | ||
| 1150 | 940 | * |
| 1151 | 941 | * @param array $values |
| 1152 | 942 | * @param array $new_values |
| 1153 | 943 | * @param int $entry_id |
| 1154 | - * | |
| 1155 | - * @return void | |
| 1156 | 944 | */ |
| 1157 | 945 | private static function after_insert_entry_in_database( $values, $new_values, $entry_id ) { |
| 1158 | 946 | |
| 1159 | 947 | self::add_new_entry_to_frm_vars( $entry_id ); |
| @@ -1169,11 +957,11 @@ | ||
| 1169 | 957 | * Perform some actions right before updating an entry |
| 1170 | 958 | * |
| 1171 | 959 | * @since 2.0.16 |
| 1172 | 960 | * |
| 1173 | - * @param int|string $id | |
| 1174 | - * @param array $values | |
| 1175 | - * @param string $update_type | |
| 961 | + * @param int $id | |
| 962 | + * @param array $values | |
| 963 | + * @param string $update_type | |
| 1176 | 964 | * |
| 1177 | 965 | * @return bool $update |
| 1178 | 966 | */ |
| 1179 | 967 | private static function before_update_entry( $id, &$values, $update_type ) { |
| @@ -1209,9 +997,9 @@ | ||
| 1209 | 997 | 'name' => self::get_new_entry_name( $values ), |
| 1210 | 998 | 'form_id' => (int) self::get_entry_value( $values, 'form_id', null ), |
| 1211 | 999 | 'is_draft' => self::get_is_draft_value( $values ), |
| 1212 | 1000 | 'updated_at' => current_time( 'mysql', 1 ), |
| 1213 | - 'updated_by' => $values['updated_by'] ?? get_current_user_id(), | |
| 1001 | + 'updated_by' => isset( $values['updated_by'] ) ? $values['updated_by'] : get_current_user_id(), | |
| 1214 | 1002 | ); |
| 1215 | 1003 | |
| 1216 | 1004 | if ( isset( $values['post_id'] ) ) { |
| 1217 | 1005 | $new_values['post_id'] = (int) $values['post_id']; |
| @@ -1238,14 +1026,12 @@ | ||
| 1238 | 1026 | * Perform some actions right after updating an entry |
| 1239 | 1027 | * |
| 1240 | 1028 | * @since 2.0.16 |
| 1241 | 1029 | * |
| 1242 | - * @param bool|int $query_results | |
| 1243 | - * @param int|string $id | |
| 1244 | - * @param array $values | |
| 1245 | - * @param array $new_values | |
| 1246 | - * | |
| 1247 | - * @return void | |
| 1030 | + * @param bool|int $query_results | |
| 1031 | + * @param int $id | |
| 1032 | + * @param array $values | |
| 1033 | + * @param array $new_values | |
| 1248 | 1034 | */ |
| 1249 | 1035 | private static function after_update_entry( $query_results, $id, $values, $new_values ) { |
| 1250 | 1036 | if ( $query_results ) { |
| 1251 | 1037 | self::clear_cache(); |
| @@ -1251,9 +1037,8 @@ | ||
| 1251 | 1037 | self::clear_cache(); |
| 1252 | 1038 | } |
| 1253 | 1039 | |
| 1254 | 1040 | global $frm_vars; |
| 1255 | - | |
| 1256 | 1041 | if ( ! isset( $frm_vars['saved_entries'] ) ) { |
| 1257 | 1042 | $frm_vars['saved_entries'] = array(); |
| 1258 | 1043 | } |
| 1259 | 1044 | |