I need to know what the wp specifications for the usernames are. Like allowed minimum and maximum length, are special characters like ü,ö,ä,ß accepted,..?
Unfortunately I couldn’t find any insight on this in the interweb. Do you have any?
Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.
I think the answer is in the source.
$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 _.[email protected]]|i', '', $username );
So, the code strips tags, octets, and html entities. And it replaces accented characters with unaccented ones via the
remove_accents function, which is fairly lengthy. Other characters get through unless
true (default is
false), in which case only ASCII characters are allowed.
The maximum login name length would be the database limit for the user_login column— 60 characters. The minimum, as best I can tell, is 1.