WordPress.org

Ready to get started?Download WordPress

Forums

Getting User Level (4 posts)

  1. Vladimir Prelovac
    Member
    Posted 6 years ago #

    I am writing a plugin that displays content only to admin user. To test if admin is logged in I trued using $user_level but the value I get is 0 instead of 10.

    This code:
    get_currentuserinfo() ;
    global $user_level;
    echo 'user level: '.$user_level;

    Will echo out 0 when admin is logged in.

    What am I doing wrong?

  2. Kafkaesqui

    Posted 6 years ago #

    Works fine for me.

    Note get_currentuserinfo() is not necessary; $user_level will already be available as a global var in the admin pages.

  3. Vladimir Prelovac
    Member
    Posted 6 years ago #

    It is not working for me.. But anyways, I just discovered I should be using

    current_user_can('level_10')

    for the same task.

    If I display all roles with wp_dropdown_roles() and user picks one (for example 'editor') how can I check later if the current user is 'editor'?

  4. Vladimir Prelovac
    Member
    Posted 6 years ago #

    Anyone please?

Topic Closed

This topic has been closed to new replies.

About this Topic