wordpress是不支持中文名字注冊的如果你要增加中文注冊是需要在注冊判斷或登錄處進(jìn)行二次開發(fā)了,具體如下.
之前寫了一篇,代碼如下:
- function ludou_non_strict_login( $username, $raw_username, $strict ) {
- if( !$strict )
- return $username;
- return sanitize_user(stripslashes($raw_username), false);
- }
- add_filter('sanitize_user', 'ludou_non_strict_login', 10, 3);
現(xiàn)在回過頭看了一下,這篇教程對用戶名的過濾太少,容易出現(xiàn)安全問題,今天介紹新的方法,借鑒了wp-includes/formatting.php中sanitize_user函數(shù)的寫法,同樣是將以下php代碼復(fù)制到當(dāng)前主題目錄下的functions.php中,即可讓W(xué)ordPress支持使用中文用戶名注冊和登錄,代碼如下:
- 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
- // 網(wǎng)上很多教程都是直接將$strict賦值false,
- // 這樣會(huì)繞過字符串檢查,留下隱患
- if ($strict) {
- $username = preg_replace ('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);//開源軟件:Vevb.com
- }
- $username = trim( $username );
- // Consolidate contiguous whitespace
- $username = preg_replace( '|\s+|', ' ', $username );
- return $username;
- }
- add_filter ('sanitize_user', 'ludou_sanitize_user', 10, 3);
增加到function.php文件中之后你就可以在wordpress注冊中加中文名字了.
新聞熱點(diǎn)
疑難解答
圖片精選