wordpress收费下载资源主题
wordpress付费下载资源插件

wordpress支持中文用户名

WordPress 4.4以后的版本对中文用户名不友好,所以我借鉴了wp-includes/formatting.php中sanitize_user函数的写法,将以下php代码复制到当前主题目录下的functions.php中,即可让WordPress支持使用中文用户名注册和登录:

function mobantu_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', 'mobantu_sanitize_user', 10, 3);

0 个评论

定制开发
本站承接WordPress等系统建站仿站、二次开发、主题插件定制等开发服务
在线咨询
  • 请直接说明需求,勿问在否
    QQ:1-247-246-247

  • QQ一群:104228692(满)
  • QQ二群:64786792
在线咨询
本站承接WordPress建站仿站、二次开发、主题插件定制等PHP开发服务!

了解详情