Mass registrations on my blog. Disable specific domain?

BTW you can try this one. I just put together something. It should block gmail.com domain.

This function will check for email domain when someone tries to register on your website and throws an error if email domain is matched.

function wpse_disable_email_domain( $errors, $sanitized_user_login, $user_email ) {

    list( $email_user, $email_domain ) = explode( '@', $user_email );

    if ( $email_domain == 'gmail.com' ) {
        $errors->add( 'email_error', __( '<strong>ERROR</strong>: Domain not allowed.', 'my_textdomain' ) );
    }

    return $errors;

}

add_filter( 'registration_errors', 'wpse_disable_email_domain', 10, 3 );

OK I just tested it and it’s working.

Leave a Comment