If you’ve ever installed bbPress you know that it supports several different levels of integration with an existing WordPress blog. By default you can integrate cookies, users, and even have access to WordPress functions. After all of this, however, the user will still experience two independent applications. Most likely the themes you are using were not made with each other in mind. This doesn’t have to be the case, and if you’re willing to get your hands dirty you can get your bbPress installation to look and feel as if it is entirely a part of WordPress. Here is an example of what this looks like: Example.
To begin, you will need to install (or modify) bbPress with full WordPress integration. This means cookie, database, and functional integration (add require_once(‘path/to/wp-blog-header.php’); to your bb-config.php for functional integration). I did this with WordPress 2.7.1 and bbPress 1.0 alpha, however, if you prefer to use the stable version of bbPress, you can find information on how to do this Here.
Once everything is installed its time to get your hands dirty. To go further we’re going to have to make a few changes to the code. Locate your theme directory. I used the default Kakumei theme. Keep in mind that a large portion of your bbPress theme is going to be stripped out (header, footer, sidebar) so don’t spend to much time selecting a theme. After you locate the directory of your current theme, you’ll need to do a search and replace through every .php file in your theme. There are several files so I suggest you use a program to do this for you; Notepad++ allows you to search and replace across multiple files.
You’ll need to do two searches:
Find:
bb_get_header();
Replace with:
global $is_bb; $is_bb = true; get_header();
get_header(); will cause bbPress to use WordPress’ header as opposed to its own. I added the additional code global $is_bb; $is_bb = true; you’ll see why later. You’ll need to do the same thing for the footer as well.
Find:
bb_get_footer();
Replace with:
get_footer();
Now that that’s done, upload the files and take a look at your forum. You should see the body of your forum embedded inside your wordpress theme. You should also notice that your forum looks pretty terrible. Don’t worry we’ll fix this in the next step.
What we need to do next is tell your wordpress theme to use your bbPress stylesheet if we are viewing the forum. This is where that additional code I added comes in. In your WordPress theme’s header file add the following lines before the first stylesheet is linked (ie before the first <link rel=”stylesheet”…):
<?php global $is_bb; if($is_bb) : ?> <link rel="stylesheet" href="[path to bbPress theme stylesheet]" type="text/css" media="screen" /> //add additional stylesheets if needed <?php endif; ?>
Make sure to replace [path to bbPress theme stylesheet] with the path to your current bbPress theme’s stylesheet.
If you look at your forum now, you’ll probably see a terrible mess. This is because your WordPress style sheets and your bbPress style sheets conflict. If you didn’t use the default theme you’re on your own for altering your bbPress stylesheet. Make sure you remove any elements that are directly conflicting with those in your WordPress theme (ie header, sidebar, footer elements). You’ll also want to look out for any position, and float attributes. You may also need to remove the width attribute for your forum body.
If you did use the default theme or the blue version of the default theme, you can use the stylesheets that I’ve already altered. I don’t promise that they are bug free, but they’re working well for me so far.
Make sure to rename them to style.css.
Now that you’ve altered your stylesheet, everything should look good. You arn’t done yet, however. Most likely all of your bbPress navigation (ie login, admin panel, logout) buttons are gone. If you correctly integrated WordPress cookies login and logout shouldn’t be a problem. To replace any links that were lost, code them directly into your WordPress theme, using the $is_bb variable to only display them on the forum.
Good Luck!
Update:
There is an issue with slashes being added to edited posts in bbpress. I think this is being caused by both wordpress and bbpress escaping content and then only bbpress unescaping it. In any case this is how I fixed it (its a bit of a hack) in bbpress 1.0.2:
- You’ll need to edit the file bb-includes/functions.bb-template.php (I think in earlier versions its called template-functions.php).
- Locate the function definition get_post_text. In bbpress 1.0.2 it looks like this:
function get_post_text( $post_id = 0 ) { $bb_post = bb_get_post( get_post_id( $post_id ) ); return apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id ); } - Change it to:
function get_post_text( $post_id = 0 ) { $bb_post = bb_get_post( get_post_id( $post_id ) ); return stripslashes(apply_filters( 'get_post_text', $bb_post->post_text, $bb_post->post_id )); }
I’ve also heard of an alternative solution. All you need to do is comment out the following line in wp-settings.php:
$_POST = add_magic_quotes($_POST ); In wordpress 2.9.2 it is on line 632. I personally have not tried this solution and I'm a little weary of it; it might have some unexpected side effects (namely POST data not being escaped, possibly exposing you to SQL injections).
If anyone has a solution that does not involve editing core files I would be very interested in hearing about it.