Created
May 16, 2024 14:38
-
-
Save voboghure-dev/150654069be06d31b4942d64d5d07ed0 to your computer and use it in GitHub Desktop.
Prevent creating spam new user in WordPress
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
// 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