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:
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…)