WordPress.org

Ready to get started?Download WordPress

Forums

How to display comment author's role (6 posts)

  1. ShadowArts
    Member
    Posted 5 years ago #

    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

  2. mrmist
    Forum Janitor
    Posted 5 years ago #

    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

  3. ShadowArts
    Member
    Posted 5 years ago #

    can you show me a example of that?

  4. mrmist
    Forum Janitor
    Posted 5 years ago #

    Try this web page to see if it helps.

  5. ShadowArts
    Member
    Posted 5 years ago #

    <?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.

  6. mrmist
    Forum Janitor
    Posted 5 years ago #

    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;
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.