wordpress中文用户名长度问题

付费节点推荐


免费节点


节点使用教程


首先,wordpress我默认不支持中文用户名注册。 网上的通用代码是这个,直接拷贝到 functions.php

然后测试发现超过5个中文字,就无法成功注册。需要修改下数据库字段的长度了。

//设置注册用户名允许为中文
function add_chinese_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’, ‘add_chinese_user’, 10, 3);

 

未经允许不得转载:Bcoder资源网 » wordpress中文用户名长度问题

相关推荐

更多优质资源关注微信公众号: bcoder

bcoder
赞 (3)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册