Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save voboghure-dev/150654069be06d31b4942d64d5d07ed0 to your computer and use it in GitHub Desktop.
Save voboghure-dev/150654069be06d31b4942d64d5d07ed0 to your computer and use it in GitHub Desktop.
Prevent creating spam new user in WordPress
// Blacklist woocommerce customer registration
function blacklisted_user( $errors, $sanitized_user_login, $user_email ) {
// Blacklist email domains
$blacklist = ['tmomail.net', 'vtext.com', 'txt.att.net'];
$email_parts = explode( '@', $user_email );
if ( is_numeric( $email_parts[0] ) ) {
// If the user email first part is numeric, add an error message
$errors->add( 'blacklist_error', '<strong>ERROR</strong>: This email is not allowed to register on this site.' );
} else if ( in_array( $email_parts[1], $blacklist ) ) {
// If the user email second part is in the blacklist, add an error message
$errors->add( 'blacklist_error', '<strong>ERROR</strong>: This email is not allowed to register on this site.' );
}
return $errors;
}
add_filter( 'registration_errors', 'blacklisted_user', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment