• Hello

    Im trying to print the second role of the current user logged in, but $wp_roles wont work.

    This is my code:

    $user = wp_get_current_user();
    $role = $user->roles[1];
    $role_name = $wp_roles->roles[$role]['name'];
    echo $role_name
    

    Why will it not work? And what can I do instead?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author WillBontrager

    (@willbontrager)

    Information about the inability to use variables that exist outside the tags of the Insert PHP code is at
    https://www.willmaster.com/software/WPplugins/insert-php-wordpress-plugin-instructions.php#inandofitself

    The page also has other information that may be of interest.

    Because I’m not familiar with the project, I’m unprepared to recommend what to do instead. Sorry.

    Will

    • This reply was modified 7 years, 3 months ago by WillBontrager. Reason: clarification
    Thread Starter arr0w

    (@arr0w)

    Hi Will

    Thank you for the quick reaction to my question.
    The page did give some information of interest, but not what I was looking for.

    To be very specific:
    I want to put the displayname of the second role of a currently logged in user into a variable. Like I’ve done above. Then I can use the variable in some shortcodes afterwards. Do you know another way to do this?

    Plugin Author WillBontrager

    (@willbontrager)

    Sorry, I don’t know how to do that within the constraints of Insert PHP.

    Will

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wp_roles not working’ is closed to new replies.