# Allow Only Administrators to Log In

> Temporarily blocks logins for everyone except administrators, for example during a migration or a security incident.

- Type: PHP
- Runs: Run everywhere
- Category: [Login](https://wpide.com/library/category/login/)
- Tags: login, maintenance, security
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admins-only-login-lockdown/

## Code

```php
$wpide_lockdown_message = 'Logins are paused for maintenance. Please try again later.';

add_filter( 'authenticate', function ( $user ) use ( $wpide_lockdown_message ) {
    if ( $user instanceof WP_User && ! user_can( $user, 'manage_options' ) ) {
        return new WP_Error( 'wpide_login_lockdown', esc_html( $wpide_lockdown_message ) );
    }

    return $user;
}, 100 );
```

## Notes

People who are already logged in stay logged in until their session ends.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Allow Only Administrators to Log In" 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/
