نمایش نقش کاربر در دیدگاه های وردپرس

شما میتوانید در دیدگاه های سایت وردپرس خود یک فرقی بین نویسندگان ، مدیران و سایر نقش ها ایجاد نمایید . بصورتی که مثلا اگر مدیری نظری در مطلب درج کرد ، در کنار نام کاربری او نوشته شود مدیر کل یا همینطور برای سایر نقش ها .
برای نمایش نقش کاربر در دیدگاه ابتدا باید کد زیر را در functions.php قالب خود قرار دهید
if ( ! class_exists( 'a4fran3_Comment_Author_Role_Label' ) ) :
class a4fran3_Comment_Author_Role_Label {
public function __construct() {
add_filter( 'get_comment_author', array( $this, 'a4fran3_get_comment_author_role' ), 10, 3 );
add_filter( 'get_comment_author_link', array( $this, 'a4fran3_comment_author_role' ) );
}
// Get comment author role :A4Fran3.IR
function a4fran3_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 a4fran3_comment_author_role($author) {
return $author .= $this->comment_user_role;
}
}
new a4fran3_Comment_Author_Role_Label;
endif;
سپس کد زیر را در Style.css قرار دهید
.comment-author-label {
padding: 5px;
font-size: 14px;
border-radius: 3px;
}
.comment-author-label-editor {
background-color:#efefef;
}
.comment-author-label-author {
background-color:#faeeee;
}
.comment-author-label-contributor {
background-color:#f0faee;
}
.comment-author-label-subscriber {
background-color:#eef5fa;
}
.comment-author-label-administrator {
background-color:#fde9ff;
}












