Integrating Vanilla Forum and WordPress Themes

The folks at Vanilla have a handy guide to integrating the database tables and cookies of WordPress and Vanilla, but they don’t explain how to use the WordPress themes in Vanilla. It’s pretty simple.

First, you need to include the WordPress files. A good place to do this is at the bottom of the Vanilla


conf/database.php
 
file, where you should put

<?php require_once('../wp-blog-header.php'); ?>
 

(of course make sure that’s the path to wp-blog-header.php–yours may be in a different directory).

Second, you need to re-connect WordPress to the database, because Vanilla will close the connection early. Edit Vanilla’s


library/Framework/Framework.Class.MySQL.php
 
file, adding the two lines in boldface to this section near the top of the file:

class MySQL extends Database {
     function CloseConnection() {
          if ($this->Connection) @mysql_close($this->Connection);
          global $wpdb;
          $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
     }

That’s it! Now you can use WordPress functions, such as get_header(), in the Vanilla theme.

18 Comments

  1. hey there,

    thanks for this. shame it doesn’t work for me for some reason. i followed your instruction, but now i get this error:

    Fatal error: Cannot instantiate non-existent class: wpdb in Framework.Class.MySQL.php on line 18

    line 18 being: $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);

    i included wp-blog-header.php in conf/database.php, but so far no wp functions are working. i’d really appreciate some help. normaly i’d think it was me doing something wrong, like usual, but this is really starightforward. i think…

  2. boris, probably '../wp-blog-header.php' is not the right path to wp-blog-header.php. You may need to adjust accordingly.

  3. Filosofo,

    I attempted to follow your directions too, and my site went blank. No source code or anything on the forum page. Then when I restored the original settings, everything was fine.

    Can you further explain the following steps?

    1. “Add to the bottom of your Vanilla conf/database.php file.”

    I changed the file path, but it still didn’t work. This was the part that blanked my site out. Does it matter that there’s already one

  4. Enigmatix, those directions assume that the PHP tags are closed at the bottom of the file (like ?>). You may need to adjust accordingly.

    Also, try turning on error reporting in PHP to see what errors are being thrown instead of just getting a blank screen.

  5. I did as you laid out above and everything works fine, no errors. I used Vanilla 1.1.1 and WP 2.1.2. However once I did your steps above Vanilla started inserting backslashes where ever it saw single or double quotes when posting new entries. Did this happen to you to? Do you have any idea what could be causing this, magic quotes are turned off on my server.

  6. Mark, which steps caused the backslashes to appear?

  7. Well I did both steps above, but its the require_once(‘../wp-blog-header.php’);

    That causes the backslashes to start coming in. Heres my test forum:

    http://iworkoutnow.com/vanilla/

    login: admin
    pass: admin

    and my php info: http://iworkoutnow.com/vanilla/info.php

    Clean install of Vanilla 1.1.1 and WP 2.1.2, no extensions default theme. You can see how it works in the two test posts I have there.

  8. Mark,
    The slash problem seems to be caused by the fact that recent versions of WordPress slash everything that gets posted. Unfortunately, Vanilla isn’t expecting this.

    You should keep those slashes from appearing initially by adding, right after require_once(’../wp-blog-header.php’);, the following lines:

    $_GET = stripslashes_deep($_GET );
    $_POST = stripslashes_deep($_POST );
    $_COOKIE = stripslashes_deep($_COOKIE);

  9. Thank you sir!

    Works perfectly!

  10. Hi,

    this sounds very nifty, but I dont think I get what it actually does..

    I would like vanilla forum to look like my website, smooth and clean, but I’m also very new at both php and the forum stuff.

    My website is http://www.cafe-nightclub.com and the forum is located at http://www.cafe-nightclub.com/forum

    Am I doing something wrong, or is it in fact, working now?

  11. Same question as above from Kasper and (also?) still searching for an easy solution for this. It appears that this will require playing with some files. Any pointers would be greatly appreciated.

    Thanks and take care.

  12. Thanks very much for these instructions. I tried them and unfortunately got this error;


    Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration in /home/.lock/user/site/messageboard/conf/database.php on line 52

    Warning: require_once(http://www.mysitename.net/wp-blog-header.php) [function.require-once]: failed to open stream: no suitable wrapper could be found in /home/.lock/user/site/messageboard/conf/database.php on line 52

    Fatal error: require_once() [function.require]: Failed opening required 'http://www.mysitename.net/wp-blog-header.php' (include_path='.:/usr/local/php5/lib/php') in /home/.lock/user/site/messageboard/conf/database.php on line 52

  13. Hello! Help solve the problem.
    Very often try to enter the site, but says that the password is not correct.
    Regrettably use of remembering. Give like to be?
    Thank you!

  14. Hi,

    Love the ease of your fix, but how do I uninstall these settings cleanly? Doing it in reverse doesn’t seem to work.

    I need to install the attachments2 extention, which is seemingly incompatible with these settings. Is there anyway I can work around that? If so, that would be even better.

    Thanks

  15. Hello,
    Thanks for this tutorial. It worked almost totally as-is, except that Ajax broke. This meant that I could not enable/disable extensions, remove posts or check for updates. I changed it from a relative path (../wp-blog-header.php) to an exact path in my server (/var/www/mydomain/wp-blog-header.php) and Ajax works perfectly now.

    Thanks again!

  16. Thanks mate
    You rule! :grin:

  17. I am having trouble getting a script to run on my WordPress blog.

    Here is the error…

    Warning: require_once() [function.require-once]: URL file-access is disabled in the server configuration in /home/content/s/s/e/sself0117/html/financial-aid-secrets.com/wp-content/themes/big-blue-01/footer.php on line 7

    Warning: require_once(http://stephen-henderson.com/blog-linking/showlink.php?id=1) [function.require-once]: failed to open stream: no suitable wrapper could be found in /home/content/s/s/e/sself0117/html/financial-aid-secrets.com/wp-content/themes/big-blue-01/footer.php on line 7

    Can you help me at all with this?

    Thank you!

  18. tesisat yikama ve temizleme hizmetleri vermekteyiz.

Post a Comment

Your email is never shared. Required fields are marked *

*
*

30 Trackbacks