Adding Your Plugin’s Link to the BuddyPress Member Toolbar Menu
If you’ve added a new navigation item to the single Member page, you may want to add the same link to the Toolbar Menu.
Let’s say you added a tab called ‘Dogs’ – this will add the same link to the Toolbar Menu.
Put it in the same file that adds your tab on the Member page.
Or put it in your theme’s functions.php or bp-custom.php or your plugin file.
function your_bp_admin_bar_add() { global $wp_admin_bar, $bp; if ( !bp_use_wp_admin_bar() || defined( 'DOING_AJAX' ) ) return; $user_domain = bp_loggedin_user_domain(); $item_link = trailingslashit( $user_domain . 'dogs' ); $wp_admin_bar->add_menu( array( 'parent' => $bp->my_account_menu_id, 'id' => 'my-account-dogs', 'title' => __( 'Dogs', 'your-plugin-domain' ), 'href' => trailingslashit( $item_link ), 'meta' => array( 'class' => 'menupop' ) ) ); // add submenu item $wp_admin_bar->add_menu( array( 'parent' => 'my-account-dogs', 'id' => 'my-account-dogs-poodles', 'title' => __( 'Poodles', 'your-plugin-domain' ), 'href' => trailingslashit( $item_link ) . 'poodles' ) ); } add_action( 'bp_setup_admin_bar', 'your_bp_admin_bar_add', 300 );
To remove an item from the Toolbar Menu, for example: activity, place this code in one of the locations mentioned above:
function your_bp_admin_bar_remove() { global $wp_admin_bar; $wp_admin_bar->remove_menu( 'my-account-activity' ); } add_action( 'bp_setup_admin_bar', 'your_bp_admin_bar_remove', 301 );
To find out what should go in the remove_menu argument, look at the browser code generated for the Toolbar. For ‘Activity’, it looks like this:
<li id="wp-admin-bar-my-account-activity" class="menupop hover">
So you want everything after ‘wp-admin-bar-‘ for whatever item you’d like to remove.