• Found the answer and figured I would share.

    Go to roughly line 354 or so and find this code block…

    $uarray = split( '@', $user['email'] );
    $user['username'] = sanitize_user( $uarray[0] );

    Now change it to this…

    $uarray = split( '@', $user['email'] );
    $uarray = preg_replace("/[^a-zA-Z0-9\s]/", "", $uarray);
    $user['username'] = sanitize_user( $uarray[0] );

    That’s it.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Erin Bell

    (@ebellempire)

    Okay, actually this may cause errors in some instances [related post]. Not sure why, but it works most of the time.

    Catchable fatal error: Object of class WP_Error could not be converted to string in... path/to/formatting.php on line 2829

    Thread Starter Erin Bell

    (@ebellempire)

    Um, it appears I was running that regular expression on the wrong variable. How about this one, which adds an extra step to the WP sanitize_user() process (which leaves those pesky dots in place):

    $uarray = split( '@', $user['email'] );
    $user['username'] = sanitize_user( $uarray[0] );
    $user['username'] = preg_replace('/[^a-zA-Z0-9]/', '', $user['username']);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Strip non-alphanumeric characters from generated usernames’ is closed to new replies.