Using the API, Creating an is_premium_user()-function.

Hey, I was trying to use the API classes to get membership status for members. Unfortunately "has_membership()" only returns true on admins. Anyway, let's take it from the beginning.

I do several things for paying members directly in my theme. With membership I used something like this:

if(function_exists('current_user_on_level')) {
return ( current_user_on_level( PREMIUM_LEVEL_ID ) || current_user_can( 'manage_options' ) );
}

Since current_user_on_level() doesn't exist in Membership 2, I needed to find another way. I found the API and tried something like this:

if( apply_filters( 'ms_active', false ) ) {
$api = MS_Plugin::$api;

$member = $api->get_current_member();

return is_user_logged_in() && $member->has_membership();
}

Like I said, this only returns true for me, the admin but if I check the data for another member it return false. Somehow what I get is also a membership with an ID that doesn't exist and a subscription with ID 0. The user has an active subscription so there must be something I'm missing or the API doesn't work. Could anyone help me writing the function to distinguish between paying and non paying customers? It is also OK if I can check "if not default user" with an ID or something.

Looking forward to some help on this, since my premium content is now temporarily available to everyone logged in :slight_smile: