WordPress topic creation Tips 3 [chinese user name logon supported]

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.