wordpress如何支持中文名注冊(cè)來(lái)訪者賬號(hào)
[重要通告]如您遇疑難雜癥,本站支持知識(shí)付費(fèi)業(yè)務(wù),掃右邊二維碼加博主微信,可節(jié)省您寶貴時(shí)間哦!
我們?cè)谑褂脀ordpress的時(shí)候,都知道注冊(cè)的時(shí)候只能是英文或者數(shù)字之類(lèi),不可以使用中文,但是別名可以,不過(guò)有些時(shí)候我們注冊(cè)的時(shí)候就想讓來(lái)訪者直接注冊(cè)為中文,那操作方式如下:
直接粘貼下面代碼插入到functions.php即可實(shí)現(xiàn)注冊(cè)為中文賬號(hào);
//支持中文名注冊(cè)
function git_sanitize_user ($username, $raw_username, $strict) {
$username = wp_strip_all_tags( $raw_username );
$username = remove_accents( $username );
$username = preg_replace( '|%([a-fA-F0-9][a-fA-F0-9])|', '', $username );
$username = preg_replace( '/&.+?;/', '', $username ); // Kill entities
if ($strict) {
$username = preg_replace ('|[^a-z\p{Han}0-9 _.\-@]|iu', '', $username);
}
$username = trim( $username );
$username = preg_replace( '|\s+|', ' ', $username );
return $username;
}
add_filter ('sanitize_user', 'git_sanitize_user', 10, 3);
function git_comment_add_at( $comment_text, $comment = '') {
if( $comment->comment_parent > 0) {
$comment_text = '@<a href="#comment-' . $comment->comment_parent . '">'.get_comment_author( $comment->comment_parent ) . '</a> ' . $comment_text;
}
return $comment_text;
}
add_filter( 'comment_text' , 'git_comment_add_at', 20, 2);
方法二:
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ì)繞過(guò)字符串檢查,留下隱患
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);
方法三
打開(kāi) wp-includes/formatting.php,找到
function sanitize_user( $username, $strict = false ) {
在這句函數(shù)的下一行添加一句下面的代碼
$strict = false;
PS:每次WordPress升級(jí)的之后,還需要做同樣的處理方式;
問(wèn)題未解決?付費(fèi)解決問(wèn)題加Q或微信 2589053300 (即Q號(hào)又微信號(hào))右上方掃一掃可加博主微信
所寫(xiě)所說(shuō),是心之所感,思之所悟,行之所得;文當(dāng)無(wú)敷衍,落筆求簡(jiǎn)潔。 以所舍,求所獲;有所依,方所成!