Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Very basic custom RESTful API to check the membership level of a Paid Memberships Pro User
/*
Call to http://yoursite.com/?verify=email@domain.com&secret=SOMESECRETHERE to check the membership level of a user.
*/
function my_init_pmpro_mini_api()
{
if(function_exists('pmpro_getMembershipLevelForUser') &&
!empty($_REQUEST['verify']) &&
!empty($_REQUEST['secret']))
{
if($_REQUEST['secret'] != "SOMESECRETHERE")
wp_die("Invalid secret.");
$user = get_user_by("email", str_replace(" ", "+", ($_REQUEST['verify'])));
if(empty($user))
wp_die("User not found.");
$membership_level = pmpro_getMembershipLevelForUser();
if(empty($membership_level))
die("0");
//user and membership level found, output json encoded membership level info
echo json_encode($membership_level);
exit;
}
}
add_action('init', 'my_init_pmpro_mini_api');
@Awzaw

This comment has been minimized.

Copy link

@Awzaw Awzaw commented Jan 27, 2020

Hi, I think https://gist.github.com/strangerstudios/9f8c0bc82cb02e127afc#file-my_init_pmpro_mini_api-php-L17 should be:

$membership_level = pmpro_getMembershipLevelForUser($user->ID);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment