Modifying the BuddyPress AdminBar

On UCalgaryBlogs, I’d modified the adminbar to include a link to the current site’s dashboard if a person was logged in, making it easy to get to the members-only side of WordPress without having to go through My Blogs and finding the right blog, then mousing over the pop-out “Dashboard” link. Most people never found that, and it’s not very intuitive.

So, I hacked in a hard-coded link to Dashboard in bp-core-adminbar.php. This worked, but meant I had to remember to re-hack the file after running a BuddyPress update. I forgot to do that right after I ran the last upgrade, and got emails from users asking WTF?

I decided to figure out the best way to add in the Dashboard link without hacking the actual plugin files. Turns out, it’s drop-dead simple. Yay, WordPress.

In your /wp-content/plugins/ directory, create a file called bp-custom.php (if it’s not there already), and drop this code into it:

<?php
  // custom functions for tweaking BuddyPress
  function custom_adminbar_dashboard_button() {
 	// adds a "Dashboard" link to the BuddyPress admin bar if a user is logged in.
 	if (is_user_logged_in()) {
 		echo '<li><a href="/wp-admin/">Dashboard</a></li>';
 	}
   }
  add_action('bp_adminbar_menus', 'custom_adminbar_dashboard_button', 1);
 ?>

When in place, your BuddyPress adminbar will look something like this:

BuddyPress-adminbar-modified

Yes, I know I should do something to properly detect user levels and privileges, rather than just providing the Dashboard link all willie-nillie to anyone that’s logged in, but the link itself just provides access to whatever Dashboard features the user is allowed to see, so there’s no security risk. Better to just say that a user can see the Dashboard for any site they’re logged into, and let WordPress deal with restricting access properly.

I should also deal with the possibility of WPMU being configured as a subdirectory vs. subdomain (the /wp-admin/ link will bork if you’re using subdirectories – better to use the real code to sniff out the base url of the current site…)

11 thoughts on “Modifying the BuddyPress AdminBar”

  1. Despite this being seemingly idiot-proof, it doesn’t work for me on WPMU 2.8.5.2 and BP 1.1.2 the file definitely has to be in /wp-content/, right?

    1. strange. The file goes in /wp-content/bp-custom.php – make sure the permissions on the file are set so that Apache can read it. I’m not sure what else would get in the way – those are the same versions I’m running. I’ll take a closer look when I get back to the office.

  2. Yes, that’s what I’ve got and I’ve doubled checked the code I copied over, too. No related errors in my logs either. Weird.

    root@lcerd01~ $ ls -l /var/www/vhosts/blogs/wp-content/
    total 108
    -rw-r–r– 1 apache apache 550 Oct 27 11:27 advanced-cache.php
    drwxr-xr-x 58 apache apache 4096 Nov 2 15:36 blogs.dir
    -rw-r–r– 1 apache apache 4207 Nov 3 09:54 blogs.php
    -rw-r–r– 1 apache apache 348 Nov 14 10:56 bp-custom.php
    drwxr-xr-x 4 apache apache 4096 Nov 14 14:58 cache
    -rw-r–r– 1 apache apache 30 Nov 3 09:54 index.php
    drwxr-xr-x 5 apache apache 4096 Nov 5 09:50 mu-plugins
    drwxr-xr-x 47 apache apache 4096 Nov 14 10:48 plugins
    drwxr-xr-x 2 apache apache 4096 Mar 18 2009 tarski
    drwxr-xr-x 99 apache apache 4096 Nov 5 14:30 themes
    drwxr-xr-x 2 apache apache 4096 Nov 14 10:48 upgrade
    drwxr-xr-x 5 apache apache 4096 Oct 14 15:31 uploads
    -rw-r–r– 1 apache apache 3391 Nov 5 16:20 wp-cache-config.php
    root@lcerd01~ $

  3. Using bp-custom.php didn’t work for me too in WPMU 2.8.5.2 and BP 1.1.2, so I just added the code into my custom theme’s functions.php and that got me what I wanted just fine 🙂 Thank you Norman.

      1. Doh! My bad! I was looking at the wrong directory when I wrote the path. Big-time screwup. Sorry!

        it’s definitely in /wp-content/plugins/bp-custom.php

  4. Thanks for sharing this mod. All works fine until I add buddypress-analytics. Like this mod, the analytics code is added to bp-custom.php:
    http://wordpress.org/extend/plugins/buddypress-analytics/
    This plugin is dependent on buddypress admin bar.

    All attempts to access the dashboard (/wp-admin and /wp-admin/index.php) result in a blank page when the analytics code is added (the dashboard will appear for a second and then go blank). ALL other admin pages work fine. Any thoughts as to what I need to do to get both analytics and the dashboard button to play nicely with each other?

  5. Update: My issue is not related to this AdminBar modification. I thought this was tested but it is now clear that the problem is isolated to the use of buddypress-analytics. When Analytics is used (with or without the AdminBar mod) the dashboard will begin to load and then result in a blank page. The Dashboard Button is working fine 🙂

Comments are closed.