• Resolved Pradeep

    (@pmaheepala)


    Hello,

    Could someone kindly explain how to find the membership status of any user within the users list using a function (php)? I am referring to WordPress users list not the Members 2 members list. I want to check the membership level of users within the loop and display something depending on their membership levels.

    Many thanks in advance!

Viewing 12 replies - 1 through 12 (of 12 total)
  • You can try this Link
    https://premium.wpmudev.org/forums/topic/how-to-read-out-the-membership-level-from-the-database

    From there, whatever may the return value you should be able to run php condition statement on it

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hey @pmaheepala,

    Hope you’re well.

    Like @goodmuyis mention you can check that forum post.

    Basically this code can get member as Membership 2 object;
    $member = MS_Model_Member::get_current_member();

    And you can find registered memberships id with this code;
    $member->get_membership_ids();

    Hope this helps!

    Cheers,
    Oguz

    Thread Starter Pradeep

    (@pmaheepala)

    Hello again,

    Thanks to both @goodmuyis and @wpmudev-support8 but that’s not what I’m looking for. As it says on that linked forum post those functions only give the memberships of the ‘currently logged’ in user. What I am looking for is a way to find the active membership of every member within a BuddyPress member loop to display some extra information for those who have this particular membership.

    I guess it’s something along these but I still can’t get my head around to do it:

    https://premium.wpmudev.org/forums/topic/get-a-members-membership-level
    http://tymescripts.com/show-paid-subscribers-wpmudev-membership-2-buddypress-members-directory/

    So you need something like this image right?

    Thread Starter Pradeep

    (@pmaheepala)

    Yes and to display some extra information on their profile page based on their membership level. Many thanks in advance.

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hey @pmaheepala,

    Hope you’re well.

    Basically shared links by you is includes what you need. Like if you know how to get user id in a loop, then you can find subscriptions with this code;
    $subscriptions = MS_Model_Relationship::get_subscriptions( array( 'user_id' => $userId ));

    And you can put some if to check conditions. Is that what you are looking for? If you need fully working example with some BuddyPress loops, I am afraid it will take a long time to prepare and that’s not something we can provide. You need custom coding for that with hiring developer.

    Or maybe if @goodmuyis has working example he can share with you.

    Cheers,
    Oguz

    Thread Starter Pradeep

    (@pmaheepala)

    Hello @wpmudev-support8,

    I am fine with BuddyPress loops and other things. I’m just trying to find an efficient way to get the existing subscriptions of a user, using the user id. For example something like this without having to get all user ids and subscriptions:

    if (in_array("gold", (array) $user->subscriptions )) {
    -
    -}

    If there is a method, please share. If not I’ll use a different method to sort this out. Thanks!

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hey @pmaheepala,

    Hope you’re well.

    I am afraid I don’t have ready to use codes, you should populate necessary variables from $subscriptions that I shared above and use in conditions.

    Cheers,
    Oguz

    Thread Starter Pradeep

    (@pmaheepala)

    Hello @wpmudev-support8,

    Sorry if I didn’t make it clear enough. I am not asking for a ready to use code. I am asking if there’s a ‘function’ to get a member’s subscription using their username/user ID. For example something like: xxxgetsubscriptions(userid). The only one I found gets the subscriptions of the currently logged in user, which is useless for this scenario.

    Thanks,

    Plugin Support Adam – WPMU DEV Support

    (@wpmudev-support8)

    Hey @pmaheepala,

    Hope you’re well.

    I already shared you a function above. Did you try that code?
    $subscriptions = MS_Model_Relationship::get_subscriptions( array( 'user_id' => $userId ));

    As you can see you are specifying user_id in the code. You just need to find user id with any method as you wish and assign it to $userId.

    Cheers,
    Oguz

    Plugin Support Pawel – WPMU DEV Support

    (@wpmudev-support9)

    Hello @pmaheepala

    Hope you’re doing well!

    We’ve not heard from you in a while. I’ve marked this ticket as resolved for now, but if you need anything else at all, we’re here for you, please just reopen the ticket or create a new one.

    Kind regards,
    Nastia

    Thread Starter Pradeep

    (@pmaheepala)

    Yes this is resolved as I managed to get it done through a combination of everything we’ve discussed in here. Thanks for all the support.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Checking the membership status of a user’ is closed to new replies.