Intergrating bbPress with WordPress and Making it Work
As it stands right now, bbPress and WordPress are two separate pieces of software. Last month, it was announced that a bbPress plugin might end up replacing the stand alone version but that is still in development. You can read about it on WordCast. When the plugin comes out it will trump the need to do the following but for now, integrating an existing bbPress forum into a WordPress install is not as easy as you would think.
I spent all day yesterday getting things to work and it literally took me all day. But it the end I got it done and now everything is working in sweet unison. The hardest part was figuring out how to be able to log in through one site and be automatically logged in to both. Luckily I was able to piece together tidbits of information from every article and WP forum thread to find out how to do it properly.
WordPress: v2.9.1
bbPress: v1.0.2
First thing I had to do was migrate over the users. My Support Forum has over 1200 users and in order to make sure that the threads on the forum didn’t get all messed up, I needed to ensure that the user ID numbers matched the bbPress database when I moved them over. I accessed the database through PHPMyAdmin and exported the bb_users database as a CSV For Excel file. If you changed your bbPress database prefix then your user database will have a different prefix instead of the bb.
More than likely, the first user in your bbPress database will be your admin, and the ID should be 1. Same thing goes for your WordPress database. I just deleted the first user from my CSV file so that I could use my WP admin user for both.
With the CSV file ready, I had to create a script that would take the users and their info and insert them into the WordPress user database. It took a bit of trial and error but in the end I prevailed. Upload the CSV file to your theme directory. In the code below I use a CSV file named users.csv.
NOTE: Your server probably has a timeout set for processing so you might have to break your CSV file in to many smaller files. My server cut out at around user number 400 so I suggest creating CSV files with only about 300 users in them.
ALSO NOTE: If you have more than one user in your WordPress install this will probably not work for you. It works best on fresh installs of WP or installs with only one main user.
The following code will copy over your users into the WordPress database and it will also give them a role of subscriber. Please backup your database before attempting any of this.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | global $wpdb; require ( ABSPATH . WPINC . '/registration.php' ); $file_handle = fopen(TEMPLATEPATH . "/users.csv", "r"); while (!feof($file_handle) ) { $field = fgetcsv($file_handle, 1024); $ID = $field[0]; $user_login = $field[1]; $user_pass = $field[2]; $user_nicename = $field[3]; $user_email = $field[4]; $user_URL = $field[5]; $user_registered = date("Y-m-d H:i:s", strtotime($field[6])); $user_status = $field[7]; $display_name = $field[8]; $adduser = " INSERT INTO $wpdb->users (ID, user_login, user_pass, user_nicename, user_email, user_URL, user_registered, user_status, display_name) VALUES ('$ID', '$user_login', '$user_pass', '$user_nicename', '$user_email', '$user_URL', '$user_registered', '$user_status', '$display_name') "; $results = $wpdb->query( $adduser ); $data = array( "ID" => $ID, "role" => 'subscriber' ); wp_update_user($data); } fclose($file_handle); |
Add the above code to your functions.php file. Reload your page and it will execute. I know that is a little sloppy but what can you do? If you have multiple CSV files, just go back into the code and change the filename in line 4 to the next file’s name. Repeat until all your users have been uploaded.
To make sure it worked take a look at your Users page in the WordPress admin. If you see your users listed then it worked. Now on to step number 2, integrating the two to work in unison.






hey, this is really helpful. i winged it through the integration, but this will definitely be something to reference to stabilize my system.
right now, i’m frustrated with bbpress theme development. i’ve used thematic and buddymatic for wordpress, but have not found an equivalent theme framework for bbpress. i am trying hybrid (http://themehybrid.com/), but the community around that theme seems pretentious and inaccessible unless i pay up $$. my point is:
do you know of any other bbpress theme frameworks, preferably something akin to ian stewart’s thematic?
I think a lot of people have written off bbPress for now. When the plugin gets officially released I think interest will be sparked again and more people will start to develop themes and such.
hi, it’s me again. i found a suitable theme framework for bbpress through hybrid theme club. unfortunately, i cannot wait for the bbpress plugin.
i’ve tried out these integration settings (on a local server) and it’s not working exactly right for me. right now, i have two tabs open– one for my bbpress installation and one for my wordpress installation (bbpress is in a subdirectory of wordpress). if i login as admin in wordpress and then go to my bbpress tab and refresh, i still have to login there. if i login to bbpress, i become logged out of wordpress automatically and have to login over there again. so i’m not sure what’s going on… ideas?
actually, i had a small error in my code.
this helped me:
http://bbpress.org/forums/topic/wp-integration-coockie-does-not-work/page/2
I’ve been playing with BuddyPress v1.2.1 with the bbPress integration and it does seem to work nicely. There is no need to sync users as BuddyPress (and thus bbPress) reads directly from the WP user table. However, I have found that getting BuddyPress integrated with a custom theme is quite difficult. I’m sure the same issue exists with trying to get bbPress itself to look nice with an existing custom WP theme as well. I also have been thinking that it would be nice if WP itself had some basic member profile and directory functionality, so it would seem that the BuddyPress route is a nice way to go for both the forums and user visibility.
I think they just released a couple plugins to allow you to use your current WP theme with BuddyPress.
http://wordpress.org/development/2010/02/buddypress-for-one-and-all-3/