We'll create fresh WordPress site with Restrict Usernames installed. You have 20 minutes to test the plugin after that site we'll be deleted.
This plugin allows you to restrict the usernames that new users may use when registering for your site.
If open registration is enabled for your site (via Settings -> General -> Membership (“Anyone can register”)), WordPress allows visitors to register for an account on your blog. By default, any username they choose is allowed so long as it isn’t an already existing account and it doesn’t include invalid (i.e. non-alphanumeric) characters.
Possible reasons for wanting to restrict certain usernames:
When attempting to register with a restricted username, the visitor will be given an error notice that says:
ERROR: This username is invalid. Please enter a valid username.
NOTE: This plugin does not put any restrictions on usernames that the admin chooses for users when creating user accounts from within the WordPress admin. This only restricts the names that users choose themselves when registering for your site.
SPECIAL NOTE: Many membership plugins implement their own user registration handling that often bypasses checks (and hooks) performed by WordPress. As such, it is unlikely that the plugin is compatible with them without special plugin-specific amendments.
Compatible with Multisite and BuddyPress as well.
Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage
The plugin exposes one filter for hooking. Typically, customizations utilizing this hook would be put into your active theme’s functions.php file, or used by another plugin.
c2c_restrict_usernames-validate (filter)
The ‘c2c_restrict_usernames-validate’ hook allows you to add your own customized checks for the username being registered. You can add additional restrictions or override the assessment performed by the plugin.
Arguments:
Example:
/**
* Add custom checks on usernames.
*
* Specifically, prevent use of usernames ending in numbers.
*
* @param bool $valid True if the username is valid, false if not.
* @param string $username The username.
* @param array $options Plugin options.
*/
function my_restrict_usernames_check( $valid, $username, $options ) {
// Only do additional checking if the plugin has already performed its
// checks and deemed the username valid.
if ( $valid ) {
// Don't allow usernames to end in numbers.
if ( preg_match( '/[0-9]+$/', $username ) ) {
$valid = false;
}
}
return $valid;
}
add_filter( 'c2c_restrict_usernames-validate', 'my_restrict_usernames_check', 10, 3 );