BuddyPress: Allow only one email domain to register

Question

In the BuddyPress, I want to allow register and log in using only one email domain. For instance, xxx@myemaildomain.com restore all will be disallowed.

I have checked in the BuddyPress source and found that BuddyPress is using bp_core_validate_user_signup( $user_name, $user_email ) for sign up that has a filter

return apply_filters( 'bp_core_validate_user_signup', $result );

So I have tried to use the filter to modify the user_email filed as in the code below. But it is not working.

function wf_validate_email_domain($result)
{

    $email = $result[ 'user_email' ];

    // make sure we've got a valid email
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
        // split on @ and return last value of array (the domain)
        $domain = array_pop(explode('@', $email));

        if ($domain != 'apolloblake.com') {
            $result[ 'user_email' ] = '';
        }
    }

    return $result;

}

add_filter('bp_core_validate_user_signup', 'wf_validate_email_domain', 9999);

Question:

How can I validate email so it allows to register and login only from
one specific email domain?

0
, pixelngrain 3 years 2020-04-07T08:51:58-05:00 0 Answers 89 views 0

Leave an answer

Browse
Browse