WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Conditionally hiding navigation links? (8 posts)

  1. CharlesKrause
    Member
    Posted 8 years ago #

    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*
    }
    endif;

    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?

  2. yosemite
    Member
    Posted 8 years ago #

    Like this?

    http://mattread.com/archives/2004/09/wp-admin-bar/#more-148

  3. CharlesKrause
    Member
    Posted 8 years ago #

    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 :)

  4. yosemite
    Member
    Posted 8 years ago #

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

  5. Phunky
    Member
    Posted 8 years ago #

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


    <?php
    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'");
    if($userRole==$role){
    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 :D just hacked it from my own personal userProfile plugin i use on my sites

  6. CharlesKrause
    Member
    Posted 8 years ago #

    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 :)

  7. manstraw
    Member
    Posted 8 years ago #

    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.

  8. Phunky
    Member
    Posted 8 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic