让wordpress支持用户名使用中文

发布时间:2020-12-24 21:09 最后更新:2023-03-20 12:55 浏览量:共 31 次浏览

让wordpress支持用户名使用中文

打开文件 【网站根目录/wp-includes/formatting.php】,查找到sanitize_user函数,将其中的

2106-2108行:


if ( $strict ) {
$username = preg_replace( '|[^a-z0-9 _.\-@]|i', '', $username );
}

修改为:

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

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

以后每次升级wordpress都要设置一下。

 

还有一个办法,是在主题下的functions.php 最后一行,添加如下代码,我用的此方法。


//让wordpress支持用户名使用中文,支持9个汉字
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', 18, 3);

相关文章

调所有前端VUE,标题四个字,超过自动调行,字和框竖向自动居中
【Simply Static生成静态失败】宝塔防火墙拦截了服务器本机访问自身域名 / IP 的环回请求
zhong zhuan
宝塔面板中如何修改网站顺序
Ubuntun和debian 系统升级
【教程】Simply Static配置详情