# Lock Registration and Default Role Settings

> Forces "Anyone can register" and the default new user role to fixed values in code, so an attacker or a mistake cannot open admin-level sign-ups.

- Type: PHP
- Runs: Run everywhere
- Category: [Security](https://wpide.com/library/category/security/)
- Tags: security, registration, settings
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/lock-registration-settings/

## Code

```php
// Whether visitors may register, and the role new users get.
$wpide_allow_registration = false;
$wpide_locked_default_role = 'subscriber';

add_filter( 'pre_option_users_can_register', function () use ( $wpide_allow_registration ) {
    return $wpide_allow_registration ? '1' : '0';
} );

add_filter( 'pre_option_default_role', function () use ( $wpide_locked_default_role ) {
    return $wpide_locked_default_role;
} );
```

## Notes

The settings screen shows the locked values; change them here instead.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Lock Registration and Default Role Settings" 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/
