WordPress.org

Support

Support » How-To and Troubleshooting » $user_level variable puzzle

$user_level variable puzzle

  • 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) { ?>

  • <h2><?php _e(‘Meta’); ?></h2>
  • <?php } ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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.

    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

    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

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

    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

    Thank you both! 🙂 I’ll try this out and report later if something went wrong. 😉

    Thanks again!

    John

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘$user_level variable puzzle’ is closed to new replies.