Username Spaces
-
Hi UM Team, thank you for this plugin!
Is there a way to prevent new users from registering a username with spaces? With an error message telling them to use “username” and not “user name”?
I couldn’t find a native option in Ultimate Member settings, so I tried this function:
add_filter( 'validate_username' , 'custom_validate_username', 10, 2);
add_filter('validate_username', function (bool $isValid, string $username): bool {
if (preg_match('/[^a-z]/', $username)) {
return false;
}
return $isValid;
});Also tried this to prevent capital letters:
add_filter( 'validate_username' , 'custom_validate_username', 10, 2);
function custom_validate_username( $valid, $username ) {
if ( preg_match("/\\s/", $username) ) {
// There are spaces, return a WP_Error object with a custom message
return new WP_Error( 'username_has_spaces', __( '<strong>Error</strong>: Usernames cannot contain spaces.', 'your-text-domain' ) );
}
return $valid;
}Neither functions are working and I think it may be because UM is handling the registration. It seems like a good idea to have some control over what is allowed when a member creates a new username. Is there a way to achieve this?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.