7

I can see validate_user() calls sanitize_user() with strict argument as true, which means uppercase letters are not allowed too.

In source code, I found this comment

// If strict, reduce to ASCII for max portability.
    if ( $strict )
        $username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );

I would like to know how does this affect portability?

7
  • The i modifier in the regex pattern makes it case-insensitive, just something to note.
    – t31os
    Apr 8, 2011 at 14:58
  • so what does this regex actually do here?
    – Ashfame
    Apr 9, 2011 at 19:56
  • 1
    Replaces anything not a-z(upper or lower), 0-9(ie. any number), an underscore, period, hyphen or an @ symbol..
    – t31os
    Apr 9, 2011 at 23:21
  • so how does it block the uppercase alphabets then? :S
    – Ashfame
    Apr 10, 2011 at 14:25
  • 1
    @Ashfame: actually, the function doesn't block uppercase letters. In the comment above the functions, WP writes: "If $strict is true, only alphanumeric characters (as well as _, space, ., -, * @) are returned.". That means uppercase letter are accepted. In fact, I have a WP where I have the username with uppercase letter, and no problems at all.
    – Anh Tran
    Jun 7, 2011 at 13:44

3 Answers 3

7

Uppercase characters are not blocked in usernames on single site setups.

Uppercase characters ARE blocked in usernames on multisite setups. The wpmu_validate_user_signup function forces lowercase a-z and numbers 0-9 only.

0
2

If You are not allowing users to register site, you may disable 'uppercase' restriction from MS install, just add into your theme functions.php file:

remove_action( 'sanitize_user', 'strtolower' );
1

Off hand, I suppose it would be so you can use validate_user's results in a URL or a $_GET string. I'm sure there are plenty of other reasons as well, I guess I don't know what they mean by max portability...

1
  • yes, I am interested in knowing about how this affects portability. anything else like a variable from URL can be configured to converted to lowercase and then made it work. A bit extra work, but will work.
    – Ashfame
    Apr 8, 2011 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.