Created
August 29, 2020 10:07
-
-
Save AchalJ/df9ad37aea9f7282a0e416b983203e21 to your computer and use it in GitHub Desktop.
WP Allow User Registration from specific domain emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter( 'pre_user_email', function( $email ) { | |
$allowed_domains = array( | |
'example.com', | |
'yoursite.com', | |
); | |
if ( ! is_email( $email ) ) { | |
return $email; | |
} | |
$user_domain = explode( '@', $email )[1]; | |
if ( ! in_array( $user_domain, $allowed_domains ) ) { | |
wp_send_json_error( array( | |
'code' => 'invalid_domain', | |
'message' => 'Sorry, you are not allowed to register.', | |
) ); | |
} | |
return $email; | |
}, 10 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment