Skip to content

Instantly share code, notes, and snippets.

@seventhqueen
Created December 8, 2016 11:07
Show Gist options
  • Save seventhqueen/696c3cc4505deca0e1eedda93eb228a6 to your computer and use it in GitHub Desktop.
Save seventhqueen/696c3cc4505deca0e1eedda93eb228a6 to your computer and use it in GitHub Desktop.
Enable Chinese usernames in Wordpress registration
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