This documentation is only for developers. If you are not a developer with good PHP coding skills then you have no need to read this.
WP eMember plugin has an API that allows you to create a member account using a standard HTTP GET or POST request.
Enabling the API
If you want to use this API then you need to enable it from the settings menu of the plugin first.
Go to the settings menu then scroll down to the “Additional Integration Options” section to find the option.
The following is a screenshot of this section in the settings menu:
It is very important that you do not reveal the Secret Word/API key to anyone else.
Using the API
Once you enable it, you can start to send HTTP request to the following URL to create member account remotely or from another software:
http://www.example.com/wp-content/plugins/wp-eMember/api/create.php
You need a minimum of 5 pieces of information to create a member account using a HTTP request. These are:
- Secret Word/API Key (you specified it in the settings menu of the plugin)
- First Name
- Last Name
- Email Address
- Membership Level ID
Optionally, you can pass in the following data with the request (if you do not pass these, a randomly generated value will be used for these)
- username
- password
1. Creating Member Account Using HTTP GET request
In order to create a member account via HTTP GET use the following format:
http://www.example.com/wp-content/plugins/wp-eMember/api/create.php?secret_key=XX&first_name=XX&last_name=XX&email=XX&membership_level_id=XX
Replace the ‘example.com’ and ‘XX’ with the appropriate values.
PHP Code Example:The following is an example of how to construct this link using PHP:
$secret_key = "6bd39ewe43a7bb"; $first_name= "Jon"; $last_name= "Doe"; $email= "[email protected]"; $membership_level_id= "1"; $prepared_data = "?secret_key=".$secret_key."&first_name=".$first_name."&last_name=". $last_name."&email=".$email."&membership_level_id=".$membership_level_id; $get_url = "http://www.example.com/wp-content/plugins/wp-eMember/api/create.php".$prepared_data; // Execute this GET Request file_get_contents($get_url);
2. Creating Member Account Using HTTP POST request
To create a member account via HTTP POST use the following format:
<form method="post" action="http://www.example.com/wp-content/plugins/wp-eMmeber/api/create.php"> <input type="hidden" name="secret_key" value="XX"> <input type="hidden" name="first_name" value="XX"> <input type="hidden" name="last_name" value="XX"> <input type="hidden" name="email" value="XX"> <input type="hidden" name="membership_level_id" value="XX"> <input type=submit value="Submit Post"> </form>
Replace the ‘example.com’ and ‘XX’ with the appropriate value.
Passing Additional Field Values
You can optionally pass additional field values using the following parameters in your request:
- phone
- address_street
- address_city
- address_state
- address_zipcode
- country
- gender
- company_name
Hi;
I ended up doing this. This is my opt in page:
include “../../../wp-load.php”;
include_once(‘../../../wp-includes/class-phpass.php’);
$wp_hasher = new PasswordHash(8, TRUE);
$hashed_password = $wp_hasher->HashPassword($_POST[‘password’]);
$wpdb->insert(‘wp_wp_eMember_members_tbl’, array(’email’=>$_POST[’email’], ‘password’ => $hashed_password));
$wpdb->show_errors();
@Seyed, don’t generate the password yourself. Pass the plain text password using the “password” parameter. The API will do the necessary encrypting before saving it to the database.
Hi;
I am writing a php script that adds the user manually. It all works fine I just dont know how to generate the password.
Can you please let me know how to generate a password like “$P$BMxD/c24E/wjzSg1KYvToMp.fMCACV1” ?
Thanks
THIS WORK, Thank you. I had an error in my code, I repeated a parameter when I programmed the function.
function activarFormacionGO($nombre, $apellido, $email, $nivelMiembro, $usuario, $password){
$url = “example.com/path/to/the/api/script”;
$postfields = array();
$postfields[“secret_key”] = ‘xxxxxxxxxxxxxxxxx’; // API Key
$postfields[“first_name”] = $nombre;
$postfields[“last_name”] = $apellido;
$postfields[“email”] = $email;
$postfields[“membership_level_id”] = $nivelMiembro;
$postfields[“username”] = $usuario;
$postfields[“password”] = $password;
$query_string = “”;
foreach ($postfields AS $k=>$v) $query_string .= “$k=”.urlencode($v).”&”;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$xml = curl_exec($ch);
if (curl_error($ch) || !$xml) $xml = ‘error’.
‘Error de Conexion’.
curl_errno($ch).’ – ‘.curl_error($ch).”;
curl_close($ch);
$arr = whmcs_xml_parser($xml); # Parse XML
}
@Pedro, yes you can pass the “password” value to this API also. Are you sending the password value using an input field with the name “password”?
Hi, I am using this API for generating users.
This API work perfect, but when i pass the password is generated random too i want use my password and not random.
Is possible?
Scratch that! Just spotted that you only need the email address to successfully run deactivate.php. Great stuff.
Great tutorial – for now I will also want to deactivate members using an external form, but I notice that the deactivate.php function needs the member_id. What is the easiest way to get hold of the member_id do I can store it in my external database?
Thanks, Hywel
@Gene, Yes you can specify the membership level ID in the request via the “membership_level_id” parameter.
Can I assign a member to a specific membership with this API?
Thanks for the support