Where can I find documentation on what characters are allowed in user names and why?

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?

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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.

  2. 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.