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.
Opens WPIDE on
Code
// 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 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.