WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get user role works only for administrator. (1 post)

  1. StefanRisticDev
    Member
    Posted 1 year ago #

    Hello everybody!

    I'm trying to modificate "Members directory" plugin, so it shows up user role along with website/name/bio.

    Here is my code:

    Get user id:

    $user_idd = $user_details->ID;

    Get role of that user:

    $user_current = new WP_User( $user_idd );
    $role_container = $user_current->roles;

    Display user role:

    $content .= '<strong>' . __('Rank') . '</strong>: ' . $role_container[0] . '<br />';

    The problem is that this code for some reason works only for administrator. When I go to members page and choose administrator, I'm getting "Rank: administrator", but when I choose contributor or subscriber profile, I'm getting "Rank: "(empty string).

    You can check it here:
    http://globelaw.info/contributors/

    Any ideas ?

    Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic