WordPress will not allow you to use Plus ‘+’ sign for username registration. Anyone trying a + sign in the username, the plus sign (+) was being removed by the function.
This issue also came up for my JSON API User Plugin registration endpoint when some people asked how they could use + sign with username and email registration.
If you are using form or sending variable values via code, you must send it as POST method and use %2b for + sign. i.e. email%2baccount@gmail.com and not email+account@gmail.com.
To allow + sign inclusion for your WordPress user registration, you need to add following function in your theme functions.php file:
function pim_sanitize_user($username, $raw_username, $strict) {
$allowed_symbols = "a-z0-9+ _.\-@"; //yes we allow whitespace which will be trimmed further down script
//Strip HTML Tags
$username = wp_strip_all_tags ($raw_username);
//Remove Accents
$username = remove_accents ($username);
//Kill octets
$username = preg_replace ('|%([a-fA-F0-9][a-fA-F0-9])|', '', $username);
//Kill entities
$username = preg_replace ('/&.+?;/', '', $username);
//allow + symbol
$username = preg_replace ('|[^'.$allowed_symbols.']|iu', '', $username);
//Remove Whitespaces
$username = trim ($username);
// Consolidate contiguous Whitespaces
$username = preg_replace ('|\s+|', ' ', $username);
//Done
return $username;
}
add_filter ('sanitize_user', 'pim_sanitize_user', 10, 3);




