WordPress.org

Ready to get started?Download WordPress

Forums

Admin Link Menu Bar only visible to Admin (6 posts)

  1. kayaker
    Member
    Posted 10 years ago #

    Has anyone done something like this with their WP?
    I'm looking to put a link on my menu that is titled Admin, linked to wp-admin, that only shows up when the Admin is the one logged in.

  2. chuckg
    Member
    Posted 10 years ago #

    Put this is your my-hacks.php:
    function is_admin () {
    global $user_level, $siteurl;
    get_currentuserinfo();
    if ($user_level >= 9) { // admins, plus site op
    return true;
    } else {
    return false;
    }
    }
    Then where you want the link, do something like:
    is_admin() ? print "admin link stuff" : "";
    or
    if (is_admin()) { print "admin link stuff";}
    ...whichever you're more comfortable working with.

  3. riddlu
    Member
    Posted 8 years ago #

    Ok, I've got some problems using chuckg's solution.

    I put this function into my-hacks.php, activated it in wordpress's backend and put file into blog root directory.

    function is_admin () {
    global $user_level;
    get_currentuserinfo();
    if ($user_level == 10) { return true; }
    else { return false; }
    }

    I try to summon it in sidebar.php:

    <?php if (is_admin()) { echo '<ul><li>'; wp_loginout(); echo '</li><li><a href="/blog/wp-admin/">Admin Panel</a></li><li><a href="/blog/wp-admin/post.php">Add post</a></li><li><a href="http://stat.4u.pl/?******">Stats</a></li></ul>'; } ?>

    And at the top of my blog whole function appears, shifting rest of content.

    Can you probably help me with other, easier solution? Sth similar to smarty-like <ADMIN_BLOCK></ADMIN_BLOCK>. Or help to debug that function / way of using it.

  4. Beel
    Member
    Posted 8 years ago #

    There is not an easier solution. You will have to place it in a spot and style it so that it does not cause the shift if it matters to you (it wouldn't to me since I am the only one that would see the shift). I use something similar in all my sites (like adding a themeswitcher to test changes before going "live").

  5. riddlu
    Member
    Posted 8 years ago #

    But I dont' understand why content of function is_admin apears on the site. Why it is visible, instead of be parsed by PHP and used in conditional statement in sidebar.

    Can you copy&paste me your function hiding content from non-admin and non-user, and way of using it?

  6. mikeorb
    Member
    Posted 8 years ago #

    kayaker, you must wrap your function is_admin () { ... declaration inside of <?php ... ?> or it will just be interpreted as HTML.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.