Last active
July 8, 2023 19:26
-
-
Save wpmudev-sls/a516633a168dd4d5c9bc9cdab2e4cc9d to your computer and use it in GitHub Desktop.
[Forminator] - Limit the submition by email.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] - Limit the submition by email. | |
* Description: [Forminator] - Limit the submition by email. | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} elseif ( defined( 'WP_CLI' ) && WP_CLI ) { | |
return; | |
} | |
add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ){ | |
$your_list_forms = [123,456]; | |
if( empty( $submit_errors ) && in_array( $form_id, $your_list_forms ) ){ | |
$your_unique_field_name = 'email-1'; | |
$your_error_msg = 'The email already sumitted'; | |
foreach( $field_data_array as $field ){ | |
if( $field['name'] === $your_unique_field_name ){ | |
global $wpdb; | |
$table_meta = $wpdb->prefix . 'frmt_form_entry_meta'; | |
$table_entry = $wpdb->prefix . 'frmt_form_entry'; | |
if( $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(1) FROM $table_meta as m LEFT JOIN $table_entry as e ON m.entry_id = e.entry_id WHERE m.meta_key = %s AND m.meta_value=%s AND e.form_id = %d LIMIT 1;", $field['name'], $field['value'], $form_id ) ) ){ | |
$submit_errors[][$your_unique_field_name] = $your_error_msg; | |
} | |
break; | |
} | |
} | |
} | |
return $submit_errors; | |
}, 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment