wordpress注冊是不是支持中文名字的如果我們要想讓它支持中文名字我需要對內核程序進行一些簡單的處理,下面一起來看看,我們找到代碼如下:
- sanitize_user在wp_includes/formatting.php中定義,其函數體如下:
- function sanitize_user( $username, $strict = false ) {
- $raw_username = $username;
- $username = wp_strip_all_tags( $username );
- $username = remove_accents( $username );
- // Kill octets
- $username = preg_replace( '|%([a-fA-F0-9][a-fA-F0
- -9])|', '', $username );
- $username = preg_replace( '/&.+?;/', '', $usernam
- e ); // Kill entities
- // If strict, reduce to ASCII for max portability.
- if ( $strict )
- $username = preg_replace( '|[^a-z0-9 _.-@]|i', '', $username );
- // Consolidate contiguous whitespace
- $username = preg_replace( '|s+|', ' ', $username );
- return apply_filters( 'sanitize_user', $username, $r
- aw_username, $strict );
- }
這樣,我們簡單地在第746行前面加上//注釋掉這個語句,就可以支持中文用戶名了,當然,根據版本不同,你的不一定也是第746行.
把 $strict 強制指定為 false,即在 sanitize_user 這行函數的下一行添加如下代碼:
$strict = false;或者注釋掉
//$username = preg_replace( '|[^a-z0-9 _.-@]|i', '', $username );
這樣就一切OK了,但我們如果要對中文名字進行驗證還需要如下操作,代碼如下:
- //增加中文注冊
- function china_login( $username, $raw_username, $strict ) {
- if( !$strict )
- return $username;
- return sanitize_user(stripslashes($raw_username), false);
- } www.49028c.com
- add_filter('sanitize_user', 'china_login', 10, 3);
不過,需要注意的是,在下次升級的時候,還需要做同樣的處理.
新聞熱點
疑難解答
圖片精選