WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to allow users to create username with + symbol. but wordpess removing the symbol by the register validation process. If I gave username as abcd+123, the user registered with username as abcd123. I need the username registered as it is with + symbol.

Answers are greatly appreciated.

share|improve this question
I think you might encounter some problems using + in the author urls, since + is an url encoded version of the space character. – birgire Mar 27 '13 at 9:11
@birgire No, I just need to change the username as email, So some email can register with + symbol, if so my username too need to contain that + . If any hook like validate_username is there means can re-define. – user1460692 Mar 27 '13 at 10:29
up vote 1 down vote accepted

We need to add a filter to 'sanitize_user'.

Here is the sample code that will work for you.

add_filter( 'sanitize_user', 'tubs_sanitize_user', 10, 3);
function tubs_sanitize_user($username, $raw_username, $strict) {
    $new_username = strip_tags($raw_username);
    // Kill octets
    $new_username = preg_replace('|%([a-fA-F0-9][a-fA-F0-9])|', '', $new_username);
    $new_username = preg_replace('/&.?;/', '', $new_username); // Kill entities

   // If strict, reduce to ASCII for max portability.
   if ( $strict )
        $new_username = preg_replace('|[^a-z0-9 _.\-@+]|i', '', $new_username);

    return $new_username;

Note: This code is the modified version of the original WordPress sanitize_user function.
share|improve this answer
Me too, just found it :) I need to dig in more – user1460692 Mar 27 '13 at 11:13

Your Answer


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.