WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to limit registration to some of my sites based on the email domain of the user. For example, I only want people with @gmail.com emails to register.

Any ideas? Plugin possible?

share|improve this question

Tough task...

function wpse27756_restrict_register_email( $user_email ) 
    $errors = new WP_Error();

    if ( ! preg_match( "/gmail/i", $user_email ) 
        $errors->add( 'invalid_email', __( '<strong>ERROR</strong>: You are not allowed to use other mail accounts than GMail.' ) );
    return $errors;
function wpse27756_add_register_email_filter( $user_email ) 
    add_filter( 'user_registration_email', 'wpse27756_restrict_register_email' );
add_action( 'init', 'wpse27756_add_register_email_filter' );

Just written straight out of my head without testing. Give it a try and let us know...

share|improve this answer
Great - thanks! I'll give it a try soon and see what happens - I'm actually not trying to limit to gmail users only (I want to limit to a specific .edu domain). but I'm sure if I change "gmail" to the specific .edu it should work? Has anyone tried using wordpress.org/extend/plugins/user-domain-whitelist ? – BentCircle Sep 6 '11 at 1:03
No, I haven't tried. I merely use plugins. If the above doesn't work with a simply replace of gmail, please go to stackoverflow.com and ask for advice for the preg_match. I'm pretty bad with regular expressions. – kaiser Sep 6 '11 at 11:59
thanks Kaiser - you mentioned plugins, are you using any plugin for this type of function? much appreciated – BentCircle Sep 7 '11 at 0:52
No, you got me wrong. I only use plugins for really big tasks, which I can't acchieve myself in the given time. If the above works for you, mark is as solution. You asked "limit to @gmail" and that's what it does - if you need more than that, please switch to stackoverflow as this would be the place inside the network where a Q about preg_replace should be asked. – kaiser Sep 7 '11 at 8:44
Thanks for the clarification. I'll test and let you know. – BentCircle Sep 7 '11 at 10:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.