Allow Network Signups Only From Certain Email Domains
Rejects user signups on the network unless the email address belongs to one of your domains, such as a school or company network.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_domains = array( 'example.com', 'example.org' ); // Allowed email domains.
add_filter( 'wpmu_validate_user_signup', function ( $result ) use ( $wpide_domains ) {
$email = isset( $result['user_email'] ) ? strtolower( $result['user_email'] ) : '';
$domain = substr( strrchr( $email, '@' ), 1 );
if ( $email && ! in_array( $domain, array_map( 'strtolower', $wpide_domains ), true ) ) {
$result['errors']->add( 'user_email', 'Please sign up with your organisation email address.' );
}
return $result;
} );
Notes
This works alongside the "Limited Email Registrations" field in Network Settings; use either one.
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.