Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Vladimir Garagulya

    (@shinephp)

    Do you wish to show role name of current user?

    Thread Starter JOHN2000

    (@john2000)

    Yes i have change the name of roles whith this plugin and now i want add the rolename to the comments! In addition to the name

    Plugin Author Vladimir Garagulya

    (@shinephp)

    global $current_user, $wp_roles;
    
      echo 'Current user role name: '. $wp_roles->role_names[$current_user->roles[0]];
    Thread Starter JOHN2000

    (@john2000)

    Nice but show all user as Administartor?

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Replace $current_user to the comment’s author user object, which you may get by his user_id:

    $user = get_user_by('id', $user_id);

    Thread Starter JOHN2000

    (@john2000)

    So?

    <?php global $user = get_user_by('id', $user_id);
    
      echo 'Current user role name: '. $wp_roles->role_names[$current_user->roles[0]]; ?>

    this not work!

    Plugin Author Vladimir Garagulya

    (@shinephp)

    This will not work as it does not have sense.
    You should get comment author value somewhere, possibly from the comment record. I suppose that you put into the $user_id variable.
    Then code will be looked like:

    global $wp_roles;
    
    // take comment author user ID somewhere. I suppose that you have comment record:
    $user = get_user_by('id', $comment->user_id);
    echo 'Current user role name: '. $wp_roles->role_names[$user->roles[0]]; ?>

    Thread Starter JOHN2000

    (@john2000)

    Thats work perfectly thank you!!!!!!!!!!!!!!!!!!!!

    is it possible add “Guest” to guest comments?

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Add conditional output:

    global $wp_roles;
    
    if (!empty($comment->user_id)) {
      $user = get_user_by('id', $comment->user_id);
      echo 'Current user role name: '. $wp_roles->role_names[$user->roles[0]];
    } else {
      echo 'Guest';
    }

    Thread Starter JOHN2000

    (@john2000)

    Tahnk you Work Perfect.

    Rostaman

    (@rostaman)

    Please Help, Tell me how to show in my account page all roles assigned to user, and how to exclude from whith list some roles?
    Thank you

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Code to show Role name?’ is closed to new replies.