1

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.

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

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.
1
  • Me too, just found it :) I need to dig in more – user1460692 Mar 27 '13 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.