# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Users](https://wpide.com/library/category/users/)
- Tags: users, registration, intranet
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/registration-allowed-email-domains/

## Code

```php
// 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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Only Allow Registration From Certain Email Domains" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
