探索,發現,愛好、學習,記錄,分享。
學海無涯,天涯若比鄰,三人行,必有我師。

让WordPress支持汉语用户名注册

将以下代码加入function.php即可:

//让wordpress支持中文用户名-wuzuowei.net
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);

版權聲明:本文采用知識共享 署名4.0國際許可協議 [BY-NC-SA] 進行授權
轉載事宜:如需轉載需徵得應允,轉載必須注明來源於本站的信息。
文章名称:《让WordPress支持汉语用户名注册》
文章链接:https://www.thefreesky.com/blog/24736.html
本站資源僅供個人學習交流,請於下載後24小時內刪除,不允許用於商業用途,否則法律問題自行承擔。

評論 抢沙发