Skip to:
Content
Pages
Categories
Search
Top
Bottom

Admin Bar Menu Editing

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi,
    Are you sure your $current_user already has data at that moment ?

    Just before your if statement, try to run
    get_currentuserinfo();
    And just to make a quick test, you could always echo the ID just after running the above function to verify
    echo 'User ID: ' . $current_user->ID . "\n";
    Pascal.


    wafflecloud
    Participant

    @wafflecloud

    Foremost I thank you for your assistance , you totally rock because it actually works now!

    Now my follow up question is a bit dumb but how would I include multiple admin user IDs?

    Hi,
    No dumb questions here…

    As you might have seen in your database, the ID field is a bigint, so to continue on the IF that you used, you could go for:

    $myadmins = array(1, 2); // Add all IDs of the admins in this array
    if ( !in_array($current_user->ID, $myadmins) ) {

    Pascal.


    wafflecloud
    Participant

    @wafflecloud

    That worked beautifully! You totally and completely rock….HARD!
    A huge thank you! I wish there was a button I could click to thank you with or something but all I can think to do is share my code so it can help others / hopefully prevent you from having to answer the same question again.

    Here is what I put to make it work:

    <?php
    function annointed_admin_bar_remove() {
            global $wp_admin_bar, $current_user;
            get_currentuserinfo();
    $myadmins = array(1, 3); // Add all IDs of the admins in this array
    if ( !in_array($current_user->ID, $myadmins) ) {
            $wp_admin_bar->remove_menu('wp-logo');          // Remove the WP Logo Menu
            $wp_admin_bar->remove_menu('site-name');        // Remove the site name menu
            $wp_admin_bar->remove_menu('view-site');        // Remove the view site link
    }
    }
    
    add_action('wp_before_admin_bar_render', 'annointed_admin_bar_remove');
Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar