Because I needed a very simple vB-Wordpress bridge, I decided to make one, but my knowledge of scripting is so poor, I'd appreciate some help.
The bridge does just this: the user logs in in vB, then goes to the WP site. WP checks vB cookie and signs the user on. When loging out (the logout link from WP is redirected to vB logout), vB logs the user out and deletes the WP cookies, thus logs the user out from WP too.
The login and logout link in WP: I did this in the lame fashion - I edited general-template.php. Is this doable with a plugin? I changed the wp_logout_url and wp_login_url functions:
PHP Code:
function wp_logout_url($redirect = '') {
global $vbulletin;
$args = array( 'action' => 'logout' );
if ( !empty($redirect) ) {
$args['redirect_to'] = urlencode( $redirect );
}
$hash = $vbulletin->userinfo['logouthash'];
$logout_url=$vbulletin->options['bburl'].'/login.php?do=logout&logouthash='.$hash;
return apply_filters('logout_url', $logout_url, $redirect);
}
PHP Code:
function wp_login_url($redirect = '', $force_reauth = false) {
global $vbulletin;
$login_url=$vbulletin->options['bburl'].'/login.php?do=login';
return apply_filters('login_url', $login_url, $redirect);
}
vB plugin: this is in fact the WP clear cookie code with the URLs edited. I would like to pull the Wordpress site url from its database, but I don't know how, so I hardcoded it for now (how do I read it from the database?).
The plugin is hooked to the logout_process in vB. I just added the code in the plugin manager.
PHP Code:
/**
* Used to guarantee unique hash cookies
* @since 1.5
*/
if ( !defined( 'COOKIEHASH' ) ) {
$siteurl = 'here goes the site url';
if ( $siteurl )
define( 'COOKIEHASH', md5( $siteurl ) );
else
define( 'COOKIEHASH', '' );
}
/**
* Should be exactly the same as the default value of SECRET_KEY in wp-config-sample.php
* @since 2.5.0
*/
$wp_default_secret_key = 'put your unique phrase here';
/**
* @since 2.0.0
*/
if ( !defined('USER_COOKIE') )
define('USER_COOKIE', 'wordpressuser_' . COOKIEHASH);
/**
* @since 2.0.0
*/
if ( !defined('PASS_COOKIE') )
define('PASS_COOKIE', 'wordpresspass_' . COOKIEHASH);
/**
* @since 2.5.0
*/
if ( !defined('AUTH_COOKIE') )
define('AUTH_COOKIE', 'wordpress_' . COOKIEHASH);
/**
* @since 2.6.0
*/
if ( !defined('SECURE_AUTH_COOKIE') )
define('SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH);
/**
* @since 2.6.0
*/
if ( !defined('LOGGED_IN_COOKIE') )
define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
/**
* @since 2.3.0
*/
if ( !defined('TEST_COOKIE') )
define('TEST_COOKIE', 'wordpress_test_cookie');
/**
* @since 1.2.0
*/
if ( !defined('COOKIEPATH') )
define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', 'here goes the wordpress url' . '/' ) );
/**
* @since 1.5.0
*/
if ( !defined('SITECOOKIEPATH') )
define('SITECOOKIEPATH', preg_replace('|https?://[^/]+|i', '', 'here goes the wordpress url' . '/' ) );
/**
* @since 2.6.0
*/
if ( !defined('ADMIN_COOKIE_PATH') )
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . 'wp-admin' );
/**
* @since 2.6.0
*/
if ( !defined('PLUGINS_COOKIE_PATH') )
define( 'PLUGINS_COOKIE_PATH', preg_replace('|https?://[^/]+|i', '', WP_PLUGIN_URL) );
/**
* @since 2.0.0
*/
if ( !defined('COOKIE_DOMAIN') )
define('COOKIE_DOMAIN', false);
setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
WP plugin: I used the
Wordpress bridge by Jafo and stripped it of everything I don't need (the plugin lets vB handle WP comments, which I don't want).
PHP Code:
<?php
/*
Plugin Name: Simple Vbridge Plugin
Plugin URI: http://www.worldwidecreations.com/
Description: This plugin will bridge to VB so as to use shared userbases.
Version: 4.01.13
Author: WorldWideCreations.com
Author URI: http://www.WorldWideCreations.com/
*/
// Start of vB
## Do not uncomment this.
#define('SKIP_SESSIONCREATE', 1);
define('DIE_QUIETLY', 1);
define('THIS_SCRIPT', 'vbridge');
define('NOSHUTDOWNFUNC', true);
## If you need to ENABLE hooks vbulletin hooks during this process (rarely) then comment out the next line.
define('DISABLE_HOOKS', true);
$cwd = getcwd(); //this is the current working directory, i.e. Wordpress directory
if (!$vwd) {
chdir($_SERVER['DOCUMENT_ROOT'] . get_option('vbb_VBRPATH'));
$vwd = getcwd();
$vwd = $vwd."/newsite";
(Had to hardcode this again. The document root + vbb_vbrpath returns the website url, not the vB url. My site has this structure:
site.com - the current pages
site.com/newsite - here the vB is installed and I'm testing it before going live
site.com/newsite/web - wordpress
PHP Code:
chdir($cwd);
}
#if (basename($_SERVER['SCRIPT_NAME']) == 'upload.php') { return; }
if ($_GET[action] == 'activate' and $_GET[plugin] == plugin_basename(__FILE__)) {
$install = true;
}
chdir($vwd);
require_once('global.php');
chdir($cwd);
add_action ("init","ZjistiUzivatele");
function ZjistiUzivatele() {
global $vbulletin;
$info = $vbulletin->userinfo;
$jmeno = $vbulletin->userinfo['username'];
$uzivid = $vbulletin->userinfo['userid'];
$heslo = "pwd";
I put all the users in the WP database with a same password for now. I have no idea how to put the vB password in here and how to handle if the user changes his/her password in the forum
PHP Code:
$email = $vbulletin->userinfo['email'];
require_once(ABSPATH . WPINC . '/registration.php');
//no user signed on
if ($jmeno == "Unregistered") {
}
else {
//let's see if the user exists in Wordpress
if (!username_exists($jmeno)) {
//if not, we create him
wp_create_user($jmeno,$heslo,$email);
}
$creds = array();
$creds['user_login']=$jmeno;
$creds['user_password']=$heslo;
$creds['remember']=true;
//now we log him in
$user1=wp_signon($creds,false);
}
}
?>
Any help appreciated. It would be great if it could make it to the mods section, there are many people wanting this bridge...