WordPress註冊賬號支持中文的完美解決方案

WordPress註冊賬號支持中文的完美解決方案

醬茄 jiangqie.com

醬茄一客戶問WordPress怎麼支持中文註冊,其實醬茄小編之前也沒去嘗試過去解決這個問題,今天趁有空研究了一下,不用WordPress插件即可輕鬆實現,方法很簡單,將下面代碼插入到當前主題functions.php中即可!

//WordPress支持中文名註冊,來自醬茄 jiangqie.com

function git_sanitize_user ($username, $raw_username, $strict) {

$username = wp_strip_all_tags( $raw_username );

$username = remove_accents( $username );

$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );

$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities

if ($strict) {

$username = preg_replace ('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);

}

$username = trim( $username );

$username = preg_replace( '|\s+|', ' ', $username );

return $username;

}

add_filter ('sanitize_user', 'git_sanitize_user', 10, 3);

文章來自:https://www.jiangqie.com/jc/6365.html


分享到:


相關文章: