WordPress.org

Ready to get started?Download WordPress

Forums

display user role on profile page (6 posts)

  1. AARONDAS
    Member
    Posted 3 years ago #

    Hello,

    On my blog I am creating a directory using "members list", I also have role manager installed, and I have created a author.php page. I would like to display on the profile page:

    Your role is: <user_role>

    I was wondering if anyone know of a way that I can display the current role, either one of the default roles or 'role manager' roles on the profile page.

    Thank you, and I appreciate your help,
    Aaron

  2. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    I use this snippet in my BNS Support plugin to show the current user's role which may accomplish what you are looking for:

    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    echo '<strong>Current User Role</strong>: ' . $user_role;

    It will only show the first role if the user has more than one assigned to them.

  3. AARONDAS
    Member
    Posted 3 years ago #

    Edward,
    This worked great, but I was wondering if you know how I can add this to my members list directory. I can display the wp_user_level in the list, but for some reason I can't display the wp_capabilities.

    Do you know how this can be done?

    Thanks,

    Aaron

  4. Edward Caissie
    Theme Review Admin
    Posted 3 years ago #

    I would suggest looking at this page in the codex: http://codex.wordpress.org/Function_Reference/get_userdata

  5. ibadullah
    Member
    Posted 2 years ago #

    How to make the first letter capital of user role?

  6. sedemik
    Member
    Posted 2 years ago #

    For example

    <?php
    $user_roles = $current_user->roles;
    $user_role = array_shift($user_roles);
    
    if ($user_role == 'administrator') {
    echo 'Administrator';
    } elseif ($user_role == 'editor') {
    echo 'Editor';
    } elseif ($user_role == 'author') {
    echo 'Author';
    } elseif ($user_role == 'contributor') {
    echo 'Contributor';
    } elseif ($user_role == 'subscriber') {
    echo 'Subscriber';
    } else {
    echo '<strong>' . $user_role . '</strong>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic