• Hey all,

    Which characters are not allowed in usernames? It looks like ampersands and commas definitely aren’t, but is there any way to be able to use them? Does anyone know of a code modification or plugin that does this? I need my users to be able to have ampersands in their usernames because they are school names and there are a lot of A&M schools.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter sageleader

    (@sageleader)

    Since nobody ever replies on posts here I’ll respond to my own.

    SOLUTION:

    Go to wp-includes/formatting.php

    Find the function sanitize_user(). Essentially I just commented out every line except the first and last. That seems to do the trick, and usernames are now allowed with special characters like ampersands, commas, hyphens, backslashes, etc.

    Hope others find this helpful.

    Hi sageleader
    I need my users to be able to create usernames of numbers only.

    Just to be sure; did you go FROM THIS:

    function sanitize_user( $username, $strict = false ) {
    $raw_username = $username;
    $username = wp_strip_all_tags($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);

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

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

    TO THIS:

    function sanitize_user( $username, $strict = false ) {
    $raw_username = $username;
    /** $username = wp_strip_all_tags($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);
    *
    * // Consolidate contiguous whitespace
    * $username = preg_replace(‘|\s+|’, ‘ ‘, $username);
    */
    return apply_filters(‘sanitize_user’, $username, $raw_username, $strict);
    }

    Thread Starter sageleader

    (@sageleader)

    No I used double slashes instead: //

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Special Characters in Usernames’ is closed to new replies.