欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 产业 > 给Wordpress评论列表的用户昵称增加个性化角色称号和注册年数

给Wordpress评论列表的用户昵称增加个性化角色称号和注册年数

2024/10/23 21:40:41 来源:https://blog.csdn.net/uuplay0216/article/details/140529926  浏览:    关键词:给Wordpress评论列表的用户昵称增加个性化角色称号和注册年数

什么是个性化角色称号?

个性化称号:其实就是对应wordpress的几个用户组,重新给它装个面具。

比如:管理员 -> 华山掌门

比如:订阅者 -> 华山弟子

比如:VIP组 -> 掌门亲传弟子

。。。

就是个好玩的东西

什么又是注册年数?

显示用户在你的网站上注册了多少年,就像CSDN的这个:

效果对比

默认的评论列表:

前端显示效果:

没有能力修改自定义后台的同学:

如果,你没有自定义后台,又实在想要这个功能,那么你可能需要手动修改代码完成每次用户头衔的变更。其实也就是一次的事情,我想你也不会总去改他吧。请把下面代码添加到 function.php 文件:

// 在评论列表 用户名后面 添加用户角色/注册年数/
// code by yangjiyong VX:uu0216if ( ! class_exists( 'Comment_Author_Role_Label' ) ) :class Comment_Author_Role_Label {public function __construct() {add_filter( 'get_comment_author', array( $this, 'get_comment_author_role' ), 10, 3 );add_filter( 'get_comment_author_link', array( $this, 'comment_author_role' ) );}	// 获取评论角色function get_comment_author_role( $author, $comment_id, $comment ) { $authoremail = get_comment_author_email( $comment); $options = get_option('classic_options');$user_honor_admin = '超级大boss';				//  管理员荣誉$user_honor_vip ='幕后大金主'; 					//  VIP组荣誉$user_honor_member = '入室小土豪'; 				//  会员组荣誉$user_honor_visiter = '踢馆的小子'; 				        //  访客荣誉$user_join_age = '学徒';					//  注册资历$user_name_age = '载';					//  资历称谓$user_visiter =	'闲人';					//  未注册访客资历称谓// 检查用户是否注册if (email_exists($authoremail)) {//获取评论角色$user_roles_name = get_user_by( 'email', $authoremail );//获取评论角色id$the_user = get_user_by('email', $authoremail);$the_user_id = $the_user->ID;    			//获取注册时间$user = get_userdata( $the_user_id );    			$registerdate = get_date_from_gmt($user->user_registered);$time=time();// 给注册时间取整,返回 n 年$amount=date("Y",$time)-date("Y",strtotime($registerdate));if($amount <=0){$amount =0;}// 为了给css编号,超过10年的统一用10,先用10吧,我不知道自己的网站能不能用10年。$css_name = $amount;if($amount > 9){$css_name = 10;}// 把0-9 转换成汉字$arr = array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');$result = null;$integerArrLength = strlen($amount);$result .= $arr[$amount];$amount_txt = $user_join_age.$result.$user_name_age;$comment_user_role = $user_roles_name->roles[0];// 自定义角色身份显示名switch ($comment_user_role) {case 'administrator':$comment_user_role_text= $user_honor_admin;break;case 'vip': // vip组用户身份$comment_user_role_text= $user_hono

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com