I'm trying to integrate an Android and Windows APP with my site. At this point, I am working 'offline' at my windows localhost site. Everything seems to be set up properly. I have 3 users: Wordpress admin + two others. I have set 2 membership levels - one free one paid. I need to get the level(s) for a user by his email address.

I have added the following to the theme functions.php file:


/*
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))
      wp_die("Membership Level Empty");

  //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');

The only response I get, besides for unknown user is the "Membership Level Empty". It knows that the user is valid, but it does not return anything useful.

Any pointer would be apreciated

up vote 1 down vote accepted

pmpro_getMembershipLevelForUser returns membership level for current user if parameter is not specified, and it will be anonymous user with high probability (depending on how you call it).

Use

pmpro_getMembershipLevelForUser($user->ID)

instead of

pmpro_getMembershipLevelForUser()

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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