How to get logged-in user membership id from "Membership 2 Pro" plugin with Hook

I want to get current logged-in user membership id from “Membership 2 Pro” plugin in my custom plugin.

Is there any hook to get login user membership id.

  • Sajid
    • DEV MAN’s Sidekick

    Hi JC,

    Hope you are doing good today :slight_smile:

    There is no function available right in the plugin but you can get the ID(s) of a member’s membership by using the following code snippet.

    $member = MS_Model_Member::get_current_member();

    foreach ( $member->subscriptions as $subscription ) {
    $membership = $subscription->get_membership();

    $membership_id[] = $membership->id;

    $membership_id array will contain the ID(s) of memberships of current logged in user.

    Using the following conditional tag, you can also check if the user is member of membership ID 123.

    $member = MS_Model_Member::get_current_member();

    if ( $member->has_membership( 123 ) ) {
    echo "Thanks for subscribing to membership 123";

    For full documentation of Membership 2 API please go to Membership 2- > Help -> API Docs.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,


  • CB
    • Flash Drive

    I tried the above code to check the membership status of a different user

    $member = MS_Model_Member::get_member( $user_id );

    I get the following error: Call to undefined method MS_Model_Member::get_member

    Any suggestions? Thanks in advance.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.