There’s a validate_username
filter hook that is used by validate_user()
which is in turn used by register_new_user()
.
So you can disallow usernames containing admin
or other prohibited terms:
add_filter( 'validate_username', 'wpse257667_check_username', 10, 2 );
function wpse257667_check_username( $valid, $username ) {
// This array can grow as large as needed.
$disallowed = array( 'admin', 'other_disallowed_string' );
foreach( $disallowed as $string ) {
// If any disallowed string is in the username,
// mark $valid as false.
if ( $valid && false !== strpos( $username, $string ) ) {
$valid = false;
}
}
return $valid;
}
You can add this code to your theme’s functions.php
file or (preferably) make it a plugin.