Change WordPress user roles and capabilities Forums How to or FAQ Show user role after name in frontend

Tagged: ,

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #4919
    csoftintl
    Participant

    On my website, I have a document management system that will show the edit history of a particular page. I would like to show, next to each user’s name, a small indicator if that person is an editor or admin, for example.

    Could this be done in any way, perhaps using ure_role_additional_options and add a CSS class on the user’s name?

    #4922
    Vladimir
    Keymaster

    You need to change the template which outputs user’s name, add user’s roles there using a function like below. It returns the string of comma separated user roles by user ID:

    
    function get_user_roles($user_id) {
    
        $wp_roles = wp_roles();
        $user = get_user_by('id', $user_id);
        
        $roles = array();
        foreach ($user->roles as $role_id) {
            $roles[] = $wp_roles->role_names[$role_id];
        }
        
        $roles_str = implode(', ', $roles);
    
        return $roles_str;
    }
    
    #4924
    csoftintl
    Participant

    thank you I will see what I can do with your suggestion

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.