Last active
June 27, 2021 08:29
-
-
Save jadealombro/0c6ec2a5224da53b6269b956f75326e9 to your computer and use it in GitHub Desktop.
Blacklist specific tld emails of WPForm's email field
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 | |
/* | |
* Blacklist ru tld emails from your WPForms. | |
* | |
* @link https://wpforms.com/developers/how-to-restrict-email-domains/ | |
* | |
*/ | |
function wpf_blacklist_ru_domains( $field_id, $field_submit, $form_data ) { | |
$tld = substr( strrchr( $field_submit, "." ), 1 ); | |
$blacklist = array( 'ru' ); // add the TLDs here. | |
if( in_array( $tld, $blacklist ) ) { | |
wpforms()->process->errors[ $form_data['id'] ][ $field_id ] = esc_html__( '.ru emails are not accepted.', 'wpforms' ); | |
return; | |
} | |
} | |
add_action('wpforms_process_validate_email', 'wpf_blacklist_ru_domains', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment