Created
September 11, 2012 17:32
-
-
Save strangerstudios/3700077 to your computer and use it in GitHub Desktop.
Allow + in WordPress Usernames
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| 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