Jefferson's Newspaper

A blog about information, education, and the (digital) humanities...

Tips for Using the WordPress Admin Bar with BuddyPress


If you run a WordPress Network that uses BuddyPress, you are probably aware of the distinctions between the WordPress and BuddyPress admin bars (or in the latter case, the “buddy bar”), so we can jump right to the point: You are no longer using the buddy bar, and are now using the core admin bar; there is something you don’t like about this arrangement and you need to change it. Well, here are a few quick tricks.

Each of these snippets (with one noted exception) can be added to functions.php of your main blog theme or you can create a simple plugin.

Swap the BuddyBar for the Admin Bar

If you somehow are still using the buddy bar, try one of the following methods. (You may also need to adjust your CSS slightly to accommodate the differences between the two admin bars.)

Here is the preferred BuddyPress method, which is simply added to wp-config.php:

/*
** Add the following to wp-config.php
** Removes BP admin bar and replaces it with the WP admin bar
*/
define( ‘BP_USE_WP_ADMIN_BAR’, true );

If for some reason you find that the above method does not work, you may try adding the following to functions.php

<?php
/*
** The following removes BP admin bar and replaces it with the WP admin bar
*/
 
function remove_bp_adminbar(){
     remove_action( 'wp_footer', 'bp_core_admin_bar', 8 );
     remove_action( 'admin_footer', 'bp_core_admin_bar');
     show_admin_bar(true);
}
add_action('after_setup_theme','remove_bp_adminbar');
?>

Remove something from the Admin Bar

To remove a menu item, you just need to know its HTML div id. This example removes the WordPress logo and menu. See remove_node().

<?php
/*
** The following removes the WordPress menu and logo
** wp-admin-bar-wp-logo is the div id in the menu HTML but we just use wp-logo 
** see http://codex.wordpress.org/Function_Reference/remove_node
*/
 
function admin_bar_remove_this(){
     global $wp_admin_bar;
     $wp_admin_bar->remove_node('wp-logo');
     }
     add_action('wp_before_admin_bar_render','admin_bar_remove_this');
?>

Adding something to the Admin Bar

Similarly, you can add a new menu item to an existing HTML div id. Here we are adding a link to create a new category within the +New menu. See add_node().

<?php
/*
** The following adds a link item to create a new "Category" within the "+New" menu
** wp-admin-bar-new-content is the div id in the menu HTML but we just use new-content 
** see http://codex.wordpress.org/Function_Reference/add_node
*/
 
function admin_bar_add_this(){
     global $wp_admin_bar;
     $newcat=get_site_url( BP_ROOT_BLOG ).'/wp-admin/edit-tags.php?taxonomy=category';
     $wp_admin_bar->add_node( array(
          'parent' => 'new-content',
          'title' => 'Category',
          'href' => $newcat) );
     }
add_action('wp_before_admin_bar_render','admin_bar_add_this');
?>

Make it Easier for Network Users to Create New Blogs

The BuddyPress dev team has added Notifications and some other BP-specific features to the admin bar, but the link to “Create a new site” is still missing as of v. 1.5.3 (UPDATE: actually, this would be a WP issue, not BP; track this issue here). If you have a very active community, especially one that routinely creates new sites (e.g. a university course blog network), they will notice this absence. To add another complication, BuddyPress redirects wp-signup.php to the network homepage, meaning the default WordPress Network mode method for creating a new site is broken (UPDATE: track this issue here). Luckily both of these are easy to fix.

<?php
/*
** The following adds a link to "Create a new site" under "My Sites" menu
*/
function admin_bar_create_blog_link(){
     global $wp_admin_bar;
     $create=get_site_url( BP_ROOT_BLOG ).'/blogs/create/';
     $wp_admin_bar->add_node( array(
          'parent' => 'my-sites',
          'title' => 'Create a new site',
          'href' => $create) );
}
add_action('wp_before_admin_bar_render','admin_bar_create_blog_link');
 
/*
** The following fixes the dashboard link for "Create a new site"
** By default, WordPress sends the user to wp-signup.php to create a site
** But wp-signup.php is redirected to the network homepage by BuddyPress as of 3.1+ and 1.5.3+ respectively
** This just filters that core behavior to use the BuddyPress link instead
*/
add_filter('wp_signup_location', 'bp_blog_creation_link');
function bp_blog_creation_link($old) {
     if (function_exists('bp_include'))
     return get_site_url( BP_ROOT_BLOG ).'/blogs/create/';
}
?>

Feel free to make additional suggestions in the comments.

Author:

Category: Reference

Tagged: , , ,

6 Responses

  1. Boone Gorges says:

    Your trick for using the WP toolbar instead of the BP admin bar will work, but we also have a special BP config flag for it. Put the following in wp-config.php:

    define( ‘BP_USE_WP_ADMIN_BAR’, true );

    If BP is redirecting registration links to the homepage, then something is wrong with your installation. At Network Admin > BuddyPress > Pages, have you associated ‘Register’ with a WP page?

    As for creating a new site, you’ll have to be more specific about which link you are talking about. If you mean the one at wp-admin/my-sites.php, then you’re right – I’d never noticed that before. You should submit your last filter as a feature enhancement at http://buddypress.trac.wordpress.org.

  2. E. Bell says:

    Yes, I’m talking about the link at wp-admin/my-sites.php.

    Will submit to Trac.

    The official define( ‘BP_USE_WP_ADMIN_BAR’, true ); does not seem to work in every situation. Not sure what’s going on with that but I’ve found it doesn’t make a difference (although admittedly, I added it a version or so back). In any case, though, I’ll update the post to be more clear.

    Thanks for having a look.

    EDIT: Submitted ticket
    http://buddypress.trac.wordpress.org/ticket/3941

  3. Tim says:

    Been looking for answer to the create site issue. But your code only works if you are on the main blog. If you have subdomain sites, you need the url to be the main site.

    This works:

    repalce get_bloginfo(‘url’)

    with

    get_site_url( BP_ROOT_BLOG )

  4. E. Bell says:

    Great catch, Tim. I’ve updated the post. Thanks.

  5. Tim says:

    No probs and I think it should be add_node not add_menu from 3.3.

    See http://codex.wordpress.org/Function_Reference/add_node

  6. E. Bell says:

    Ah, got me again. I see now that using add_/remove_node is the “preferred” method since 3.3. Thanks.

    This post has clearly been co-authored by the comments section :)

Leave a Reply