• I have three custom roles. Each custom role has it’s own custom permission or ‘Capability’. I’m trying to show/hide menu items in header.php based on their role. I’m using similar code from your suggestion above, but it’s not working. The End User role has the role_enduser permissions and the Partner role has role_partner permissions. Users have to be logged in to see this page. I can confirm that the users have the correct roles and each role has the correct permissions in the admin. Can you help?

    <? php if ( current_user_can( 'role_enduser' ) ) { ?>
    I'm an End User
    <? php } else if ( current_user_can( 'role_partner' ) ) { ?>
    I'm a Partner
    <? php } ?>

    https://www.ads-software.com/plugins/user-role-editor/

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

    (@shinephp)

    How can WordPress know what role does user have, if user did not log in?
    I confirm that user should login 1st. In other case current_user_can(‘something’) returns false.

    Thread Starter Dap1

    (@dap1)

    Sorry if that was not clear, but users have to be logged in to see this page. They are in fact logged in. This still doesn’t work when they’re logged in.

    Thread Starter Dap1

    (@dap1)

    Any help Vladimir? The users are logged in and this still isn’t working.

    Plugin Author Vladimir Garagulya

    (@shinephp)

    Try to add this test output

    global $current_user;
    echo $current_user->user_login.'<br>';
    print_r($current_user->roles);
    echo '<br>';

    before your code to check what the current user really is at that point.

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