Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would love to be able to use spaces in usernames, but this does not seem possible. Is there a writeup in the codex or somewhere that explains what characters are allowed and why it was restricted to that set or is it just alphas only and suck it up?

If I want users to use something other than a username with no spaces, is my only real option a plugin that allows users to login with their email addresses instead, but still requires an alpha only username at account creation?

Oh, and I am on a WPMU/network site.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

You can use spaces in usernames, no problem. Several users on wordpress.org have spaces in their usernames.

Strict mode only allows these characters: a-z0-9<space>_.\-@

However WP doesn't default to strict mode.

Now, multisite has different restrictions, and it may strip spaces there. This is because usernames are used to create independent blogs and such on multisite installs.

share|improve this answer
    
Makes sense, and yet my multi install will not allow me to create users with spaces, @, or . in the name. I looked at formatting.php and it does appear to allow @ . and spaces. Any idea of where I should search to figure out what is preventing these characters? I would just like to know why they are prevented. –  Purcell Jul 5 '11 at 20:20
2  
It's in the function wpmu_validate_user_signup in wp-includes/ms-functions.php, and yes, it only allows letters and numbers. Definitely a multisite thing. –  Otto Jul 5 '11 at 21:05

I don't think there's any official documentation about that, but you can have a look at the sanitize_user function in wp-includes/formatting.php :

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 );

    return apply_filters( 'sanitize_user', $username, $raw_username, $strict );
}

You could hook into that function and override the default behavior with your own.

share|improve this answer
    
Thanks for pointing out formatting.php. My multi install will not allow me to create users with spaces, @, or . in the name. I looked at formatting.php and it does appear to allow @ . and spaces. Any idea of where I should search to figure out what is preventing these characters? I would just like to know why they are prevented. –  Purcell Jul 5 '11 at 20:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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