From c5ca22cd1c9c5b8a1121268a367d3d4ee6d15931 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:26:29 -0400 Subject: [PATCH 01/17] New duplicate check prototype --- classes/models/FrmEntry.php | 10 ++++++++++ classes/models/FrmEntryMeta.php | 5 +++++ js/formidable.js | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 3c62c10456..a68930fea0 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -47,6 +47,13 @@ private static function create_entry( $values, $type ) { public static function is_duplicate( $new_values, $values ) { $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); + if ( 60 === $duplicate_entry_time ) { + $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); + if ( $unique_id && FrmDb::get_var( 'frm_item_metas', array( 'field_id' => 0, 'meta_value' => serialize( compact( 'unique_id' ) ) ), 'id' ) ) { + $duplicate_entry_time = MONTH_IN_SECONDS; + } + } + if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) { return false; } @@ -80,6 +87,9 @@ public static function is_duplicate( $new_values, $values ) { $metas = FrmEntryMeta::get_entry_meta_info( $entry_exist ); $field_metas = array(); foreach ( $metas as $meta ) { + if ( 0 === (int) $meta->field_id ) { + continue; + } $field_metas[ $meta->field_id ] = $meta->meta_value; } diff --git a/classes/models/FrmEntryMeta.php b/classes/models/FrmEntryMeta.php index 1668ca152b..6b69e01830 100644 --- a/classes/models/FrmEntryMeta.php +++ b/classes/models/FrmEntryMeta.php @@ -125,6 +125,11 @@ public static function update_entry_metas( $entry_id, $values ) { 'field_id' ); + $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); + if ( $unique_id ) { + self::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) ); + } + $values_indexed_by_field_id = array(); foreach ( $values as $field_id_or_key => $meta_value ) { $field_id = $field_id_or_key; diff --git a/js/formidable.js b/js/formidable.js index fffcda4ef5..d41236de93 100644 --- a/js/formidable.js +++ b/js/formidable.js @@ -1740,6 +1740,12 @@ function frmFrontFormJS() { object.appendChild( antispamInput ); } + const uniqueIDInput = document.createElement( 'input' ); + uniqueIDInput.type = 'hidden'; + uniqueIDInput.name = 'unique_id'; + uniqueIDInput.value = Math.random().toString( 36 ).substring( 2, 11 ); + object.appendChild( uniqueIDInput ); + if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) { hasFileFields = jQuery( object ).find( 'input[type="file"]' ).filter( function() { return !! this.value; From 6521b28ad993e5dce669b9431ce633c56df0335e Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:45:28 -0400 Subject: [PATCH 02/17] Move check --- classes/models/FrmEntry.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index a68930fea0..6431dde682 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -47,17 +47,28 @@ private static function create_entry( $values, $type ) { public static function is_duplicate( $new_values, $values ) { $duplicate_entry_time = apply_filters( 'frm_time_to_check_duplicates', 60, $new_values ); + if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) { + return false; + } + if ( 60 === $duplicate_entry_time ) { $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); - if ( $unique_id && FrmDb::get_var( 'frm_item_metas', array( 'field_id' => 0, 'meta_value' => serialize( compact( 'unique_id' ) ) ), 'id' ) ) { - $duplicate_entry_time = MONTH_IN_SECONDS; + if ( $unique_id ) { + $unique_id_match = FrmDb::get_var( + 'frm_item_metas', + array( + 'field_id' => 0, + 'meta_value' => serialize( compact( 'unique_id' ) ), + 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - MONTH_IN_SECONDS ), + ), + 'id' + ); + if ( $unique_id_match ) { + $duplicate_entry_time = MONTH_IN_SECONDS; + } } } - if ( false === self::is_duplicate_check_needed( $values, $duplicate_entry_time ) ) { - return false; - } - $check_val = $new_values; $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ); From 1b95d15119e34835d90e14e07a4b25e2f652e070 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:48:59 -0400 Subject: [PATCH 03/17] More new logic into a new function --- classes/models/FrmEntry.php | 50 ++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 6431dde682..7477b92c21 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -51,23 +51,7 @@ public static function is_duplicate( $new_values, $values ) { return false; } - if ( 60 === $duplicate_entry_time ) { - $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); - if ( $unique_id ) { - $unique_id_match = FrmDb::get_var( - 'frm_item_metas', - array( - 'field_id' => 0, - 'meta_value' => serialize( compact( 'unique_id' ) ), - 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - MONTH_IN_SECONDS ), - ), - 'id' - ); - if ( $unique_id_match ) { - $duplicate_entry_time = MONTH_IN_SECONDS; - } - } - } + $duplicate_entry_time = self::maybe_extend_duplicate_entry_time( $duplicate_entry_time ); $check_val = $new_values; $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ); @@ -144,6 +128,38 @@ public static function is_duplicate( $new_values, $values ) { return $is_duplicate; } + /** + * @since x.x + * + * @param int $duplicate_entry_time + * @return int + */ + private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time ) { + if ( 60 !== $duplicate_entry_time ) { + return $duplicate_entry_time; + } + + $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); + if ( ! $unique_id ) { + return $duplicate_entry_time; + } + + $unique_id_match = FrmDb::get_var( + 'frm_item_metas', + array( + 'field_id' => 0, + 'meta_value' => serialize( compact( 'unique_id' ) ), + 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - MONTH_IN_SECONDS ), + ), + 'id' + ); + if ( ! $unique_id_match ) { + return $duplicate_entry_time; + } + + return MONTH_IN_SECONDS; + } + /** * Convert form data to the actual value that would be saved into the database. * 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. From 1bc42fa225dafab09bf3ccfd48db9dde1efddc73 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:51:12 -0400 Subject: [PATCH 04/17] Add missing param --- classes/models/FrmEntry.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 7477b92c21..615f737637 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -51,7 +51,7 @@ public static function is_duplicate( $new_values, $values ) { return false; } - $duplicate_entry_time = self::maybe_extend_duplicate_entry_time( $duplicate_entry_time ); + $duplicate_entry_time = self::maybe_extend_duplicate_entry_time( $duplicate_entry_time, $new_values['created_at'] ); $check_val = $new_values; $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ); @@ -131,10 +131,11 @@ public static function is_duplicate( $new_values, $values ) { /** * @since x.x * - * @param int $duplicate_entry_time + * @param int $duplicate_entry_time + * @param string $created_at * @return int */ - private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time ) { + private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time, $created_at ) { if ( 60 !== $duplicate_entry_time ) { return $duplicate_entry_time; } @@ -149,7 +150,7 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time array( 'field_id' => 0, 'meta_value' => serialize( compact( 'unique_id' ) ), - 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - MONTH_IN_SECONDS ), + 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $created_at ) - MONTH_IN_SECONDS ), ), 'id' ); From fa25a29954b4265423d5c951034af39b8f721568 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:52:58 -0400 Subject: [PATCH 05/17] Add comments --- classes/models/FrmEntry.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 615f737637..99d84254e2 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -137,11 +137,13 @@ public static function is_duplicate( $new_values, $values ) { */ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time, $created_at ) { if ( 60 !== $duplicate_entry_time ) { + // Only check if the time has not been filtered. return $duplicate_entry_time; } $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); if ( ! $unique_id ) { + // Only continue if a unique ID was generated on form submit. return $duplicate_entry_time; } @@ -154,11 +156,9 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time ), 'id' ); - if ( ! $unique_id_match ) { - return $duplicate_entry_time; - } - return MONTH_IN_SECONDS; + // Extend the check to a month when unique ID is detected. + return $unique_id_match ? MONTH_IN_SECONDS : $duplicate_entry_time; } /** From 03daeb9b4b421ae0d4b69d5c2ff7f6f00322be12 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 13:57:18 -0400 Subject: [PATCH 06/17] Clean up a bit --- classes/models/FrmEntry.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 99d84254e2..05afb438cf 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -147,12 +147,17 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time return $duplicate_entry_time; } + $timestamp = strtotime( $created_at ); + if ( false === $timestamp ) { + $timestamp = time(); + } + $unique_id_match = FrmDb::get_var( 'frm_item_metas', array( 'field_id' => 0, 'meta_value' => serialize( compact( 'unique_id' ) ), - 'created_at >' => gmdate( 'Y-m-d H:i:s', strtotime( $created_at ) - MONTH_IN_SECONDS ), + 'created_at >' => gmdate( 'Y-m-d H:i:s', $timestamp - MONTH_IN_SECONDS ), ), 'id' ); From 82be497dadecb7e76dd83fff2707f196660a076c Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 14:04:09 -0400 Subject: [PATCH 07/17] Improve code --- js/formidable.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/js/formidable.js b/js/formidable.js index d41236de93..d5c6d89f10 100644 --- a/js/formidable.js +++ b/js/formidable.js @@ -1594,6 +1594,18 @@ function frmFrontFormJS() { window.hcaptcha = null; } + /** + * @since x.x + * + * @return {string} + */ + function getUniqueKey() { + return Array.from( window.crypto.getRandomValues( new Uint8Array(8 ) ) ) + .map( b => b.toString(16).padStart( 2, '0' ) ) + .join( '' ) + .substring( 0, 9 ); + } + return { init: function() { jQuery( document ).off( 'submit.formidable', '.frm-show-form' ); @@ -1740,10 +1752,11 @@ function frmFrontFormJS() { object.appendChild( antispamInput ); } + // Add a unique ID, used for duplicate checks. const uniqueIDInput = document.createElement( 'input' ); uniqueIDInput.type = 'hidden'; uniqueIDInput.name = 'unique_id'; - uniqueIDInput.value = Math.random().toString( 36 ).substring( 2, 11 ); + uniqueIDInput.value = getUniqueKey(); object.appendChild( uniqueIDInput ); if ( classList.indexOf( 'frm_ajax_submit' ) > -1 ) { From 811bb008e08429eff299a07651006a4f1d5e55b4 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 14:05:19 -0400 Subject: [PATCH 08/17] Spacing fixes --- js/formidable.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/js/formidable.js b/js/formidable.js index d5c6d89f10..9684f6b5eb 100644 --- a/js/formidable.js +++ b/js/formidable.js @@ -1600,8 +1600,8 @@ function frmFrontFormJS() { * @return {string} */ function getUniqueKey() { - return Array.from( window.crypto.getRandomValues( new Uint8Array(8 ) ) ) - .map( b => b.toString(16).padStart( 2, '0' ) ) + return Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) ) + .map( b => b.toString( 16 ).padStart( 2, '0' ) ) .join( '' ) .substring( 0, 9 ); } From 236ea79db5b4390504383da9874845b438cd9f0a Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 14:08:57 -0400 Subject: [PATCH 09/17] Add comment --- js/formidable.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/formidable.js b/js/formidable.js index 9684f6b5eb..a8c1f8e7d1 100644 --- a/js/formidable.js +++ b/js/formidable.js @@ -1597,7 +1597,7 @@ function frmFrontFormJS() { /** * @since x.x * - * @return {string} + * @return {string} Unique key, used for duplicate checks. */ function getUniqueKey() { return Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) ) From c24fb98c441f83ee1e973d22861290e653efe3de Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 21 Nov 2024 14:24:36 -0400 Subject: [PATCH 10/17] Add a filter to allow opt-out --- classes/models/FrmEntry.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 05afb438cf..34f5a84610 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -141,6 +141,18 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time return $duplicate_entry_time; } + /** + * Allow users to opt out of the DB query, in case it causes performance issues. + * + * @since x.x + * + * @param bool $should_extend + */ + $should_extend = apply_filters( 'frm_extend_duplicate_entry_time_on_unique_id_match', true ); + if ( ! $should_extend ) { + return $duplicate_entry_time; + } + $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); if ( ! $unique_id ) { // Only continue if a unique ID was generated on form submit. From 4d5db88a54b55438ac253285f94367376e799774 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 25 Nov 2024 15:33:29 -0400 Subject: [PATCH 11/17] Allow for a longer unique string --- js/formidable.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/js/formidable.js b/js/formidable.js index a8c1f8e7d1..646f2c9674 100644 --- a/js/formidable.js +++ b/js/formidable.js @@ -1602,8 +1602,7 @@ function frmFrontFormJS() { function getUniqueKey() { return Array.from( window.crypto.getRandomValues( new Uint8Array( 8 ) ) ) .map( b => b.toString( 16 ).padStart( 2, '0' ) ) - .join( '' ) - .substring( 0, 9 ); + .join( '' ); } return { From 4332fbcf2efabcbca539407a7704cb7da92c5c96 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 25 Nov 2024 15:33:50 -0400 Subject: [PATCH 12/17] Change the logic and throw error on match --- classes/models/FrmEntry.php | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 34f5a84610..60f3b88485 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -51,7 +51,10 @@ public static function is_duplicate( $new_values, $values ) { return false; } - $duplicate_entry_time = self::maybe_extend_duplicate_entry_time( $duplicate_entry_time, $new_values['created_at'] ); + $is_duplicate = self::maybe_check_for_unique_id_match( $new_values['created_at'] ); + if ( $is_duplicate ) { + return true; + } $check_val = $new_values; $check_val['created_at >'] = gmdate( 'Y-m-d H:i:s', strtotime( $new_values['created_at'] ) - absint( $duplicate_entry_time ) ); @@ -135,12 +138,7 @@ public static function is_duplicate( $new_values, $values ) { * @param string $created_at * @return int */ - private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time, $created_at ) { - if ( 60 !== $duplicate_entry_time ) { - // Only check if the time has not been filtered. - return $duplicate_entry_time; - } - + private static function maybe_check_for_unique_id_match( $created_at ) { /** * Allow users to opt out of the DB query, in case it causes performance issues. * @@ -148,15 +146,15 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time * * @param bool $should_extend */ - $should_extend = apply_filters( 'frm_extend_duplicate_entry_time_on_unique_id_match', true ); - if ( ! $should_extend ) { - return $duplicate_entry_time; + $should_check = apply_filters( 'frm_check_for_unique_id_match', true ); + if ( ! $should_check ) { + return false; } $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); if ( ! $unique_id ) { // Only continue if a unique ID was generated on form submit. - return $duplicate_entry_time; + return false; } $timestamp = strtotime( $created_at ); @@ -175,7 +173,7 @@ private static function maybe_extend_duplicate_entry_time( $duplicate_entry_time ); // Extend the check to a month when unique ID is detected. - return $unique_id_match ? MONTH_IN_SECONDS : $duplicate_entry_time; + return (bool) $unique_id_match; } /** From bfb19e6f614747c76ff7984af6660607e1c8f198 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 25 Nov 2024 17:14:45 -0400 Subject: [PATCH 13/17] Fix workflow issue --- classes/models/FrmEntry.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 60f3b88485..3a0f4e8778 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -134,7 +134,6 @@ public static function is_duplicate( $new_values, $values ) { /** * @since x.x * - * @param int $duplicate_entry_time * @param string $created_at * @return int */ From ff8fa1f43e9e7c072ef0f4c12627772b8f217d54 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Mon, 25 Nov 2024 17:15:29 -0400 Subject: [PATCH 14/17] Remove var --- classes/models/FrmEntry.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 3a0f4e8778..4878397545 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -51,8 +51,7 @@ public static function is_duplicate( $new_values, $values ) { return false; } - $is_duplicate = self::maybe_check_for_unique_id_match( $new_values['created_at'] ); - if ( $is_duplicate ) { + if ( self::maybe_check_for_unique_id_match( $new_values['created_at'] ) ) { return true; } From 1154b99c6acf1d72c78ffe7c105fd22d44560547 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Wed, 27 Nov 2024 13:24:41 -0400 Subject: [PATCH 15/17] Remove old comment that is no longer true --- classes/models/FrmEntry.php | 1 - 1 file changed, 1 deletion(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 4878397545..351a6b16be 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -170,7 +170,6 @@ private static function maybe_check_for_unique_id_match( $created_at ) { 'id' ); - // Extend the check to a month when unique ID is detected. return (bool) $unique_id_match; } From faa76aa20e3deda2d6a8b824c7636ca34176f76e Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 29 Nov 2024 10:22:04 -0400 Subject: [PATCH 16/17] Move filter to a function and stop adding the item meta when opted out --- classes/models/FrmEntry.php | 27 +++++++++++++++++---------- classes/models/FrmEntryMeta.php | 4 +++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 351a6b16be..64221a6643 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -134,18 +134,10 @@ public static function is_duplicate( $new_values, $values ) { * @since x.x * * @param string $created_at - * @return int + * @return false|int */ private static function maybe_check_for_unique_id_match( $created_at ) { - /** - * Allow users to opt out of the DB query, in case it causes performance issues. - * - * @since x.x - * - * @param bool $should_extend - */ - $should_check = apply_filters( 'frm_check_for_unique_id_match', true ); - if ( ! $should_check ) { + if ( ! self::should_check_for_unique_id_match() ) { return false; } @@ -173,6 +165,21 @@ private static function maybe_check_for_unique_id_match( $created_at ) { return (bool) $unique_id_match; } + /** + * @since x.x + */ + public static function should_check_for_unique_id_match() { + /** + * Allow users to opt out of the DB query, in case it causes performance issues. + * + * @since x.x + * + * @param bool $should_extend + */ + $should_check = apply_filters( 'frm_check_for_unique_id_match', true ); + return (bool) $should_check; + } + /** * Convert form data to the actual value that would be saved into the database. * 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. diff --git a/classes/models/FrmEntryMeta.php b/classes/models/FrmEntryMeta.php index 6b69e01830..acba6c5bf3 100644 --- a/classes/models/FrmEntryMeta.php +++ b/classes/models/FrmEntryMeta.php @@ -125,8 +125,10 @@ public static function update_entry_metas( $entry_id, $values ) { 'field_id' ); + // This unique ID is inserted with JS on form submit. + // It is used to check for duplicate entries. $unique_id = FrmAppHelper::get_post_param( 'unique_id', '', 'sanitize_key' ); - if ( $unique_id ) { + if ( $unique_id && FrmEntry::should_check_for_unique_id_match() ) { self::add_entry_meta( $entry_id, 0, '', compact( 'unique_id' ) ); } From 27f129e9136ca8bc8d4365890207399a08632f3f Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Fri, 29 Nov 2024 10:39:56 -0400 Subject: [PATCH 17/17] Fix return type --- classes/models/FrmEntry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/models/FrmEntry.php b/classes/models/FrmEntry.php index 64221a6643..b3dffb90b1 100644 --- a/classes/models/FrmEntry.php +++ b/classes/models/FrmEntry.php @@ -134,7 +134,7 @@ public static function is_duplicate( $new_values, $values ) { * @since x.x * * @param string $created_at - * @return false|int + * @return bool */ private static function maybe_check_for_unique_id_match( $created_at ) { if ( ! self::should_check_for_unique_id_match() ) {