微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

解决WordPress支持使用中文用户名注册和登录的方法

我们在使用wordpress建站的过程当中,有些客户要求后台可以使用中文用户名来进行注册登录。借鉴wp-includes/formatting.PHP中sanitize_user函数的写法,可以使用下面的方法实现。

切换到模板目录,打开 functions.PHP 文件添加如下代码

Crayon-5c891d4e4ea9a822073184" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">functions.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">Crayon-row">
Crayon-nums " data-settings="show">
Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;">
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-1">1
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-2">2
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-3">3
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-4">4
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-5">5
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-6">6
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-7">7
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-8">8
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-9">9
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-10">10
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-11">11
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-12">12
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-13">13
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-14">14
Crayon-num" data-line="Crayon-5c891d4e4ea9a822073184-15">15
Crayon-num Crayon-striped-num" data-line="Crayon-5c891d4e4ea9a822073184-16">16
Crayon-code">
Crayon-pre" style="font-size: 12px !important; line-height: 15px !important; -moz-tab-size:4; -o-tab-size:4; -webkit-tab-size:4; tab-size:4;">
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-1">Crayon-ta">PHP
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-2">Crayon-t">functionCrayon-h"> Crayon-e">sanitize_userCrayon-h"> Crayon-sy">(Crayon-v">$usernameCrayon-sy">,Crayon-h"> Crayon-v">$raw_usernameCrayon-sy">,Crayon-h"> Crayon-v">$strictCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-3">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">wp_strip_all_tagsCrayon-sy">(Crayon-h"> Crayon-v">$raw_usernameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-4">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">remove_accentsCrayon-sy">(Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-5">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replaceCrayon-sy">(Crayon-h"> Crayon-s">'|%([a-fA-F0-9][a-fA-F0-9])|'Crayon-sy">,Crayon-h"> Crayon-s">''Crayon-sy">,Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-6">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replaceCrayon-sy">(Crayon-h"> Crayon-s">'/&.+?;/'Crayon-sy">,Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-sy">)Crayon-sy">;Crayon-h"> Crayon-c">// Kill entities
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-7">Crayon-h"> Crayon-st">ifCrayon-h"> Crayon-sy">(Crayon-v">$strictCrayon-sy">)Crayon-h"> Crayon-sy">{
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-8">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replaceCrayon-h"> Crayon-sy">(Crayon-s">'|[^a-z\p{Han}0-9 _.\-@]|iu'Crayon-sy">,Crayon-h"> Crayon-v">$usernameCrayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-9">Crayon-h"> Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-10">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">trimCrayon-sy">(Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-11">Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-o">=Crayon-h"> Crayon-e">preg_replaceCrayon-sy">(Crayon-h"> Crayon-s">'|\s+|'Crayon-sy">,Crayon-h"> Crayon-s">' 'Crayon-sy">,Crayon-h"> Crayon-v">$usernameCrayon-h"> Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-12">Crayon-h"> Crayon-k ">returnCrayon-h"> Crayon-v">$usernameCrayon-sy">;
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-13">Crayon-sy">}
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-14">
Crayon-line" id="Crayon-5c891d4e4ea9a822073184-15">Crayon-e">add_filterCrayon-h"> Crayon-sy">(Crayon-s">'sanitize_user'Crayon-sy">,Crayon-h"> Crayon-s">'sanitize_user'Crayon-sy">,Crayon-h"> Crayon-cn">10Crayon-sy">,Crayon-h"> Crayon-cn">3Crayon-sy">)Crayon-sy">;
Crayon-line Crayon-striped-line" id="Crayon-5c891d4e4ea9a822073184-16">

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐