WordPress注册账号支持中文的解决方案

02月/22日/WordPress/浏览 580

WordPress怎么支持中文注册,其实追格小编之前也没去尝试过去解决这个问题,今天趁有空研究了一下,不用WordPress插件即可轻松实现,方法很简单,将下面代码插入到当前主题functions.php中即可!

//WordPress支持中文名注册 追格 zhuige.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);


发表评论

暂无评论,抢个沙发...

客服 工单