As promised at Wordcamp Toronto 2009, I’m pleased to annouce the launch of b5media Labs! Moving forward, this will serve as our test bed for new ideas and technology demonstrations and as our resource to talk about some of the stuff we’re doing or have done with all of you!
Also as promised, in this first post I will re-outline my Wordcamp presentation on integrating Wordpress MU, bbPress and buddyPress and go into a little more detail from a code perspective.
Step 1: Software
The first step is to install all of the various software components. We are using three software programs: Wordpress MU, bbPress and buddyPress. All three are from Automattic or a derivative of the Wordpress code base so fortunately for Wordpress developers, there’s already an inane level of familiarity there. So go ahead and set up all of the different software packages.
Wordpress MU is a pretty straight forward install. While there are plans to port buddyPress over to a single install of Wordpress (the two code bases are actually merging), for now we need to run Wordpress MU. Of course Wordpress MU can run just like a single Wordpress install, you just need to disable users signing up for their own blogs.
buddyPress will get installed info the plugins directory and requires setting up a few extra directories, but is also relatively straight forward (don’t forget to read the readme.txt file).
Finally, install bbPress into a subdirectory (ie. yourblog.com/community) under your Wordpress install.
When installing bbPress, be sure to configure it to share usernames between Wordpress and bbPress. They’ve made this a surprisingly easy part of the installation.
Step 2: Customization
Fortunately for those who have Wordpress experience, the buddyPress and bbPress templating system should be nothing new. Even if you have no experience with templating these systems, if you have PHP experience, it should be realtively easy to get up and running.
There isn’t too much to talk about under this category, but I would love to point to a couple of important things to note:
If you’re wrapping your buddyPress install in the same header/footer as your Wordpress install, you’ll need to copy all of the dependencies over into buddyPress’s theme directory (CSS, images, etc.) This is because buddyPress overwrites the return values of the theme directory functions. So while it uses the exact same functions, it reroutes all theme specific file to wp-content/bp-themes.
For bbPress, if you want to use the same header/footer files, you can just copy the header.php and footer.php into your bb-templates/[theme] directory. However, you’ll need to import the Wordpress functions into bbPress. So you’ll need to add the following lines to your bb-config.php file. Note: Do not attempt to make this fix before bbPress is installed. It doesn’t like it.
After the line “define(’BB_LANG’, ”);” include the following code (pun intended):
// Include Wordpress functionality $currDir = dirname(getcwd());
// Make sure this isn't install or admin (go up if it is)
if(!file_exists("$currDir/wp-blog-header.php"))
$currDir = dirname($currDir);
if(!file_exists("$currDir/wp-blog-header.php"))
die("Cannot find Wordpress integration files.");
require_once("$currDir/wp-blog-header.php");
This ensures that the Wordpress functions are available to you inside bbPress. bbPress works surprisingly well with this (in terms of lack of function names colliding, etc.).
That’s pretty much it for theming. So much for the good and the bad… you know what comes next.
Step 3: Integration (The Ugly)
This is ugly mostly because there are so many points where we can integrate these three solutions together. In this overview, we’ll go through including the “buddy bar” in bbPress and linking to buddyPress user profiles to replace bbPress’s rather lacking user profiles.
The “Buddy Bar”
Getting the buddyPress admin bar which shows up in Wordpress to show up in bbPress can be tricky. This usually comes in two parts. First, including the code above for customization. This will include all of the Wordpress hooks, filters, and most importantly plug-ins. Second, we need to make some theme changes. First, go into wp-content/buddypress/bp-core/bp-core-admibar.php and at the bottom, you’ll find a hook for wp_footer. We’re going to replace that line with the following:
add_action( 'bp_footer', 'bp_core_admin_bar', 8 );
As you can see, we’re replacing wp_footer with bp_footer, giving it it’s own action. Now, in your footer.php file in your Wordpress theme, where it currently calls do_action(’wp_footer’), you’ll need to add the following line after it:
do_action('bp_footer');
Now that that’s all done, it’s a simple matter of adding that same line to the bottom of your footer.php in your bbPress template. Simply find the line which calls do_action(’bb_foot’); and add the following line below it:
do_action('bp_footer');
You should now have the buddyPress bar in your bbPress installation!
Profile Linking
Profile linking is troublesome. There are two cases to consider: 1) You’re viewing a user’s profile and 2) You’re administering a user profile. This is easiest to do in a plug-in, and I have created one which you can download here. You can unzip the file inside into your bb-plugins directory and activate it from you bb-admin panel. Allow me to explain the code.
add_filter('get_user_profile_link', 'bppro_user_profile_link', 10, 2);
/* FUNCTIONS */
function bppro_user_profile_link($link, $uid) {
if(BB_IS_ADMIN || (isset($_GET['tab']) && ($_GET['tab'] == 'edit')))
return($link);
$user = bb_get_user($uid);
return(get_option('siteurl').'/members/'.$user->user_login);
}
As you can see, we’re simply replacing the link to their profile page with a link to their buddyPress member’s page, but only in specific cases. Note: if you changed the buddyPress member slug to something else, you’ll need to reflect that change here.
Step 4: Continue
Hopefully these code snippets and examples of what we’ve done have inspired you to think of new and creative ways to integrate these platforms into your own site. Every site can and should leverage these easy to use and learn programs to expand on the defaults given by Wordpress. buddyPress delivers full profiles as opposed to Wordpress’s Name/E-mail/Comment paradigm. bbPress also helps to break away from Wordpress’s typical Author -> Commentor relationship, allowing user contributed conversations and discussions to branch off in any direction.
Together the combination of these solutions is sure to build on top of any site’s popularity and usefulness.
