WordPress.org

Ready to get started?Download WordPress

Forums

$user_level variable puzzle (8 posts)

  1. pebdakota
    Member
    Posted 9 years ago #

    I tried using this code to make a sidebar menu only visible to a certain user level, but it seems like $user_level won't do the trick, even when a user is logged in at the admin level. I tried echoing the $user_level variable; it's either empty or null - it doesn't show anything. An example of what I tried is posted below. Can anyone spot an error in what I'm doing?

    Thanks,
    PEB

    <?php if ($user_level >= 5) { ?>

  2. <h2><?php _e('Meta'); ?></h2>
  3. <?php } ?>

  • ColdForged
    Member
    Posted 9 years ago #

    Make certain to reference the global $user_level variable before accessing it. Right above that, try adding:

    <?php global $user_level; ?>

    and see if it helps.

  • jowra
    Member
    Posted 9 years ago #

    I have a similar problem. In WP 1.5 I've written some simple lines of code to hide postings from visitors which are not logged in. This was done via

    get_currentuserinfo();
    if ( $user_level > 0 ) : ...

    Since get_currentuserinfo(); is now (Wp 1.5.1.) defined in the pluggable-functions.php, I've included this file first and then comes the rest as usual. But the test of $user_level didn't work. If I make an echo $user_level it works fine, but the test (> 0, or anything else) won't work anymore.

    Any ideas on how to resolve this? Or is there any simple solution to check if a user is logged in, in WP 1.5.1.?

    Thanks in advance.

    John

  • eyetag
    Member
    Posted 9 years ago #

    looking for the same feature, need to customize wp to show pages accordingly to $user_level. who knows more? any difference between 1.5 and 1.5.1.?

    thanks for any hint!
    et

  • jowra
    Member
    Posted 9 years ago #

    No ideas? No one sharing the same problem and maybe has an solution? *argh*

  • Minna
    Member
    Posted 9 years ago #

    Well, no idea really, but I'm using this to hide theme switcher for everyone but me:
    <?php get_currentuserinfo(); global $user_level; if ($user_level > 9) { ?>
    stuff here
    <?php } ?>

    I used it in 1.5 and haven't noticed anything odd in 1.5.1. I got the code off some thread in these forums but of course I forget which

  • skippy
    Member
    Posted 9 years ago #

  • jowra
    Member
    Posted 9 years ago #

    Thank you both! :) I'll try this out and report later if something went wrong. ;)

    Thanks again!

    John

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags

    No tags yet.