Wordpress supports two methods for registering Chinese user names

Source: Internet
Author: User
Tags php file php code

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.

Related Article

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.