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


分享到:


相關文章: