Vanilla 1 Documentation Archive

 
 
vanilla:integration:wordpress
Table of Contents

Wordpress Integration

The following integration was made with Wordpress 2.0.4 and Vanilla 1.0.1 on August 22, 2006. Let it be known that I am not a Wordpress user. Besides the fact that it’s an insanely popular blogging tool and people often ask how to integrate it with Vanilla, I honestly don’t know much about the program. I just downloaded it, installed it, and now I’m integrating it with Vanilla.

So, let’s begin...

File Integration

Obviously the first question that comes to mind is “where should I put the Vanilla files with relation to Wordpress?”.

I installed Wordpress first. I put it in my document root with the actual version name as the folder name:

/path/to/document/root/wordpress-2.0.4/

Up next I downloaded the latest version of Vanilla (1.0.1) and I dropped the zip file into my wordpress-2.0.4 folder. I unzipped it right there so my Vanilla sat in wordpress like this:

/path/to/document/root/wordpress-2.0.4/Vanilla.1.0.1/

Obviously those folder names aren’t the greatest, but I’m using them for the sake of clarity.

Database Integration

Installation

Okay, so I’ve got Wordpress installed and Vanilla just sitting there, not yet installed. Next I’m going to install Vanilla. I’m going to make it use the same database as Wordpress, so all of the tables are in the same database for both Wordpress and Vanilla.

If I load up Vanilla in my web browser at localhost:8020/wordpress-2.0.4/Vanilla.1.0.1/ it prompts me with the installer. I choose to do a brand new installation and go through with it. If you don’t know how to install Vanilla, that’s for a different document altogether.

One thing to make note of during the installation is that you will be prompted to enter your administrative username and password. You can put anything you want in here, because the values will be saved to Vanilla’s user table, which we WON’T be using after the next step.

Merging Databases

Alright, both Wordpress and Vanilla are installed, but they aren’t aware of each other at all yet. So next up we want to start merging the two databases together. We’ll start with the most obvious place: the user table.

Because both Vanilla and Wordpress have user tables, we want to only use one of them so all users are contained in one place. I have built Vanilla so that it doesn’t directly reference it’s own tables. It references table and column mappings instead. So, we just need to make Vanilla aware of the Wordpress user table through these mappings.

Open up the following file:

/path/to/document/root/wordpress-2.0.4/Vanilla.1.0.1/appg/database.php

This is the file that contains the database table and column mappings. Because there are a lot of them, this file is pretty big - but don’t get scared. The first array contains table mappings, and the second massive array contains mappings for all of the columns.

We DO NOT want to alter this file. This file should be treated as a template that should not be altered. Instead we want to copy the fields we want to change into our conf (short for configuration) directory and add them to the database.php file in there.

Here is what my /path/to/document/root/wordpress-2.0.4/Vanilla.1.0.1/conf/database.php file currently looks like after a fresh install:

<?php
// Database Configuration Settings
$Configuration['DATABASE_HOST'] = 'localhost';
$Configuration['DATABASE_NAME'] = 'wordpress';
$Configuration['DATABASE_USER'] = 'mysql_user';
$Configuration['DATABASE_PASSWORD'] = 'mysql_password';
?>

So, let’s start by adding the new table mapping for the user table:

<?php
// Database Configuration Settings
$Configuration['DATABASE_HOST'] = 'localhost';
$Configuration['DATABASE_NAME'] = 'wordpress';
$Configuration['DATABASE_USER'] = 'mysql_user';
$Configuration['DATABASE_PASSWORD'] = 'mysql_password';
 
// Wordpress Integration
// =====================
// Map to the wordpress user table
$DatabaseTables['User'] = 'wp_users';
?>

Up next I took a look at the existing columns in the wp_users table and quickly saw which fields could map to Vanilla fields. Obviously not all of the fields will have perfect matches between the two different systems, but we’ll tackle that later. For now I just add the mappings that I can with the following code:

<?php
// Database Configuration Settings
$Configuration['DATABASE_HOST'] = 'localhost';
$Configuration['DATABASE_NAME'] = 'wordpress';
$Configuration['DATABASE_USER'] = 'root';
$Configuration['DATABASE_PASSWORD'] = 'thing';
 
// Wordpress Integration
// =====================
// Map to the wordpress user table
$DatabaseTables['User'] = 'wp_users';
// Map existing wordpress columns to Vanilla
$DatabaseColumns['User']['UserID'] = 'ID';
$DatabaseColumns['User']['Name'] = 'user_login';
$DatabaseColumns['User']['Password'] = 'user_pass';
$DatabaseColumns['User']['Email'] = 'user_email';
$DatabaseColumns['User']['DateFirstVisit'] = 'user_registered';
?>

Finally, I will need to map the remaining wp_users columns into the Vanilla:

<?php
// Database Configuration Settings
$Configuration['DATABASE_HOST'] = 'localhost';
$Configuration['DATABASE_NAME'] = 'wordpress';
$Configuration['DATABASE_USER'] = 'root';
$Configuration['DATABASE_PASSWORD'] = 'thing';
 
// Wordpress Integration
// =====================
 
// Map to the wordpress user table
$DatabaseTables['User'] = 'wp_users';
 
// Map existing wordpress columns to Vanilla
$DatabaseColumns['User']['UserID'] = 'ID';
$DatabaseColumns['User']['Name'] = 'user_login';
$DatabaseColumns['User']['Password'] = 'user_pass';
$DatabaseColumns['User']['Email'] = 'user_email';
$DatabaseColumns['User']['DateFirstVisit'] = 'user_registered';
 
// Also map the Wordpress columns into Vanilla
$DatabaseColumns['User']['user_nicename'] = 'user_nicename';
$DatabaseColumns['User']['user_url'] = 'user_url';
$DatabaseColumns['User']['user_activation_key'] = 'user_activation_key';
$DatabaseColumns['User']['user_status'] = 'user_status';
$DatabaseColumns['User']['display_name'] = 'display_name';
?>

So, as I mentioned, I now need to make sure that all of the other fields Vanilla requires get added to the Wordpress user table (wp_users).

I’m going to do this by going into Vanilla’s setup folder and getting the mysql.sql file to see how Vanilla builds it’s user table:

CREATE TABLE `LUM_User` (
  `UserID` int(10) NOT NULL AUTO_INCREMENT,
  `RoleID` int(2) NOT NULL DEFAULT '0',
  `StyleID` int(3) NOT NULL DEFAULT '1',
  `CustomStyle` varchar(255) DEFAULT NULL,
  `FirstName` varchar(50) NOT NULL DEFAULT '',
  `LastName` varchar(50) NOT NULL DEFAULT '',
  `Name` varchar(20) NOT NULL DEFAULT '',
  `Password` varchar(32) DEFAULT NULL,
  `VerificationKey` varchar(50) NOT NULL DEFAULT '',
  `EmailVerificationKey` varchar(50) DEFAULT NULL,
  `Email` varchar(200) NOT NULL DEFAULT '',
  `UtilizeEmail` enum('1','0') NOT NULL DEFAULT '0',
  `ShowName` enum('1','0') NOT NULL DEFAULT '1',
  `Icon` varchar(255) DEFAULT NULL,
  `Picture` varchar(255) DEFAULT NULL,
  `Attributes` text NULL,
  `CountVisit` int(8) NOT NULL DEFAULT '0',
  `CountDiscussions` int(8) NOT NULL DEFAULT '0',
  `CountComments` int(8) NOT NULL DEFAULT '0',
  `DateFirstVisit` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `DateLastActive` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `RemoteIp` varchar(100) NOT NULL DEFAULT '',
  `LastDiscussionPost` datetime DEFAULT NULL,
  `DiscussionSpamCheck` int(11) NOT NULL DEFAULT '0',
  `LastCommentPost` datetime DEFAULT NULL,
  `CommentSpamCheck` int(11) NOT NULL DEFAULT '0',
  `UserBlocksCategories` enum('1','0') NOT NULL DEFAULT '0',
  `DefaultFormatType` varchar(20) DEFAULT NULL,
  `Discovery` text,
  `Preferences` text,
  `SendNewApplicantNotifications` enum('1','0') NOT NULL DEFAULT '0',
  PRIMARY KEY  (`UserID`),
  KEY `user_role` (`RoleID`),
  KEY `user_style` (`StyleID`),
  KEY `user_name` (`Name`)
);

So, now I know what the other columns and datatypes are required by Vanilla. I also know that the UserID, Name, Password, Email, and DateFirstVisit columns are already mapped to the wordpress columns. So, I’ll write my table alteration scripts for the wp_users table now:

ALTER TABLE wp_users
  ADD `RoleID` int(2) NOT NULL DEFAULT '3',
  ADD `StyleID` int(3) NOT NULL DEFAULT '1',
  ADD `CustomStyle` varchar(255) DEFAULT NULL,
  ADD `FirstName` varchar(50) NOT NULL DEFAULT '',
  ADD `LastName` varchar(50) NOT NULL DEFAULT '',
  ADD `VerificationKey` varchar(50) NOT NULL DEFAULT '',
  ADD `EmailVerificationKey` varchar(50) DEFAULT NULL,
  ADD `Email` varchar(200) NOT NULL DEFAULT '',
  ADD `UtilizeEmail` enum('1','0') NOT NULL DEFAULT '0',
  ADD `ShowName` enum('1','0') NOT NULL DEFAULT '1',
  ADD `Icon` varchar(255) DEFAULT NULL,
  ADD `Picture` varchar(255) DEFAULT NULL,
  ADD `Attributes` text NULL,
  ADD `CountVisit` int(8) NOT NULL DEFAULT '0',
  ADD `CountDiscussions` int(8) NOT NULL DEFAULT '0',
  ADD `CountComments` int(8) NOT NULL DEFAULT '0',
  ADD `DateLastActive` datetime NOT NULL DEFAULT '2006-06-06 00:00:00',
  ADD `RemoteIp` varchar(100) NOT NULL DEFAULT '',
  ADD `LastDiscussionPost` datetime DEFAULT NULL,
  ADD `DiscussionSpamCheck` int(11) NOT NULL DEFAULT '0',
  ADD `LastCommentPost` datetime DEFAULT NULL,
  ADD `CommentSpamCheck` int(11) NOT NULL DEFAULT '0',
  ADD `UserBlocksCategories` enum('1','0') NOT NULL DEFAULT '0',
  ADD `DefaultFormatType` varchar(20) DEFAULT NULL,
  ADD `Discovery` text,
  ADD `Preferences` text,
  ADD `SendNewApplicantNotifications` enum('1','0') NOT NULL DEFAULT '0';

Okay, so I just ran that query on my wordpress database and double-checked to be sure that all of the extra columns for Vanilla were added to the wp_users table.

One thing to take note of is the second line of my query:

ADD `RoleID` int(2) NOT NULL DEFAULT '3',

Notice that I gave it a default of 3? That is because the “member” RoleID in Vanilla is 3. This will make it so that new users added by the wordpress “create a new user” form will automatically be added to the member role on the forum. Also notice that I’ve made any field that doesn’t accept NULL have a default value. This way regular user operations in Wordpress won’t break because of Vanilla restrictions.

Authentication Integration

So now that we’ve got our databases munged together, we need to make Vanilla start to talk like Wordpress. The first step is to go digging through the Wordpress code to see how they handle sessions and cookies. After a lot of time and reading through various files I discover that Wordpress doesn’t use PHP Sessions.

Wordpress stores it’s session information in cookies. The hard part was finding out what the cookie names were because in this version of Wordpress the cookie names are generated based on the “siteurl” configuration setting. This configuration setting can be found in the wp_options table of the database.

This is too bad, really, because it means that before Vanilla can even begin to examine the cookies it will need to query the database for that value. Regardless, the time has come to start building a custom Authenticator in Vanilla. The default authenticator can be found at:

/path/to/document/root/wordpress-2.0.4/Vanilla.1.0.1/library/People/People.Class.Authenticator.php

I’m going to make a copy of this file and rename it:

/path/to/document/root/wordpress-2.0.4/Vanilla.1.0.1/library/People/People.Class.WordpressAuthenticator.php

Now I’ll open it up and edit the methods within so that Vanilla can:

Technically I don’t need to make Vanilla handle the logging in of users. I could just leave all of that to wordpress and remove the people.php file in Vanilla altogether. But I’ll do it anyway.

So that took some time. Here is the new WordpressAuthenticator I’ve written:

<?php
/*
* Copyright 2003 Mark O'Sullivan
* This file is part of People: The Lussumo User Management System.
* Lussumo's Software Library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
* Lussumo's Software Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with Vanilla; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
* The latest source code is available at www.lussumo.com
* Contact Mark O'Sullivan at mark [at] lussumo [dot] com
* 
* Description: Default interface for user authentication. This class may be
* replaced with another using the "AUTHENTICATION_MODULE" configuration setting.
* Applications utilizing this file: Vanilla;
*/
class Authenticator {
   var $Context;
	var $WordpressSettingsRetrieved;
	var $CookiePath;
	var $SiteCookiePath;
	var $CookieHash;
	var $UserCookieName;
	var $PassCookieName;
	
	function AssignSessionData($user_login, $user_pass, $PersistentSession = '0') {
		$this->GetWordpressSettings();
      
		$Expire = $PersistentSession ? time() + 31536000 : 0;
		$user_pass = md5($user_pass); // Double hash the password in the cookie.
		
		// Set the cookies
		setcookie($this->UserCookieName, $user_login, $Expire, $this->CookiePath, false);
		setcookie($this->PassCookieName, $user_pass, $Expire, $this->CookiePath, false);
	
		if ($this->CookiePath != $this->SiteCookiePath ) {
			setcookie($this->UserCookieName, $user_login, $Expire, $this->SiteCookiePath, false);
			setcookie($this->PassCookieName, $user_pass, $Expire, $this->SiteCookiePath, false);
		}		
	}
	
	// This method is used in various places in Vanilla to sign someone into a session
	function AssignSessionUserID($UserID) {
		// Get the login_name and password for session assignment
      $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
      $s->SetMainTable('User', 'u');
      $s->AddSelect(array('Name', 'Password'), 'u');
      $s->AddWhere('u', 'UserID', '', $UserID, '=');
      $Result = $this->Context->Database->Select($s,
         'WordpressAuthenticator',
         'AssignSessionUserID',
         'An error occurred while attempting to assign session data');
              
      if ($Result) {
			$user_login = '';
			$user_pass = '';
         while ($rows = $this->Context->Database->GetRow($Result)) {
            $user_login = ForceString($rows['Name'], '');
            $user_pass = ForceString($rows['Password'], '');
         }
			$this->AssignSessionData($user_login, $user_pass);
		}
	}
	
   // Returning '0' indicates that the username and password combination weren't found.
   // Returning '-1' indicates that the user does not have permission to sign in.
   // Returning '-2' indicates that a fatal error has occurred while querying the database.
   function Authenticate($Username, $Password, $PersistentSession) {
      // Validate the username and password that have been set
      $Username = FormatStringForDatabaseInput($Username);
      $Password = FormatStringForDatabaseInput($Password);
      $UserID = 0;
		$user_login = '';
		$user_pass = '';
		
      // Retrieve matching username/password values
      $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
      $s->SetMainTable('User', 'u');
      $s->AddJoin('Role', 'r', 'RoleID', 'u', 'RoleID', 'inner join');
      $s->AddSelect(array('UserID', 'Name', 'Password'), 'u');
      $s->AddSelect('PERMISSION_SIGN_IN', 'r');
      $s->AddWhere('u', 'Name', '', $Username, '=');
      $s->AddWhere('u', 'Password', '', md5($Password), '=', 'and', '', 1, 1);
      $s->AddWhere('u', 'Password', '', $Password, '=', 'or');
      $s->EndWhereGroup();
 
      $UserResult = $this->Context->Database->Select($s,
         'WordpressAuthenticator',
         'Authenticate',
         'An error occurred while attempting to validate your credentials');
              
      if (!$UserResult) {
         $UserID = -2;
      } elseif ($this->Context->Database->RowCount($UserResult) > 0) {
         $CanSignIn = 0;
         $VerificationKey = '';
         while ($rows = $this->Context->Database->GetRow($UserResult)) {
				$UserID = ForceInt($rows['UserID'], 0);
            $user_login = ForceString($rows['Name'], '');
            $user_pass = ForceString($rows['Password'], '');
            $CanSignIn = ForceBool($rows['PERMISSION_SIGN_IN'], 0);
         }
         if (!$CanSignIn) {
            $UserID = -1;
         } else {
            // Update the user's information
            $this->UpdateLastVisit($UserID);
 
            // Assign the session value
            $this->AssignSessionData($user_login, $user_pass, $PersistentSession);
				
				// Log the person's ip
            $this->LogIp($UserID);
         }
      }
      return $UserID;
   }
   
   function Authenticator(&$Context) {
      $this->Context = &$Context;
		$this->WordpressSettingsRetrieved = '0';
		$this->CookiePath = '';
		$this->SiteCookiePath = '';
		$this->CookieHash = '';
   }
   
   function DeAuthenticate() {
		if (session_id()) session_destroy();
		$this->GetWordpressSettings();
		setcookie($this->UserCookieName, ' ', time() - 31536000, $this->CookiePath, false);
		setcookie($this->PassCookieName, ' ', time() - 31536000, $this->CookiePath, false);
		setcookie($this->UserCookieName, ' ', time() - 31536000, $this->SiteCookiePath, false);
		setcookie($this->PassCookieName, ' ', time() - 31536000, $this->SiteCookiePath, false);
      return true;      
   }
   
   function GetIdentity() {
		$this->GetWordpressSettings();
		
		// Examine the cookie values for session info
      $login = ForceIncomingCookieString($this->UserCookieName, '');
		$pass = ForceIncomingCookieString($this->PassCookieName, '');
		$dbpass = '';
		$UserID = 0;
 
      if ($login != '' && $pass != '') {
			$s = "select id, user_pass from wp_users where user_login = '".FormatStringForDatabaseInput($login)."'";
 
			$Result = $this->Context->Database->Execute($s,
				'WordpressAuthenticator',
				'GetIdentity',
            'An error occurred while attempting to retrieve session data.');
 
			if ($Result) {
				while ($rows = $this->Context->Database->GetRow($Result)) {
					$UserID = ForceInt($rows['id'], 0);
					$dbpass = ForceString($rows['user_pass'], '');
				}
				// If the double-md5d password doesn't match the one in the cookie - don't authenticate
				if (md5($dbpass) != $pass) {
					$UserID = 0;
				}
         }
      }
      else {
         if (session_id()) session_destroy();
      }
 
      if (!session_id()) {
         session_set_cookie_params(0, $this->CookiePath);
         session_start();
      }
 
      return $UserID;
   }
	
	function GetWordpressSettings() {
		if ($this->WordpressSettingsRetrieved == '0') {
			$siteurl = '';
			$home = '';
			$s = "select option_name, option_value from wp_options where option_name = 'siteurl' or option_name = 'home'";
			$DataSet = $this->Context->Database->Execute($s,
				'WordpressAuthenticator',
				'GetCookieName',
				'An error occurred while retrieving cookie names.');
			if ($DataSet) {
				while ($rows = $this->Context->Database->GetRow($DataSet)) {
					if ($rows['option_name'] == 'siteurl') {
						$siteurl = ForceString($rows['option_value'], '');
					} else if ($rows['option_name'] == 'home') {
						$home = ForceString($rows['option_value'], '');
					}
				}
			}		
			$this->CookiePath = preg_replace('|https?://[^/]+|i', '', $home . '/' );
			$this->SiteCookiePath = preg_replace('|https?://[^/]+|i', '', $siteurl . '/' );
			$this->CookieHash = md5($siteurl);
			$this->UserCookieName = 'wordpressuser_'.$this->CookieHash;
			$this->PassCookieName = 'wordpresspass_'.$this->CookieHash;
			$this->WordpressSettingsRetrieved = '1';
		}
	}
	
   function LogIp($UserID) {
      if ($this->Context->Configuration['LOG_ALL_IPS']) {
         $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
         $s->SetMainTable('IpHistory', 'i');
         $s->AddFieldNameValue('UserID', $UserID);
         $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1));
         $s->AddFieldNameValue('DateLogged', MysqlDateTime());
 
         $this->Context->Database->Insert($s,
            'WordpressAuthenticator',
            'LogIp',
            'An error occurred while logging your IP address.',
            false); // fail silently
      }
   }
		
   function UpdateLastVisit($UserID) {
      $s = $this->Context->ObjectFactory->NewContextObject($this->Context, 'SqlBuilder');
      $s->SetMainTable('User', 'u');
      $s->AddFieldNameValue('DateLastActive', MysqlDateTime());
      $s->AddFieldNameValue('CountVisit', 'CountVisit + 1', 0);
      $s->AddWhere('u', 'UserID', '', $UserID, '=');
 
      $this->Context->Database->Update($s,
         'WordpressAuthenticator',
         'UpdateLastVisit',
         'An error occurred while updating your profile.',
         false); // fail silently
   }
}
?>

Okay, so now I need to make Vanilla aware of my new authentication class. I do this by editing the conf/settings.php file and adding the following lines:

// Wordpress Authenticator
$Configuration['AUTHENTICATION_MODULE'] = 'People/People.Class.WordpressAuthenticator.php';

Now I’ll go try to sign in with my wordpress login.

I’ve now tried using both the vanilla login screen and the wordpress login screen - both of which work and sign me in properly. It’s up to you which one you want to use.

The big issue now is...

User Management

Administrative Account

I quickly discover that my wordpress account only has basic member status in Vanilla. I’ll need to remedy this with a quick query on the wp_users table. I know that the administrative RoleID in Vanilla is 4. If you aren’t sure that is the administrative role in your Vanilla forum, you can review the roles with the following query:

SELECT * FROM LUM_Role

So, I need to update my admin account with Vanilla’s admin RoleID. I also know that my wordpress admin user is ID 1 in the wp_users table, so I can update my role with the following query:

UPDATE wp_users SET RoleID = 4 WHERE id = 1

So now I can browse around Vanilla and have full access to all administrative abilities as well as in Wordpress.

New Members

Now I need to figure out how to handle new members in both Wordpress and Vanilla. The wp_users table’s original fields do NOT allow any nulls, so if you try to create a user with Vanilla’s registration form, it will likely not work at all and fail when it tries to insert nulls into the wordpress fields in the wp_users table.

I’ve gone in and created users manually in the wordpress administration, and I’ve also turned on public registration for Wordpress and created a user this way. Both methods worked and allowed the registered user to sign in and begin discussions in Vanilla - as well as perform operations in Wordpress.

Option 1

So, you can disable the vanilla registration and login forms if you wish. The easiest way is to just delete the people.php file in the root of Vanilla. This also works since most people that sign up are not given the rights on the WordPress side, since the wp_usermeta table is not made aware of the new user, and cannot assign the proper WordPress privileges to the new user.

Option 2

Alternately you can write an extension for Vanilla that alters the way Vanilla users are created - making it choose some default values for the wordpress fields. This way you could keep the people.php file and just tell your users which login to use.

I went into my extensions directory in Vanilla, created a “WordpressIntegration” folder. I went into the WordpressIntegration folder and created a default.php file. I opened up the default.php file and wrote:

<?php
/*
Extension Name: Wordpress Integration
Extension Url: http://lussumo.com/docs/
Description: Makes it so that new users can be added via the Vanilla registration form and it won't mess up the wordpress user table.
Version: 1.0
Author: Mark O'Sullivan
Author Url: http://markosullivan.ca/
*/
 
if ($Context->SelfUrl == 'people.php') {
   function UserManager_AddWordpressFieldsToCreateUser(&$UserManager) {
      $User = &$UserManager->DelegateParameters['User'];
      $SafeUser = clone ($User);
		$SafeUser->FormatPropertiesForDatabaseInput();
      $s = &$UserManager->DelegateParameters['SqlBuilder'];
      
      // Since Vanilla and Wordpress encode their passwords differently, I need
      // to make Vanilla's CreateUser method save it's password in the same way.
      // So, I'll have to rebuild this sql object with the proper password.
      $s->Clear();
      $s->SetMainTable('User', 'u');
      $s->AddFieldNameValue('FirstName', $SafeUser->FirstName);
      $s->AddFieldNameValue('LastName', $SafeUser->LastName);
      $s->AddFieldNameValue('Name', $SafeUser->Name);
      $s->AddFieldNameValue('Email', $SafeUser->Email);
      $s->AddFieldNameValue('Password', md5($SafeUser->NewPassword));
      $s->AddFieldNameValue('DateFirstVisit', MysqlDateTime());
      $s->AddFieldNameValue('DateLastActive', MysqlDateTime());
      $s->AddFieldNameValue('CountVisit', 0);
      $s->AddFieldNameValue('CountDiscussions', 0);
      $s->AddFieldNameValue('CountComments', 0);
      $s->AddFieldNameValue('RoleID', $UserManager->Context->Configuration['DEFAULT_ROLE']);
      $s->AddFieldNameValue('StyleID', 0);
      $s->AddFieldNameValue('UtilizeEmail', $UserManager->Context->Configuration['DEFAULT_EMAIL_VISIBLE']);
      $s->AddFieldNameValue('Attributes', '');
      $s->AddFieldNameValue('RemoteIp', GetRemoteIp(1));      
      $s->AddFieldNameValue('user_nicename', $SafeUser->Name);
      $s->AddFieldNameValue('user_url', 'http://');
      $s->AddFieldNameValue('user_activation_key', '');
      $s->AddFieldNameValue('user_status', '0');
      $s->AddFieldNameValue('display_name', $SafeUser->Name);
   }
   $Context->AddToDelegate('UserManager',
      'PreDataInsert',
      'UserManager_AddWordpressFieldsToCreateUser');
}
?>

Then I signed into Vanilla with my administrative username and enabled the extension in the settings tab / extensions form. Then I went to the settings tab / registration management and changed the “New member role” to “Member” since I want people to be automatically signed in when they register for Vanilla.

Next I signed out of Vanilla and went to Vanilla’s “Apply for Membership” form and tried it out. Sure enough it signed me in with my new account. When I went back down to wordpress, I was still signed in as my new user and I had basic admin priviledges.

Conclusion

The code and examples in this document are not meant for a production environment. I have not tried this code on a live server, and there may be gotcha’s that I don’t know about because I’m not a well-versed wordpress user. If anyone has anything to add to this document, I invite you to do so.

All told I’ve spent about three hours working on this document and getting my first Wordpress / Vanilla integration up and running. It is really that easy to get the job done with Vanilla. The only remaining question is: where do you want your users to sign in and register? Through the Vanilla forms or the Wordpress forms. The choice is yours.

 
 
 
 
vanilla/integration/wordpress.txt · Last modified: 2009/03/28 14:19
Vanilla 1 Documentation archive (Wiki by DokuWiki)