Last active
October 30, 2020 21:25
-
-
Save strangerstudios/9f8c0bc82cb02e127afc to your computer and use it in GitHub Desktop.
Very basic custom RESTful API to check the membership level of a Paid Memberships Pro User
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Call to http://yoursite.com/[email protected]&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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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);