Skip to:
Content
Pages
Categories
Search
Top
Bottom

I need a PHP code IF user-level

  • Avatar of Tiago
    Tiago
    Member

    @tiagobeloto

    Hello everybody, okay? I love the BuddyPress and use it on my site it’s been a year. I am also looking for a long time ago if php code. I do not know php programming, but I always find a way to try to resolve things. If I need an id for each user displayed. example:
    I have 3 users on my network. 1 is the administrator (me), level 10. Is a subscriber level 0 and the other author-level 9 (I think it is 9). This code would show if a text, “Administrator”, for example, only for the users level 10 and so on. And I would view this code in the header-member or elsewhere in the profile of each user. Then, the user level 0 appear “User” and while the level 9 appear “Author” in your profile.

    I know that was kind of big post because it’s kind of hard to explain. I ran the search and google, but did not. The codes found in the WP codex did not work …
    I await answers, please help me. Hugs to all!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Are you using a plugin to create your user levels? If so, which one? WordPress supports roles and capabilities for users by default, but doesn’t have numeric levels.

    If s2member have a look at their documentation for if queries on member level.

    Avatar of meg@info
    meg@info
    Participant

    @megainfo

    hi,,

    global $current_user;
    get_currentuserinfo();
    $userLevel = $current_user->wp_user_level;

    switch ($userLevel){
    //http://codex.wordpress.org/Roles_and_Capabilities
    case 0: $_SESSION = 2; break; // member
    case 1: $_SESSION = 2; break; // Contributor
    case 2: $_SESSION = 1; break; // author
    case 3: $_SESSION = 1; break; // author
    case 4: $_SESSION = 2; break;
    case 5: $_SESSION = 2; break;
    case 6: $_SESSION = 2; break;
    case 7: $_SESSION = 2; break;
    case 8: $_SESSION = 0; break;
    case 9: $_SESSION = 0; break;
    case 10: $_SESSION = 0; break; // admin
    default: $_SESSION = 3; // guest
    }

    and read this http://codex.wordpress.org/Roles_and_Capabilities

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    User levels were replaced by roles in WP 2.0, and were deprecated in 3.0 — so, checking wp_user_level and such like shouldn’t be relied on

    http://codex.wordpress.org/User_Levels

    Avatar of Tiago
    Tiago
    Member

    @tiagobeloto

    @rogercoathup I do not use any plugin for user levels and permissions. I only gave examples of levels. I’d like an If with an elseif and else to levels. If you are an administrator, a text appears: “Administrator” or is Editor, a text appears: “Editor” and if is a subscriber, you may see “Member” or simply any message.

    Avatar of Tiago
    Tiago
    Member

    @tiagobeloto

    @rogercoathup and @djpaul can you help me with this my reply: ” I do not use any plugin for user levels and permissions. I only gave examples of levels. I’d like an If with an elseif and else to levels. If you are an administrator, a text appears: “Administrator” or is Editor, a text appears: “Editor” and if is a subscriber, you may see “Member” or simply any message.”

    Avatar of Tiago
    Tiago
    Member

    @tiagobeloto

    … and this code if is not for current logged user, is for displayed user. Thanks!!!

    Avatar of Roger Coathup
    Roger Coathup
    Participant

    @rogercoathup

    Here is an example of how to check a user’s role: http://www.peterrknight.com/get-wordpress-user-role-by-id/

    You can also look at this WordPress page for more information on user roles: http://codex.wordpress.org/Roles_and_Capabilities

Viewing 7 replies - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.