PHP – Import DigitalAccessPass existing users into vbulletin 5 connect for auto-login

I work for many customers who has business model of online sales of digital products like ebooks, video tutorials, premium articles and forums discussion are using DAP for defining user access levels for their wordpress articles.

dap-vb5

Vbulletin Connect is 5th version of vbulletin has huge code changes than vbulletin < 5. So, if you want to make external plugins using its old functions it might not always work. To integrate DigitalAccessPass with vb5, login to your DAP account and find [LATEST] DAP v4.5.2 link.

Now let’s do basic integration with vbulletin5 with DAP as explained here. They all works fine except this one.

4. Update dap-config.php under the dap folder

Run the following command – http://www.yoursite.com/dap/getpath.php (replace yoursite.com with the name of your site)

It won’t work for vbulletin5.

Try this to make it work.

  1. Open your DigitalAccessPass config file (dap-config.php)
  2. Run http://www.yoursite.com/dap/getpath.php as stated in above documentation.
    let’s say it’s 

    /home/web/public_html/forum/core
  3. Append following line
    // make sure you append /core after the path you get from getpath.php
    define('VBFORUMPATH', '/home/vault/public_html/forum/core');
    define('TABLE_PREFIX', 'vb_'); // your vb forum db tables prefix
    define('AUTO_CREATE_VB_ACCOUNT_UPON_DAP_REG', 'Y'); 
    
    require_once("dap-settings.php");

After that, You are ready for forum integration. Follow instructions from this video and sync session between vbulletin and DigitalAccessPass by defining your DigitalAccessPass products to vbulletin forums access level.  So, from now whenever new user make purchase from DAP and creates account, vbulletin also makes his account.

But what about user already made purchases and want to auto-login into vbulletin as soon as they login into your wordpress’s DigitalAccessPass?

Probably, you would consider vbulletin impex import plugin to import users from DAP. Yes, it’s one of the option. But it won’t work if your user didn’t chosen username in your DAP account as it needs only email/password combination for login while vbulletin explicitly need username to map with DAP account.

So, We’ll code a script using DAP plugin API that auto-import userdata from DAP and creates login for them in vbulletin5.

Create php script within /dap directory (lets say dap2vb.php) and all records from dap users table with simple php code.

$link = mysql_connect("localhost","USER","PASS");

if(!$link) {
	echo "Unable to connect";
	exit;
}

$db_selected = mysql_select_db("vault_wp",$link);

if (!$db_selected) {
    die ('Can\'t use foo : ' . mysql_error());
}

$query = 'select * from dap_users where user_name is NOT NULL order by id asc';

$result = mysql_query($query,$link);

while($D = mysql_fetch_array($result)){
 // $D will contain all user data
}

Let’s make automatic username by concatenating their firstname with lastname  for DigitalAccessPass for users didn’t choose login yet.

$query = 'select LCASE(CONCAT(first_name,last_name)) as username,id from dap_users where user_name is NULL';
$result = mysql_query($query,$link);
while($D = mysql_fetch_array($result)){
	$u =  addslashes($D['username']);
	$i =  $D['id'];
	$q = "update dap_users set user_name='$u' where id = $i";
	$r = mysql_query($q,$link);
	if(!$r) {
		echo mysql_error();
	}
}

Include following php files from DAP plugin direcrory in this script.

require_once('/public_html/dap/dap-config.php');
require_once('/public_html/dap/plugins/vbulletin/Dap_Vbulletin.class.php');

Now we fetched all DAP users into array, next step is to use DAP plugin api to auto-create login ito vb forum. Iterate through all users and call registerUser method.

while ( $D = mysql_fetch_array($result) ) {
  $forum = new Dap_Vbulletin();
  $dapuser = Dap_User::loadUserById($D['id']);
  $errmsg = $forum->registerUser($dapuser,1);
}

Finally Run this php script and your all DigitalAccessPass logins will be imported into vbulletin.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

 
Previous Post

Coding chrome desktop notification in jQuery

Next Post

How to know if HTML checkbox is checked in any version of jQuery

Related Posts