Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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])) {
            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');
share|improve this question
    
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
add comment

1 Answer

up vote 1 down vote accepted

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 ;)

share|improve this answer
    
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
add comment

Your Answer

 
discard

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.