• Hello

    I’m a php noob, though can do some basic things.

    Is there a bit code that can be placed in the sidebar which can control whether a link for example, is displayed in the sidebar, depending of whether a user is logged in or has a certain Role (user level)?

    So for example, for a direct link to write post, this would be displayed if user is logged in. A check like this: If user = logged in, then…

    Or, if they only have Role of Contributor or above

    thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • I use this in my sidebar, it may get you started:

    <?php global $user_login; get_currentuserinfo();
    if ($user_login) :?>
    <li><a href="your-uri-goes-here/wp-admin/post.php">Write a New Post</a></li>
    <?php endif; ?>

    This puts a link in to the write post page if the user is logged in.

    Thread Starter snowcrash

    (@snowcrash)

    hi heyrsmith

    that worked great – just what I was looking for 🙂

    Would you happen to know what the php code is for a check on user level/role.
    So something like:
    If user = contributor or more, then…

    Can’t seem to find this kind of info in the docs

    thanks

    I have not poked around with 2.0 much – I only just performed my first 2.0 install a week ago. Your request is a good one though, and someone smarter is sure to answer. My guess is (and I am usually wrong about such things) is that it may be kind of tough as roles are simply “wrappers” for capabilities. They are not really hierarchical either in the sense that user levels were in 1.5, so it could really check for “role > X” either. Add to the mix that you can customize roles, add new ones and rename the ones you have it seems tough. Rumor is there are lots of roll-based plugins coming down the pipe though.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display link based on if Logged-in or Role in sidebar?’ is closed to new replies.