If you are using WordPress as a blog or enterprise website, you must be familiar with this user page:
People on the powerful Earth of Wordpress are clear, but on the other hand, it sometimes makes us feel complicated. For example, you can set the name as shown in the preceding figure. The settings include "User Name", "name", "Last Name", "nickname", and "public display name ", you can leave the "name" and "last name" unspecified..
Users who want to use the Chinese name as the "user name" may encounter the following problem: when registering with a Chinese character, the system prompts an error:
Today, even domain names support Chinese characters. WordPress is so popular that it does not support Chinese user names. It is a bit difficult to say. After all, there is indeed a need for this in reality. Fortunately, we can modify the system function to support Chinese user names. The function that controls character registration is inTheSanitize_user,CodeAs follows:
Function Sanitize_user ( $ Username , $ Strict = False ){ $ Raw_username = $ 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 ); // Consolidate contiguous whitespace $ Username = Preg_replace ('| \ S + | ','', $ Username ); Return Apply_filters ('sanitize _ user ', $ Username , $ Raw_username , $ Strict );}
The reason why this function can control the registration of Chinese characters is that the user name registration and modification function (Validate_username and wp_insert_userThe sanitize_user function is referenced during execution, and the value of the second parameter of the sanitize_user function is set to "true ".
$ Username=Preg_replace('| [^ A-z0-9 _. \-@] | I ','',$ Username);
Therefore, characters other than letters and numbers in the uername string are blocked. There are two ways to make username support Chinese:
1) comment out the if statement in the sanitize_user function;
2) set the second parameter value to "false" when the user name is registered and the function is modified to call sanitize_user ".
This is OK. However, if you do not need to register a chinese user name, we recommend that you do not modify the WordPress system function.