用户角色未出现在前端-wp评论

问题描述

所以我想“在wordpress中的注释旁边添加用户角色标签

我正在尝试这段代码

if ( ! class_exists( 'WPB_Comment_Author_Role_Label' ) ) :
    class WPB_Comment_Author_Role_Label {
        public function __construct() {
            add_filter( 'get_comment_author',array( $this,'wpb_get_comment_author_role' ),10,3 );
            add_filter( 'get_comment_author_link','wpb_comment_author_role' ) );
        }
         
        // Get comment author role 
        function wpb_get_comment_author_role($author,$comment_id,$comment) { 
            $authoremail = get_comment_author_email( $comment); 
            // Check if user is registered
            if (email_exists($authoremail)) {
                $commet_user_role = get_user_by( 'email',$authoremail );
                $comment_user_role = $commet_user_role->roles[0];
                
                // HTML output to add next to comment author name
                $this->comment_user_role = ' <span class="comment-author-label comment-author-label-'.$comment_user_role.'">' . ucfirst($comment_user_role) . '</span>';
            } else { 
                $this->comment_user_role = '';
            } 

            return $author;
        } 
         
        // display comment author                   
        function wpb_comment_author_role($author) { 
            return $author .= $this->comment_user_role; 
        } 
    }
    
    new WPB_Comment_Author_Role_Label;
endif;

工作正常,但当我检查评论页面时,用户角色未出现在作者姓名旁边

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)