加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

wordpress支持中文用户名的简便方法

发布时间:2020-12-14 14:29:07 所属栏目:wordpress 来源:网络整理
导读:由站长 通过网络收集整理的代码片段。编程之家小编现在分享给大家,也给大家做个参考。 今天创客云介绍新的方法,借鉴了 wp-includes/formatting.php 中 sanitize_user 函数的写法,同样是将以下 php 代码复制到当前主题目录下的 functions.

以下代码由PHP站长网 52php.cn收集自互联网现在PHP站长网小编把它分享给大家,仅供参考

今天创客云介绍新的方法,借鉴了 wp-includes/formatting.php 中 sanitize_user 函数的写法,同样是将以下 php 代码复制到当前主题目录下的 functions.php 中,即可让 wordpress 支持使用中文用户名注册和登录:

代码如下:

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-zp{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);

以上内容由PHP站长网【52php.cn】收集整理供大家参考研究如果以上内容对您有帮助,欢迎收藏、点赞、推荐、分享。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读