借鉴了wp-includes/formatting.php中sanitize_user函数的写法,同样是将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录
[start_tab][wptab number=”1″ title=”代码” ]
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);
[/wptab][wptab number=”2″ title=”备注” ]打开你主题的functions.php文件添加代码即可[/wptab]
[end_tab]
加群入久伴博客官方微信群
加入久伴官方微信群有啥优势?
1.文章内部资源由于时间久远可能失效,加群,群内可以第一时间反馈
2.网站中教程不一定适用任何人,加群可以第一时间咨询并解决您得疑惑
3.你游荡于互联网,也需要群体,加群一起互动交流,畅所欲言
扫描下方二维码即可加入交流讨论

支持中文名字,是个不错的选择
就算不支持中文,其实可以到后台自己设置名字,但是有的用户可能不知道有这个操作,干脆允许中文注册呗
这个功能不错!!
这不错的,收藏了!