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

前端之家收集整理的这篇文章主要介绍了解决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">

原文链接:https://www.f2er.com/wordpress/238511.html

猜你在找的wordpress相关文章