Only Allow Registration From Certain Email Domains
Limits sign-ups to email addresses at the domains you list, for example your company or school domain.
Opens WPIDE on
Code
// Email domains that may register.
$wpide_allowed_email_domains = array( 'example.com', 'example.org' );
add_filter( 'registration_errors', function ( $errors, $login, $email ) use ( $wpide_allowed_email_domains ) {
$domain = strtolower( (string) substr( strrchr( (string) $email, '@' ), 1 ) );
if ( ! in_array( $domain, array_map( 'strtolower', $wpide_allowed_email_domains ), true ) ) {
$errors->add( 'wpide_email_domain', '<strong>Error:</strong> Registration is limited to approved email addresses.' );
}
return $errors;
}, 10, 3 );
Notes
Administrators can still create users with any email address from the Users screen.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.