Support » Plugins » Conditionally hiding navigation links?

  • Resolved CharlesKrause


    I’ve done some searching, both online and here in the fora, and I’m uncertain how to do what I want 🙂

    What I’d like to do is hide/reveal a portion of the blog’s masthead, depending on whether or not the viewer is logged in as an admin, or not. I had hoped there might be a conditional tag the would do the trick, but I don’t think so. I’d like to do something like.

    if (is_admin())
    *block of code here*

    Basically I’d like to show/hide the “add post” link, as well as links to other software packages and control panels installed on my web server: things that *I* use, but no one else really needs access to.

    Anyone have any ideas?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Like this?

    Hmm… yes, thank you 🙂

    I may have to hack it to add my own custom links to it as well – but that probably can be done 🙂

    Yeah, I thought you might take a peek at the code…

    here’s a quick function i knocked up for you that should return true or false depending if $userRole matches $role that is set.

    function pky_dirtyRoleCheck($id,$role='admin'){
    global $wpdb ;
    $userRole = $wpdb->get_var("SELECT meta_value FROM $wpdb->usermeta WHERE user_id = '$id' AND meta_key='wp_capabilities'");
    return true;
    } else {
    return false;

    So just set $id to the current user id and $role to the role you are trying to find!

    this will only work on WP2.0 and up!

    Please note ive not tested it 😀 just hacked it from my own personal userProfile plugin i use on my sites

    Thanks for the code 🙂

    Actually, I used the plugin, and just manually added in the paths to the applications on my server in the source code, as it is only ever going to be me that uses those links, and I’m going to be the only admin (or author) on that blog 🙂

    I’m leaving a comment, just so I’ll find this later. I’ll be coding some role based custom menus and such. Thanks for the starting place.

    Ive just checked over my post again, and it wont actual work as it would be checking against as serialized array string.

    you would need to unserialize($userRole) and check against the role feild in the array

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Conditionally hiding navigation links?’ is closed to new replies.