I wrote an article
The code is as follows: |
Copy code |
Function ludou_non_strict_login ($ username, $ raw_username, $ strict ){ If (! $ Strict) Return $ username; Return sanitize_user (stripslashes ($ raw_username), false ); } Add_filter ('sanitize _ user', 'ludou _ non_strict_login ', 10, 3 ); |
Now I have taken a look at it. This tutorial filters too few usernames and is prone to security issues. Today we will introduce a new method, using wp-shortdes/formatting for reference. in php, the sanitize_user function is written by copying the following php code to the functions under the current topic directory. in php, WordPress can be registered and logged on using a Chinese user name:
The code is as follows: |
Copy code |
Function ludou_sanitize_user ($ username, $ raw_username, $ strict ){ $ Username = wp_strip_all_tags ($ raw_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 // Many online tutorials directly assign $ strict a value of false, // This will bypass the string check, leaving hidden risks If ($ strict ){ $ Username = preg_replace ('| [^ a-z \ p {Han} 0-9 _. \-@] | iu', '', $ username ); } $ Username = trim ($ username ); // Define lidate contiguous whitespace $ Username = preg_replace ('| \ s + |', '', $ username ); Return $ username; } Add_filter ('sanitize _ user', 'ludou _ sanitize_user ', 10, 3 ); |
After adding it to the function. Php file, you can add a Chinese name to the wordpress registration.