让WordPress支持中文用户名的三种方法

WordPress教程5个月前更新 炙宇
11,056 0

方法一

打开 wp-includes/formatting.php,找到

function sanitize_user( $username, $strict = false ) {

在这句函数的下一行添加一句下面的代码

$strict = false;

这样就OK了,但是这样的做法,在每次升级wordpress版本后,必须再重复操作一次,并且这样会绕过字符串检查,留下隐患。但是只有这样才能让管理员使用中文名。

方法二

找到当前主题目录下的functions.php加入下面的代码

function ludou_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-z\p{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);

方法三

使用Chinese Username插件。

 

 

 

© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...