WordPress-vBulletin Bridge

A modification of the popular blog software WordPress to interface with the vBulletin bulletin board. In short, this mod allows you to use the blog as usual while moving the discussion to the bulletin board. There is also an associated import script allowing you to move all existing blog entries and comments.

The bridge was written as a favor for Phil Plait, aka The Bad Astronomer, to bridge his blog with the Bad Astronomy and Universe Today Forum (BAUT). I recommend both his site and the forum for all with a scientific mind.

Please note that the instructions here might be a bit technical. If you're having troubles, please ask in some forum dealing with this, eg. www.vbulletin.com. Don't ask me for support (unless you're willing to pay ;-). Genuine bug reports and suggestions are always welcome, though.

Features

  • Can import all existing blog entries with comments to the forum
  • Will attempt to find forum user accounts for the comments based on e-mail
  • WordPress' and vBulletin's databases don't have to be on the same server
  • Automatically generates a reasonable excerpt for the forum thread
  • Modifications only on the WordPress side. All logic in a central file

Author

Robert Andersson <robert on profundis. se (på=@)>

Disclaimer

I am not very experienced in either software package, so there may be a lot of things I've overlooked. Use this mod at your own risk. If it destroys your blog or forum or the Internet, I'm not to blame.

Procedure

Follow these steps when activating the bridge to ensure a smooth ride. It assumes a preexisting blog. If you're doing this to a new blog, you can just skip some of the steps.

  1. Install and configure the bridge (see below)
  2. Perform backups of both your blog and forum databases
  3. Disable comments on the blog and write a short post informing your readers
  4. Do the import (see below)
  5. Activate the bridge
  6. Reactivate comments
  7. Syncronize post count on the forum, and rebuild search index

Installation

  • Download
  • Configuration
  • Add column to WordPress post table
  • Patch WordPress standard files
  • Patch WordPress template

Download

Download, and extract in the blog's directory.

Configuration

Edit the file wordpress_vbulletin_bridge-config.php.

Add column to WordPress post table

A new table column must be added to WordPress' post table, so we know which vBulletin thread it corresponds to. Using a MySQL client, do: ALTER TABLE `wp_posts` ADD `vb_threadid` INT(10);.

Patch WordPress standard files

All of these modifications could probably be made into a patch file, but I haven't had the time nor environmental ability to yet, so it has to be done manually. If you make one, please send it to me and I will put it up here.

wp-admin/admin-functions.php

Include the bridge at the very top of the file:

<?php
// Include WordPress-vBulletin Bridge
require_once(ABSPATH."wordpress_vbulletin_bridge.php");

// Creates a new post from the "Write Post" form using $_POST information.
function write_post() {

Add a hook just before returning in function write_post() (ca line 75), and edit_post (ca line 220):

        // Now that we have an ID we can fix any attachment anchor hrefs
        fix_attachment_links($post_ID);

        // WordPress-vBulleting Bridge: hook
        wp2vb_newpost($post_ID);

        return $post_ID;
}

wp-includes/comment-functions.php

Include the bridge at the very top of the file:

<?php
// Include WordPress-vBulletin Bridge
require_once(ABSPATH."wordpress_vbulletin_bridge.php");

// Template functions

function comments_template( $file = '/comments.php' ) {

Replace code in function get_comments_number(), ca line 230:

        if ( !isset($comment_count_cache[$post_id]) )
          $comment_count_cache[$id] = $wpvb->get_var(...);
          $comment_count_cache[$id] = wp2vb_get_comments_number($post_id);

        return apply_filters('get_comments_number', $comment_count_cache[$post_id]);
}

Replace code in function get_comments_link(), ca line 240:

function get_comments_link() {
  return get_permalink() . '#comments';
  return wp2vb_get_comments_link($GLOBALS['id']);
}

Replace code in function comments_popup_link(), ca line 280 and 310:

       if (! is_single() && ! is_page()) {
        if ( !isset($comment_count_cache[$id]) )
          $comment_count_cache[$id] = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_post_ID = $id AND comment_approved = '1';");
          $comment_count_cache[$id] = wp2vb_get_comments_number($id);

        $number = $comment_count_cache[$id];
               } else { // if comments_popup_script() is not in the template, display simple comment link
                        if ( 0 == $number )
                          echo get_permalink() . '#respond';
                          echo wp2vb_get_comments_link_respond($id);
                        else
                                comments_link();
                        echo '"';
                }

wp-includes/functions.php

Comment out in the function update_post_cache(), ca line 1410:

        // Get the categories for all the posts
        for ($i = 0; $i < count($posts); $i++) {
                $post_id_array[] = $posts[$i]->ID;
                $post_cache[$posts[$i]->ID] = &$posts[$i];
                $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;
                // $comment_count_cache[$posts[$i]->ID] = $posts[$i]->comment_count;
        }

Patch WordPress template

Exactly how this is done will depend on your template of choice. The modification below is for the Daisy Rae Gemini theme, but it will likely work for most others. In beginning of wp-content/themes/*/comments.php add:

<?php
if($GLOBALS['wp2vb_activated']) {
  wp2vb_comments_template($id);
  return;
}
?>
<?php if ( !empty($post->post_password) && $_COOKIE['wp-postpass_' . COOKIEHASH] != $post->post_password) : ?>

History

1.1.0 (2006-06-19)
Publish date has to be in the past for vB thread to be created
New configuration directive $wp2vb_autocreate causes a vB thread to be created automatically whenever it failes to find one. Use with caution.
1.0.0 (2006-06-01)
Initial