I have a site option where users can enter domains to "whitelist" registrations from. What I'd like to do is hook into the invite/create user flow to verify the new user's domain from their email address matches one of the domains in the site options.

Does anyone know if this is possible, or how to go about doing that?

Add clarification: This would need to look at the email address field within the invite process and I assume strip out everything but the root domain. Then validate the domain is included in an array from blog options. So I guess the start of it would be something like this?

function dwsl_whitelistreg() {
        $settings=get_option( 'school_settings');
        if (in_array( ENTEREDEMAILADDRESS , $settings[whitelist])) {
        else {
            echo "I'm sorry the user's email address does not match a domain given by the school. If you feel this is an error, please email support@dewsly.com";
    add_filter('wpmu_signup_user', 'dwsl_whitelistreg');
  • Can you please add some clarification to this? I'm not at all sure what you're asking. What fields are you wanting to access? – Dan Jan 23 '13 at 22:52
  • Added some more detail – Jake Lisby Jan 23 '13 at 23:13

It is possible to hook into wpmu_validate_user_signup, which returns the $result of the sign-up process. Add another check for the email domain whitelist and add an error if not allowed.

add_filter( 'wpmu_validate_user_signup', 'whitelist_registration_wpse_82859' );

function whitelist_registration_wpse_82859( $result )
    // Test array
    $whitelist = array( 'gmail.com', 'mydomain.com' );

    // http://php.net/manual/en/function.explode.php
    $user_name_domain = explode( '@', $result['user_email'] );

    if( isset( $user_name_domain[1] ) && !in_array( $user_name_domain[1], $whitelist ) )
        $result['errors']->add( 'user_email',  __( 'Email domain blacklisted' ) );

    return $result;

PS: nice trick with the fake filter wpmu_signup_user ;)

  • That works like a charm. I figured someone would know what it was really called. :) I wanted to throw something in that might spring some thought. Thanks so much for your help, you're a life saver. – Jake Lisby Jan 24 '13 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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