Integrating MyBB and WordPress

Trying to make two disparate PHP applications work together can be a pain.  Especially when both have their own membership systems, and various functions using the same names.

On the other hand, having a website with different themes all over and users having to sign up twice is worse.

I tried to find an integrated forum solution for WordPress.  I really did.  Problem is, I’m used to something that works like phpBB, and none of the solutions I could find were similar enough.

bbPress isn’t mature enough.  On the integration side it’s perfect, but it just doesn’t do enough.  I don’t want to have to rely on a dozen plugins just to get basic things like security and user rights.

Simple:Press is just too darned ugly. Sorry, but it just looks like a forum crammed inside a wordpress page.

So looks like I was stuck with having to integrate an existing standalone forum into WordPress.  I’d done some work in the past integrating MediaWiki so it didn’t look like an impossible task.  Mostly its a case of editing the forum theme to strip out extraneous formatting and then wrapping the WordPress header and footer around it.

The next issue was phpBB itself.  Every modification requires hacking the core files – there’s no plugin/hook system.  So instead I looked around for a forum that actually had a plugin system.  MyBB stood out as one of the more progressive ones, with a plugin/hook system much like WordPress’s own.

So, I had my forum, and just had to make a plugin to make it work inside WordPress.  Right?

Wrong.

Had MyBB not used the exact same function names as WordPress in a few places, I could have pulled it off relatively easily.  Unfortunately, not the case.

(note to anyone reading this, if you ever write anything in PHP and want people to actually use it, for gods sake use Namespaces)

In the interests of making no real code changes, I thought perhaps it would be enough to throw a namespace declaration at the beginning of each MyBB file.  Not that simple – MyBB references objects by name internally, and if you start namespacing them it expects the references to use the namespace too.  Way too much core hacking involved, and required far too much messing around working out how MyBB actually works to figure out what to change and where.

I was still resisting making any changes to MyBB core files, but really needed to rename those duplicate functions.  I thought about abandoning my stance on core hacking and just hoping Subversion could help me merge future releases with my changes, but wanted one last shot with a wild idea.

What if it were possible to make on-the-fly edits to PHP files as they were read by the server? This would leave them unchanged on disc, and just rename the functions in memory before executing them.  Sounds perfect, doesn’t it?  Pity I didn’t have a clue how to start.

I began by trying to use an Apache filter, but it got far too complicated.  And besides, I wasn’t sure it was even the right approach.  Then I managed to stray across this post.

Yes, you’re reading that post right (you did click the link, didn’t you? If not go click it now, I promise you if you’re a PHP coder it’ll rip apart your whole idea of how things work, and start making your creativity do loop-the-loops coming up with new and interesting things to do with the idea) – thats a PHP script that intercepts file access and makes on-the-fly changes as they are read (and could make them as they are written, if you wanted it to).  It’s called a Stream Wrapper, and is quite possibly the coolest thing you can possibly do in PHP.

So I used that as a base, and wrote a similar one.  Mine performs search/replace on those duplicate function names in MyBB (mostly just prefixing them with “mybb_”) so it can coexist with WordPress.  Then I do some magic with injecting my own functions into certain places to check the logged-on WordPress user and log them into MyBB, creating a user with the same name where necessary.

Its mostly working now, in testing on the new Warpedcore Community site, and I’ll upload it here when I’ve finished testing it out.  It’s got a few things specific to this site in it, but it should be helpful for anyone else trying to integrate WordPress and MyBB.

You know, what the hell, lets do one for phpBB too.

Comments (5)

  1. freshjustin says:

    Hi Matt,

    This is awesome any chance you will be releasing this soon. If your free I would pay you to do this to my site as i need it done right away.

  2. Charlie says:

    I have been using both MyBB and WordPress for over two years now, and the integration of the two has been a dream of mine ever since then. How did you fair on your quest to get them to cooperate with one another? Did you manage to do the un-doable?

    Would love to know how you faired and, if at all possible, get a copy of it to use.

    Thanks-very much, great article,

    Charlie

  3. icedevil says:

    Hey matt,

    sounds really promising. Is there any chance you can upload your script?

    Thanks

  4. Daniele says:

    Any news about your hack ?

    Really interested

  5. Joe says:

    Hey,

    I’m also interested in getting that script. Could you upload it, please?

Leave a Reply to icedevil Cancel reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.