之前没有发现,登录注册的时候,只有使用英文才能注册成功,对于大部分读者都是国内用户,这显然十分不友好,折腾了一下,将其修改为中文也可以。通过查询资料,找到了三种修改方法:
方法一
打开 wp-includes/formatting.php,找到
function sanitize_user( $username, $strict = false ) {
在这句函数的下一行添加一句下面的代码:
1 |
$strict = false; |
但是这样的做法,在每次升级wordpress版本后,必须再重复操作一次。
方法二
使用chinese-username插件来解决此问题。
方法三(推荐)
将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
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 // 网上很多教程都是直接将$strict赋值false, // 这样会绕过字符串检查,留下隐患 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); |
该方法参考自:让wordpress支持中文用户名的简便方法,个人建议使用方法三。
评论