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.

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.

Pages: 1 2 3