Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cartpauj/60ef72af2cc5ecb9da618e003f48bb71 to your computer and use it in GitHub Desktop.
Save cartpauj/60ef72af2cc5ecb9da618e003f48bb71 to your computer and use it in GitHub Desktop.
How to add a Member and Transaction and Send a Welcome Email to the Member with MemberPress Developer Tools API
<?php
$url = 'http://testsite.w6.wpsandbox.pro/wp-json/mp/v1/members';
$ch = curl_init($url);
$data_string = json_encode(
[
'email' => '[email protected]',
'username' => '[email protected]',
'first_name' => 'test',
'last_name' => 'test_last_name',
'send_welcome_email' => true,
'transaction' => [
'membership' => 376, // ID of the Membership
'amount' => '0.00',
'total' => '0.00',
'tax_amount' => '0.00',
'tax_rate' => '0.000',
'trans_num' => 'mp-txn-'.uniqid(),
'status' => 'complete',
'gateway' => 'free',
'created_at' => gmdate('c'),
'expires_at' => '0000-00-00 00:00:00'
]
]
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt(
$ch,
CURLOPT_POSTFIELDS,
$data_string
);
$header = array();
$header[] = 'MEMBERPRESS-API-KEY: MgCUGSO5Qg'; // Your API KEY from MemberPress Developer Tools Here
$header[] = 'Content-Type: application/json';
$header[] = 'Content-Length: ' . strlen($data_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$response = curl_exec($ch);
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
echo $response;
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment