0

Hello I'm trying to retrieve membership levels for any given user from a desktop application , after I did some research I have found this code :

/*
Call to http://yoursite.com/?verify=email@domain.com&secret=CHECK 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'] != "CHECK")
        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');

My question is : in witch file should I add this snippet in order for my website to start responding to those requests?

  • without knowing more about the plugin you're referring to, and judging simply by the line add_action('init', 'my_init_pmpro_mini_api'); I'd say either the functions.php of your theme, or perhaps from your own plugin. – hwl Aug 7 '17 at 11:56
0

First you will need to have the plugin installed (paidmembershipspro ) otherwise you wont be able to call the function "pmpro_getMembershipLevelForUser" and then you just need to copy the code below to your functions.php file which is inside your WordPress theme.

/*
Call to http://yoursite.com/?verify=email@domain.com&secret=CHECK 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'] != "CHECK")
    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');
  • didn't work when adding to theme and the plugin doesn't have a function.php file , – Hamza Hmidi Aug 8 '17 at 1:41
  • Got it to wok thank's , the cashing plugin was the problem – Hamza Hmidi Aug 8 '17 at 1:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.