I have recently had an influx of requests to integrate vBulletin with WordPress. Oddly, ALL of these requests have come from video game community websites. The most recent being BlisteredThumbs.net. This job was a bit different than the other integrations I’ve done in that they are not a new site. So I had to customize their vB integration to accomodate the fact that they have well over 10k WordPress accounts. This led me to Google to try to find ideas, examples, tutorials, etc on how best to achieve the desired result – that being a singe login for both WordPress and vBulletin.
I decided to write this artice because of what my Google search turned up – almost nothing except links to my other article on how to integrate vBulletin and WordPress. That article goes over how to get vB to show up within the header and footer of a WordPress theme. However, until now, I haven’t had to bridge the logins between the two scripts.
So here is a simple explanation of how I did it.
First, I wrote a simple script to map the user tables from the existing WordPress accounts to the vBulletin database. It’s a pretty straightforward approach. The one thing that initially eluded me was adding the vB user id to the vb_userfield and vb_usertextfield tables. While I didn’t really look into why, I do know that if you don’t do this, you won’t be able to administer those accounts from the control panel. The other issue is dealing with the passwords. In order for a single log in to work, the password need to be the same. This would have been easy if WordPress used a simple md5 hash. They don’t. They use phpass. Since vB uses a md5 hash and salt, this presents a problem in creating the user accounts. I overcame this limitation by inserting random strings for the password initially. Then I modified the WordPress login function to take the entered password and put it into the vB database. Since I can access the salt at this point, this seemed the best way to sync the passwords. Also, if they change their WordPress password, the vB password will be automatically updated when they next log in.
Then I modified the WordPress registration page to add the new users to the vBulletin database at the same time. This was easier because you have access to the plain text password and can put it in vB already synced.
Now that I have the databases synced, it’s time to figure out how to get it to work so that the user only needs to log in once but is effectively logged into both WordPress and vBulletin.
This took quite a bit of trying different things as the vB-Wordpress bridges out there are mostly set up for syncing posts and comments or for using the vBulletin login to log into WordPress. I first tried to utilize the vBulletin API. While I was finally able to get the API to respond, I wasn’t able to get the session synced as the request was actually coming from the web server and not the browser.
Then I found an example of how to log in from non vB pages. This didn’t work initially in that vB actually runs within WordPress. So when I called vB from WordPress to run the login function, WordPress was being loaded twice causing errors. That’s when I found the beautiful vB constant DISABLE_HOOKS. Since WordPress is loaded via a hook in vBulletin, this allows vB to load on the WordPress login page without calling WordPress.
From there, it was pretty simple:
verify_authentication($login, "", $passmd5, "", true, true);
Now there are a few caveats. This only works for WordPress -> vBulletin. If they log directly into vBulletin they are not logged into WordPress. This can be easily adjusted as WordPress is already loaded when vBulletin renders.
Another bonus to this is the potential to eliminate the annoying spam vBulletin is renown for. By requiring users to register and log in to WordPress and handeling the vBulletin session on the back end, you can effectively remove the login and registration options from rendering. This would prevent bots from auto registering and auto posting!
As usual, I hope this helps someone save quite a bit of time. However, I am more than happy to help you if this isn’t in your realm of expertise.