How can i add custom display name for user role in comments?
-
Hello
With this code, I have the user role next to the name in the comments section, but instead of displaying the administrator’s name, I want it to display the desired name that I want.
What should I do?/** Add User Role to Comments. */
if ( ! 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);
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( 'email', $authoremail );
$comment_user_role = $commet_user_role->roles[0];
$this->comment_user_role = ' ' . ucfirst($comment_user_role) . '';
} else {
$this->comment_user_role = '';
}
return $author;
}
function comment_author_role($author) {
return $author .= $this->comment_user_role;
}
}
new Comment_Author_Role_Label;
endif;
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- You must be logged in to reply to this topic.