Skip to:
Content
Pages
Categories
Search
Top
Bottom

procedure for removing Admin Bar Sub Nav item

  • @mikepratt

    Participant

    There has been loads of help showing code for adding your own Admin Bar Nav/Sub Nav items.

    What is the procedure for removing an unwanted item from the list?

    Of course, I could just comment out the line of code but then I have an upgrade nightmare everytime the code base is updated.

    How would you write a filter or action to eliminate it in your own code? For example: I turned off the Blog creation capability yet the option still remains on the Admin Bar: My Account >> Blogs >> Create a Blog . It is already adding confusion and I want it gone.

    Thanks.

Viewing 10 replies - 1 through 10 (of 10 total)
  • @nicolagreco

    Participant

    in this case you should remove an action

    @anonymized-303747

    Inactive

    Mike, if you found out how to do it please share your solution. This is likely of interest to many others as well.

    @mikepratt

    Participant

    Nicola – I appreciate the tip, I do but now I have to answer a million other questions (most of us a novice hacks unlike yourself) So….remove what action? Where are all these actions? Are there any special considerations? Is there a general format for the function to create this action removal? I see stuff for the Admin Bar all over the place…member theme, bp-blogs, bp-core and it’s a wild goose chase to figure it all out. I assumed someone knew how to do a generic Admin bar item removal. Many Thanks

    @mikepratt

    Participant

    One final note: the actions look appropriate for removing top level nav items like “My Account”, etc but the Sub Nav items in MyAccount are created in a loop, as are their own Sub Nav items so you’d have to remove them from the source….which I am still looking for

    @burtadsit

    Participant

    Mike the idea is that if I want to change the function of a menu item, I have to replace the menu item with something of my own. I want to change “My Account” on the bar and add a new item underneath entitled: “I Owe Mike How Much!?”. I have to replace the entire “My Account” menu item since the granularity of the actions are at the top level menu item only.

    I can slide new menu items in between existing items easily but that’s the way it has to happen for drop down items.

    I create a plugin that runs in /mu-plugins since I want this to run all the time for all users on all blogs. It’ll get run every page load.

    An example is replacing the bp logo image in the bar. Same technique for other menu items. The item gets rendered through the function:

    bp_adminbar_logo() in bp-core-adminbar.php

    This function gets registered in mu by us telling mu about this function and when to trigger it:

    add_action( ‘bp-adminbar-logo’, ‘bp_adminbar_logo’ ) at the bottom of bp-core-adminbar.php

    To replace the logo with our own logo or do something completely diff like just use the word ‘Home’, whatever we unregister the existing fn, register our own that replaces the old fn and does something different. Like below:


    function oci_adminbar_logo() {
    global $bp;
    echo '<a href="' . $bp['root_domain'] . '"><img id="admin-bar-logo" src="' . apply_filters( 'bp_admin_bar_logo_src', site_url( MUPLUGINDIR . '/common-interest/images/oci_home.gif' ) ) . '" alt="' . apply_filters( 'bp_admin_bar_logo_alt_text', __( 'BuddyPress', 'buddypress' ) ) . '" /></a>';
    }

    remove_action('bp-adminbar-logo','bp_adminbar_logo');
    add_action('bp-adminbar-logo','oci_adminbar_logo');


    The above says “don’t pay any more attention to the function bp_adminbar_logo() when the action ‘bp-adminbar-logo’ occurs, pay attention to my oci_adminbar_logo() fn and do that instead.

    You have to replace the *entire* menu item with something of your own. Clearer? No?

    @mikepratt

    Participant

    Burt – sorry for the late reply – much much clearer – Thank you

    @rogercoathup

    Participant

    @burt:

    I’ve written a plugin (essentially your logo replacement code), and put it in the mu-plugins directory, but it doesn’t seem to be getting invoked?

    Am I missing something obvious?

    My file is called 2l2r-plugins.php and sits in the mu-plugins directory:

    <?php

    /*

    Plugin Name: l2r adminbar logo

    Plugin URI: http://www.21inspired.com

    Description: replaces the adminbar logo

    Version: 1.0

    Author: Roger Coathup

    Author URI: http://www.21thoughts.com

    */

    function l2r_adminbar_logo() {

    global $bp;

    echo '<img id="admin-bar-logo" src="' . apply_filters( 'bp_admin_bar_logo_src', site_url( MUPLUGINDIR . '/2l2r/images/l2r_home.gif' ) ) . '" alt="' . apply_filters( 'bp_admin_bar_logo_alt_text', __( 'BuddyPress', 'buddypress' ) ) . '" />';

    }

    remove_action('bp-adminbar-logo','bp_adminbar_logo');

    add_action('bp-adminbar-logo','l2r_adminbar_logo');

    ?>

    @burtadsit

    Participant

    Roger that fn I wrote was 3 months old. Things have changed in bp. All you need to do is add a filter to change the logo now.

    see: https://buddypress.org/forums/topic.php?id=1969&replies=2#post-10463

    Sorry for the late reponse. Your post got ‘spammed’ by akismet because of number of links in the post. The plugins in /mu-plugins don’t need a plugin header like that. Your code will translate better in the forums with backticks before and after.

    @rogercoathup

    Participant

    Burt, much appreciated… I’d found that other thread and implemented the filter.

    I’m now wondering whether to upgrade all my BP install; I’m working on files I downloaded about 3 months back.

    @burtadsit

    Participant

    It’s up to you of course Roger. There have been quite a few changes since RC1. Lots of new capabilities, you’ll have to run wpmu 2.7.1 beta. bp 1.0 is going to be out shortly here and the forums are going to get kinda nutty.

    It might be best to upgrade now instead of after 1.0 and get your eventual problems solved now. Heads up.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘procedure for removing Admin Bar Sub Nav item’ is closed to new replies.
Skip to toolbar