One WPForms Submission per Email per Day
Stops the same email address from submitting a WPForms form more than once in 24 hours, useful for giveaways and quote requests, even in WPForms Lite.
Opens WPIDE on
Code
$wpide_wpf_daily_forms = array(); // Form IDs to protect, e.g. array( 1 ).
$wpide_wpf_daily_hours = 24;
add_action( 'wpforms_process_validate_email', function ( $field_id, $field_submit, $form_data ) use ( $wpide_wpf_daily_forms ) {
if ( ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_daily_forms ), true ) ) {
return;
}
$email = strtolower( trim( is_array( $field_submit ) ? (string) reset( $field_submit ) : (string) $field_submit ) );
if ( is_email( $email ) && get_transient( 'wpide_wpf_once_' . md5( $form_data['id'] . '|' . $email ) ) ) {
$process = method_exists( wpforms(), 'obj' ) ? wpforms()->obj( 'process' ) : wpforms()->process;
$process->errors[ $form_data['id'] ][ $field_id ] = 'This email address has already been used today.';
}
}, 10, 3 );
add_action( 'wpforms_process_complete', function ( $fields, $entry, $form_data ) use ( $wpide_wpf_daily_forms, $wpide_wpf_daily_hours ) {
if ( ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_daily_forms ), true ) ) {
return;
}
foreach ( (array) $fields as $field ) {
if ( isset( $field['type'] ) && 'email' === $field['type'] && is_email( $field['value'] ) ) {
set_transient( 'wpide_wpf_once_' . md5( $form_data['id'] . '|' . strtolower( trim( $field['value'] ) ) ), 1, $wpide_wpf_daily_hours * HOUR_IN_SECONDS );
}
}
}, 10, 3 );
Notes
Only the forms listed at the top are checked; addresses are kept only as hashes in transients that expire after the waiting period.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.