WordPress – Custom username validation

Ever wanted to use a Gmail alias e-mailaddress as a username in WordPress?

Noticed that WordPress doesn’t like that?

That’s where the validate_username filter comes in handy.
Paste the code below somewhere in your functions.php and start accepting GMail aliasses as usernames!

add_filter('validate_username', 'my_validate_username', 10, 2);
 
function my_validate_username($valid, $username)
{
    $sanitized = sanitize_user($username, false);
    $valid = ($sanitized == $username && !empty($sanitized));
    return $valid;
}

Enjoy!

comments

No comments yet.

Sorry, the comment form is closed at this time.