Skip to content

Instantly share code, notes, and snippets.

@jadealombro
Last active June 27, 2021 08:29
Show Gist options
  • Save jadealombro/0c6ec2a5224da53b6269b956f75326e9 to your computer and use it in GitHub Desktop.
Save jadealombro/0c6ec2a5224da53b6269b956f75326e9 to your computer and use it in GitHub Desktop.
Blacklist specific tld emails of WPForm's email field
<?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