Support » Fixing WordPress » How to display comment author’s role

  • How to display the role of author of the comment posted? Just like this forum, If we are logged in we are displayed as Member.

    I want to display the role of people who commented but did not login as Guest

    The rest who commented who are logged in, display accordingly to their registered role:
    Administrator
    Editor
    Author
    Contributor
    Subscriber

Viewing 5 replies - 1 through 5 (of 5 total)
  • mrmist

    (@mrmist)

    Forum Janitor

    You’d have to write a custom callback for the wp_list_comments function as described in the codex article, to include the relevant code + html. http://codex.wordpress.org/Template_Tags/wp_list_comments

    can you show me a example of that?

    mrmist

    (@mrmist)

    Forum Janitor

    Try this web page to see if it helps.

    <?php
    function custom_comment($comment, $args, $depth) {
           $GLOBALS['comment'] = $comment; ?>
    <li <?php comment_class(); ?> id="comment-<?php comment_ID( ); ?>">
           <div class="avatar_cont"><?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?></div>
    Comment by <em><?php comment_author_link() ?></em>:
    <?php if ($comment->comment_approved == '0') : ?>
    <em>Your comment is awaiting moderation.</em>
    <?php endif; ?>
    <br />
    <small class="commentmetadata"><a href="#comment-<?php comment_ID() ?>" title="">
    <?php comment_date('l, F jS Y') ?> at <?php comment_time() ?></a>&nbsp;|&nbsp;<?php edit_comment_link('Edit','',''); ?></small>
    	<?php comment_text() ?>
    
    <?php echo comment_reply_link(array('before' => '<div class="reply">', 'after' => '</div>', 'reply_text' => 'Reply to this comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ));  ?>
    
    <?php } ?>

    I believe there’s no code to return the value of the role.

    mrmist

    (@mrmist)

    Forum Janitor

    This piece of code will tell you the role for a user with $userid

    <?php
    	$user_object = new WP_User($userid);
    	$roles = $user_object->roles;
    	$role = array_shift($roles);
    echo $role;
    ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to display comment author’s role’ is closed to new replies.