WP模板阁数千套各行业Wordpress模板随你选,总有一款适合你的网站![收藏本站] 注册 登录

无插件实现wordpress支持中文名注册方法

        发布:WP模板阁 类型:wordpress教程 浏览:1,481 次

一般而言,我们在网上注册用户名的时候肯定常用和默认使用英文或者数字作为注册用户名,同样在WordPress注册账户的时候也是这样默认的。

我们一般的WordPress程序可能都没有开放用户注册,也有一些朋友使用的wordpress模板是开放注册的。如果我们希望支持用户注册使用中文用户名,则需要在WordPress程序中设置才可以支持。

如果我们有需要wordpress支持中文名注册,可以按照以下的方法。

在当前主题functions.php文件中添加下面代码,即可实现。比之前的方法好处就不用担心WP程序升级后被替换。

//Wordpress支持中文名注册
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);