Support Forum

WordPress usernames, allowable characters?

BC bart cocchiola
bart cocchiola
Member

Hi folks,

Thought I’d put this question here even though it’s a general WordPress question and not specific to SimplePress.

Is it true that WordPress only allows lowercase letters and numbers in usernames?  If so then how do people here have names like “Mr Papa”?  We continue to have gremlins and I’m wondering if our lack of restrictions on our users’ names is something that might be contributing to our problems.

Does BuddyPress have different allowances for characters in usernames?

Thanks,

Bart

11 Answers

New Answer

YS Yellow Swordfish
Yellow Swordfish
Member

I am actually unaware of any restrictions on WP user names although there are almost certainly some. But absolutely NOT capital lertters

BC bart cocchiola
bart cocchiola
Member

thanks for the reply Y.S.  i had a user with a space and capital letters in his username do a test for me.  we had only flagged the space in his username as the problem for him so he registered the name but without the space.

strangely enough, the new username (ohioAV8TOR) without the space seemed to activate his old username (ohio AV8TOR) and his account suddenly let loose a stream of PM’s and other notifications that were hung up in the system.  It’s as if the software associated the bad address with the new address and used it as a validation to dislodge errors with the old address.

there must be something to the usernames issue.  i did find references to username only allowing lowercase and numbers but i’ve got to run out for a bit.  i’ll link to them when i get back.

bart

MP Mr Papa
Mr Papa
Member

Is this standard wp or multisite? Multisite has, I believe, further restrictions… WP is planning to change that in multisite but no ETA….

BC bart cocchiola
bart cocchiola
Member

Mr Papa said
Is this standard wp or multisite? Multisite has, I believe, further restrictions… WP is planning to change that in multisite but no ETA….

standard wordpress

ClassiPress theme, SP forums

 

Would you mind elaborating on the character restrictions please?

YS Yellow Swordfish
Yellow Swordfish
Member

I think you need to direct that question to WordPress support. Simple:Press accepts whatever username has been created by the WP core. And that user name does include capitals and sopaces – witness my own user name for example.

MP Mr Papa
Mr Papa
Member

andy is right, not a wp issue if something is restricting names… likely a membership or registration plugin… or theme…

but how wp does it:  http://codex.wordpress.org/Function_Reference/sanitize_user

BC bart cocchiola
bart cocchiola
Member

I saw that function at the wordpress site and another reference to it in the formatting.php file so I went looking for it.  Here it is for reference;

/**
 * Sanitizes a username, stripping out unsafe characters.
 *
 * Removes tags, octets, entities, and if strict is enabled, will only keep
 * alphanumeric, _, space, ., -, @. After sanitizing, it passes the username,
 * raw username (the username in the parameter), and the value of $strict as
 * parameters for the ‘sanitize_user’ filter.
 *
 * @since 2.0.0
 *
 * @param string $username The username to be sanitized.
 * @param bool $strict If set limits $username to specific characters. Default false.
 * @return string The sanitized username, after passing through filters.
 */
function sanitize_user( $username, $strict = false ) {
    $raw_username = $username;
    $username = wp_strip_all_tags( $username );
    $username = remove_accents( $username );
    // Kill octets
    $username = preg_replace( ‘|%([a-fA-F0-9][a-fA-F0-9])|’, ”, $username );
    $username = preg_replace( ‘/&.+?;/’, ”, $username ); // Kill entities

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

    $username = trim( $username );
    // Consolidate contiguous whitespace
    $username = preg_replace( ‘|s+|’, ‘ ‘, $username );

    /**
     * Filter a sanitized username string.
     *
     * @since 2.0.1
     *
     * @param string $username     Sanitized username.
     * @param string $raw_username The username prior to sanitization.
     * @param bool   $strict       Whether to limit the sanitization to specific characters. Default false.
     */
    return apply_filters( ‘sanitize_user’, $username, $raw_username, $strict );
}

I’m not an expert on .php but it looks to me like standard wordpress lets just about any character to be used with WordPress, provided $strict=false.

And, fwiw, i’m posting this here figuring that the people using SP are probably also WP literate and might be able to help.  i’m not necessarily vying for admin help.  the wordpress.org forums are very limited in the help that one can expect to find there so i thought it might be something we could discuss here.  if it isn’t appropriate to post these kinds of general WP questions then I won’t do so again in the future.

Bart

IK Ike
Ike
Member

Feel free to post any questions – no matter how far from SP they may be. As you said, maybe someone can shed some light on the situation. Unfortunately not myself! Will have to wait for someone else to take a look here.

BC bart cocchiola
bart cocchiola
Member

I just posted this to the ClassiPress forums since it ought to be their responsibility to provide a solution.  If anyone feels like chiming in I’d be happy to find an answer.  Thanks, Bart

 

dealing with similar usernames issue….was going to report a bug

in the formatting.php file I set $strict to True to limit characters that can be used in usernames. using characters other than ., -, and @ throws an error message during the registration process. if you use a space though, the system accepts the new username BUT DELETES THE SPACE WHEN IT RECORDS THE ENTRY!

So if you register using “GSN test user” as your username, it will actually put you into the system as GSNtestuser and when you go to change your password or do something else it won’t recognize you if you put in “GSN test user” but you won’t know to put in GSNtestuser which is how you have been recorded into the database.

How do we get the system to generate a fault for a username with a space in it?? Is there a way to make it spit out the same error message for a space by listing the space character in the sanitize_usernames subroutine or whatever that little bit of code is called? so far, all i’ve done there is to change the false to true after $strict.

thanks,
bart

BC bart cocchiola
bart cocchiola
Member

took a closer look at the sanitize-User subroutine in the Formatting.php file

line 1132 has a string of characters that look like allowed characters for when the $strict variable is set to TRUE as we did last night.  the code around line 1132 also looks like it’s pointing to this string of characters when $strict=true.

In the string of characters there is a mysterious looking space after the number 9 so I deleted the space, saved the file and tried to register the username “test user”.  before deleting the space it would take the name, change it to testuser, and then welcome the new user to the site.

with the space after the 9 in line 1132 deleted, it now throws an error message and our users will be better for it!

Bart