Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Created December 1, 2015 12:55
Show Gist options
  • Save JudeRosario/02374847a73f3826a1c7 to your computer and use it in GitHub Desktop.
Save JudeRosario/02374847a73f3826a1c7 to your computer and use it in GitHub Desktop.
Membership 2 PRO
$api = ms_api();
$member = $api->get_current_member();
// Check if current user is in certain membership:
$membership_id = 100; // hardcode the ID.
$membership_id = $api->get_membership_id( 'premium' ); // fetch by membership name.
if ( $member->has_membership( $membership_id ) ) {
echo "You are member of " . $membership_id;
}
// Get the membership of the current user:
$membership = $api->detect_membership();
echo "First membership: " . $membership->name;
// Note: If multiple-memberships is enabled, this will return only the first membership!
// Get all memberships of the current user (multiple memberships)
foreach ( $member->subscriptions as $subscription ) {
// Note: Double check if user has_membership() to filter out expired/pending subscriptions
if ( ! $member->has_membership( $subscription->membership_id ) ) {
continue;
}
$membership = $subscription->get_membership();
echo "<br>Your membership: " . $membership->name;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment