Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created September 11, 2012 17:32
Show Gist options
  • Select an option

  • Save strangerstudios/3700077 to your computer and use it in GitHub Desktop.

Select an option

Save strangerstudios/3700077 to your computer and use it in GitHub Desktop.
Allow + in WordPress Usernames
/*
Allow + in usernames
Just add this code to your active theme's functions.php or a custom plugin.
*/
function pmprorh_sanitize_user( $username, $raw_username, $strict = false )
{
//only check if there is a + in the raw username
if(strpos($raw_username, "+") === false)
return $username;
//start over
$username = $raw_username;
$username = wp_strip_all_tags( $username );
$username = remove_accents( $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 ); //added a + here
$username = trim( $username );
// Consolidate contiguous whitespace
$username = preg_replace( '|\s+|', ' ', $username );
return $username;
}
add_filter("sanitize_user", "pmprorh_sanitize_user", 1, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment