Can I hook into the invite user process to verify their email address is from a certain domain?

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?

Read More

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])) {
            ACTION TO SUBMIT USER
        }
        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');

Related posts

Leave a Reply

1 comment

  1. 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 😉