• 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.

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

    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.

    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”).

    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?

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

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Admin Link Menu Bar only visible to Admin’ is closed to new replies.