Forums

Get a user's role by user ID (in comments) (6 posts)

  1. NotAlame
    Member
    Posted 3 months ago #

    Hi!
    I'm using this function to display the author role:
    http://core.trac.wordpress.org/attachment/ticket/5290/author-template-the_author_role.diff

    function get_the_author_role() {
    	global $wpdb, $wp_roles, $authordata;
    
    	if ( !isset($wp_roles) )
    		$wp_roles = new WP_Roles();
    
    	foreach($wp_roles->role_names as $role => $Role) {
    		$caps = $wpdb->prefix . 'capabilities';
    		if (array_key_exists($role, $authordata->$caps))
    			return $Role;
    	}
    }
    
    /**
     * Echo the account role of the author of the current post in the Loop.
     * @see get_the_author_role()
     * @return null
     */
    function the_author_role() {
    	echo get_the_author_role();
    }

    (founded here)

    and now, I would like to display the author role on comments (like on this wordpress support site); when using this function, it show the same role for all comments ( because it's in reality the role of the author of the commented post).
    What can I do?

    Thanks

  2. esmi
    Member
    Posted 3 months ago #

    Not sure what you mean by the author role in terms of the comments. Can you elaborate a little?

  3. NotAlame
    Member
    Posted 3 months ago #

    I mean I want to show the comment author role behind his username on comments... so every comment will have the username and just after, "this user is author" (for exemple)

  4. esmi
    Member
    Posted 3 months ago #

  5. NotAlame
    Member
    Posted 3 months ago #

    Thanks for your answer...
    But, can you help me with this "get_userdata " because I'm not so good on programming on wordpress...

    Thanks

  6. NotAlame
    Member
    Posted 3 months ago #

    up ?

Reply

You must log in to post.

About this Topic