Forums

Special Characters in Usernames (4 posts)

  1. sageleader
    Member
    Posted 2 years ago #

    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.

  2. sageleader
    Member
    Posted 2 years ago #

    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.

  3. fotoblogger
    Member
    Posted 2 years ago #

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

  4. sageleader
    Member
    Posted 1 year ago #

    No I used double slashes instead: //

Topic Closed

This topic has been closed to new replies.

About this Topic