WishList Member Tips  

How to add a membership level to wordpress member remotely?

Wishlist Member have a API that allow us to take control of WordPress core functions and do what we want by using simple line of code. but that is not all. You can do even  control your WordPress remotely. How it feel to add a new member ship level to your current WordPress member from another website? possibles are unlimited. Fortunately it is very simple than you think. here are an example to show you how you can do it yourself.

The same functions available to WishList Member extensions can be made available to remote applications via a simple to use REST interface. This allows developers to create a lot of different applications that control a particular WishList Member powered website remotely.

Lets start:

Silver user have no level    http://screencast.com/t/OJyWmWyrNjnl

I want to add Silver level to this user remotely.

<?php
$Fxn = 'AddUserLevels';
$Secret = 'BIKLOQRhGKLManqs';
$txnid="my-txnid-999";
$user=2;
$params = array ($user,1288000826,$txnid);
$Key = md5 ($Fxn . '__' . $Secret . '__' . implode ('|',$params));

$URL="http://example.com/?WLMAPI=$Fxn/$Key/$user/1288000826/$txnid";

//echo $URL;

$ch = curl_init ($URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$RESTReturn = curl_exec($ch);      
curl_close($ch);


echo '<br /> return value=' . $RESTReturn ."<br />";

list ($status, $return) = unserialize ($RESTReturn);
 if ($status) {
 // successful do something useful here
 var_dump ($return);
 } else {
 // failed, show error message
 echo $return;
 }

?>

Simply create a php file with name addlevel.php and copy past similar code. We need copy our file to a php enabled server and run it.

by visiting our file url ( for example Http://example.com/addlevel.php) , Silver user will be added to “silver” Member ship level remotely.
Example: http://screencast.com/t/9JfscW39Qaf

How it works?

A) We want to call “AddUserLevels” remotely.  You can call this function to add a level right inside your wordpress theme or plugin cod when wishlist member plugin is activated. but here we want to call it from another website or perhaps a standalone php file that have nothing to do with our wordpress installation.

B) What we need is user id (which is 2 here) and level silver level id (which is 1288000826 here) . we also need Secret Word that you can get from Wishlist member integration tab.

Example: http://screencast.com/t/Cq8sMmkwF

Txnid is your shopping cart transaction_id, It can be anything at our example.

C) Replace your own similar variables. If you save it and run it. You will see a message like a:2:{i:0;b:1;i:1;b:1;} that shows result is successful.

If you echo $url value, you will see a url like

http://example.com/?WLMAPI=AddUserLevels/d8feb2f5ff2add0c558e768a4d6581b1/2/1288000826/my-txnid-999

Just   visiting above url is enough to add our user to silver level. we used curl to make it happen from inside our code.

Note: if your secret word or parameters are wrong you will get a message like a:2:{i:0;b:0;i:1;s:20:”AUTHORIZATION FAILED”;}

Note. Order of parameters are important.

More information can be found at Wishlistmember API Quide.

Do you need farther help on this topic? Contact me
Do you need Professional coder? Hire me
Looking for different WordPress plugin? Try Wishlist member


Andy is one of core WordPress WishList Member Developer. He is in love with WordPress and fun of turning new ideas to WordPress plugin or theme.

Add your comment


  1. Dan
    January 27, 2012
    10:47 am

    Hi Andy, thank you so much for this little piece of code. I don’t know much about API but you really make it easy for us this way.

    Cheers!

RSS feed for comments on this post. TrackBack URL

Add your comment.





( DoFollow )

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Home | Themes | Plugins | Download | Forum | Freelance | Resume | Projects | Service | Contact | About
© Copyright 2009 - 2014 Hecode.com