Created
December 8, 2016 11:07
-
-
Save seventhqueen/696c3cc4505deca0e1eedda93eb228a6 to your computer and use it in GitHub Desktop.
Enable Chinese usernames in Wordpress registration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sanitize_chinese_user( $username, $raw_username, $strict ) { | |
if ( $username != $raw_username ) { | |
$username = $raw_username; | |
} | |
$username = strip_tags( $username ); | |
// Kill Chinese characters | |
$username = preg_replace( '|[^a-z0-9 _.\-@一-龥]|ui', '', $username ); | |
// Consolidate contiguous whitespace | |
$username = preg_replace( '|\s+|', ' ', $username ); | |
return apply_filters( 'sanitize_chinese_user', $username, $raw_username, $strict ); | |
} | |
add_filter( 'sanitize_user', 'sanitize_chinese_user', 1, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment