WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] $user_level question (8 posts)

  1. ringostar
    Member
    Posted 6 years ago #

    I understand that 0 = subscriber and 1= contributer but for some reason this code

    >= 0 allows users not registered or logged in to view content

    shouldn't this only be for those logged in ?

  2. MichaelH
    Member
    Posted 6 years ago #

    Not too sure what you are trying to accomplish--but you can use this to determine if user is logged in:

    <?php
    global $user_login;
    if( $user_login ) :
    ?>
    
    <?php your_code_blah_blah_blah; ?>
    
    <?php endif; ?>
  3. ringostar
    Member
    Posted 6 years ago #

    is it possible to list by user role ?

    ie

    if ( customrole1, customrole2, customrole3 )

    i have these all set to zero and just use the roles themselves

  4. MichaelH
    Member
    Posted 6 years ago #

  5. ringostar
    Member
    Posted 6 years ago #

    unfortunately, that code is for listing a role, I'm looking for a hook to use for access purposes, am trying to stay away from having to enter a user level # since they are each level 0

    ie

    customrole1 > can see

    this

    else

    everybody else

    end

  6. MichaelH
    Member
    Posted 6 years ago #

    I believe some plugin authors use 'capabilities' to test.

    if (current_user_can('import'))

    so guessing this might work:
    if (current_user_can('level_2'))

    Resource:
    Roles and Capabilities

  7. ringostar
    Member
    Posted 6 years ago #

    yea what i did was create a bogus capability and used the current_user_can worked beautifully thanks :)

  8. Clicknathan
    Member
    Posted 6 years ago #

    Can you explain this in a little more detail?

    Once you create a capability, how do you know what it's name is?

    I mean, I know that I give it a name, but if I create a capability how do I know what to put in the 'level_2' area as noted here:

    if (current_user_can('level_2'))

    I tried putting in the obvious, the name of what I was doing, but that didn't work. :(

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.