大家都知道,WordPress 預設是不支援中文使用者名稱的,當初小幻註冊使用的英文,但是作者名稱也是英文,小幻便透過資料庫修改弄了幾個中文的別名,但是還是不可以透過中文使用者名稱,有些站點是開啟遊客登入功能的,總不能都是英文的吧,當然別人也不可以修改你的資料庫吧!

那麼便使用中文使用者名稱註冊吧!支援中文使用者名稱的方法也是很簡單的,只要將一段程式碼加入 functions.php 中即可了!
function huan_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
if ($strict) {
$username = preg_replace ('|[^a-zp{Han}0-9 _.-@]|iu', '', $username);
}
$username = trim( $username );
// Consolidate contiguous whitespace
$username = preg_replace( '|s+|', ' ', $username );
return $username;
}
add_filter ('sanitize_user', 'ludou_sanitize_user', 10, 3);
新增進去,開啟註冊功能,就可以看到,中文使用者名稱可以成功使用了!
不過,小幻關閉了使用者註冊,前段時間看了下使用者近千的使用者註冊,有點坑,果斷刪除關閉了!
這段程式碼只對有這些要求的人使用,如果想要在作者處顯示中文別名,資料庫裡修改下就好了!即公開顯示的下拉里,資料庫中新增下就好了!