Multiple Memberships Allowed - Leads to Duplicate Messages

I'm using Membership 2 Pro. I have "users can join multiple memberships" add-on enabled.

The problem I've just run into is that when using [ms-protect-content id="XXXX"] shortcode to create different messages for different users, if a user has two memberships, he sees both messages at the same time. This has led to some really awkwardly-worded pages, with almost-duplicate information.

Is there a way around this? A way to prefer one message over the other, somehow? Or an "and" option (if they have XXX and YYY memberships, see "this" message)? Hopefully it's there and I just haven't found it yet. :slight_smile:

  • Milan

    Hello kalico,

    Hope you are well today and thanks fora asking us. :slight_smile:

    I am sorry but I am facing little bit difficulty in understanding your question. Can you please tell me step by step what you want to achieve ?

    Furthermore if we talk about [ms-protect-content] shortcode then it does allow multiple membership ids to be added in its 'id' parameter. So in short you should be able to display same message for multiple membership. ?

    [ms-protect-content id="2,3" ]

    Cheers,
    Milan

  • kalico

    Hi @milansavaliyaz

    Thanks for pointing out the "and" option. That should prove useful. However, it's not quite getting me where I need to be. The simplest way I can put it is with code logic. Let's say we have two memberships, gold and silver. A user can be a member of either one, or both.

    What seems to be happening now is this (including the "and" scenario you provided):

    if (gold)
     "display message for gold"
    if (silver)
     "display message for silver"
    if (gold & silver)
     "display message for gold and silver"

    What I want to do is:

    if (gold)
     "display message for gold"
    elseif (silver)
     "display message for silver"
    elseif (gold & silver)
     "display message for gold and silver"

    Does that make more sense?

    Actually this would be equally helpful:

    if (gold)
     "display message for gold"
    elseif (silver)
     "display message for silver"
    
    if (gold & silver)
     "display message for gold and silver"

    The main idea is to make the message for gold and the message for silver mutually exclusive, so they do not both show up at the same time for a user who is in both groups.

    Thanks for any suggestions. :slight_smile:

  • Predrag Dubajic

    Hi Kalico,

    I was checking your installation to better understand this but I'm not sure I'm looking at a right page, can you tell me which page is using this so I could catch up here? :slight_smile:

    If I did got it correctly you can try out something like this:

    [ms-protect-content id="G" silent="yes"]
    Show to Gold
    [/ms-protect-content]
    
    [ms-protect-content id="G" access="no" silent="yes"]
    [ms-protect-content id="S" silent="yes"]
    Show to Silver
    [/ms-protect-content]

    ID's are shown as G - gold and S - silver so replace those with correct ID's of your memberships.

    Let me know if that works for you :slight_smile:

    Best regards,
    Predrag

  • kalico

    Hi @dubajicp1

    Wow, thanks! How did I miss that? I was ignoring all those potential arguments. And even if I had been trying them I don't think I would ever have considered nesting them like that, with a single closing tag.

    I'm fascinated by this approach! I'm still not sure I fully understand the logic behind how these two arguments interact with each other, but I do think you've got me aimed in the right direction. :slight_smile:

    I may need you to look at the site if I can't get this working right, but for now, I just have one question:

    What would be the suggested code for making a message visible ONLY to users who are a member of both Gold *AND* Silver? Members who have just Gold or just Silver would not see this message.

    Is that possible?

  • Milan

    Hello kalico,

    I hope you are having a good day. :slight_smile:

    I am sorry but displaying message to members of multiple membership ( with And Condition applied to it) is not possible as a out of box feature, so you won't be able to display message to users who are having gold and silver membership with [ms-protect-content] shortcode.

    But for you I've created new shortcode based on [ms-protect-content] shortcode which will do job of displaying message only if member belongs to each supplied memberships( as Id ). I've exposed that shortcode as a plugin and attached it with this post. Please download attached zip with this post and extract folder in it to /wp-content/ folder of your site. Then go to Plugins > Installed > Custom Protect Content Shortcode for Membership 2 Pro and activate it. In case if you lose this copy, you can always get latest and updated code from my gist.
    https://gist.github.com/MilanSavaliya/d90904ff35e04c00031fc796b47a71ad

    ====================
    Sample Usage
    ====================

    [wpmu-custom-ms-protect-content id="125,126" access="no" msg="YOUR CUSTOM MESSAGE"]
    Protected Content
    [/wpmu-custom-ms-protect-content]

    Hope this helps you. Please ping me back if you need some clarification or further help regarding this.
    Enjoy WPMU DEV. :slight_smile:
    Best Regards,
    Milan

  • kalico

    Hi Milan

    You rock!!! Thanks so much for doing this. I can't wait to try it out. :slight_smile:

    I do have one question: I need someone to explain to me the logic behind the "access", "silent", and "msg" arguments for the [ms-protect-content] (and yours) shortcode.

    I've read all the documentation, but I'm still not grasping the right way to make them work together. I think I must have a very basic level of misunderstanding about the way it's designed. I expect to put a message in (between) the shortcode open and close tags, and have that message display (or not) based on the user's membership. So I don't understand how "access" (yes or no) changes that, or why I would add a "msg" and also put something between the open/close tags. And then there's "silent"....I'm displaying something, so why would I want to hide it...? You can see, I'm just a little lost....lol :slight_smile:

    I just need more details, I guess. Thanks in advance :slight_smile:

  • Predrag Dubajic

    Hi kalico,

    Shortcode attributes could be bit complicated so I'll give you few examples below to explain what those additional attributes do.

    silent - is for hiding protection message, with this disabled (by default) users that don't have access will see protection message.
    For example, if you use this shortcode:

    [ms-protect-content silent="yes"]
    Hello World!
    [/ms-protect-content]

    Users that don't have access won't see anything in that place, and if you do it like this:

    [ms-protect-content silent="no"]
    Hello World!
    [/ms-protect-content]

    Users that don't have access will see protection message in that place.

    access - this basically says if membership ID's in shortcode should or shouldn't have access
    For example:

    [wpmu-custom-ms-protect-content id="125,126" access="no"]
    Hello World!
    [/wpmu-custom-ms-protect-content]

    Memberships 125 and 126 will NOT have access to Hello World!, and with this:

    [wpmu-custom-ms-protect-content id="125,126"]
    Hello World!
    [/wpmu-custom-ms-protect-content]

    Memberships 125 and 126 will HAVE access to Hello World!.

    msg - that's the message that will be shown to users that don't have access to protected content

    [wpmu-custom-ms-protect-content id="125,126" access="no" msg="YOUR CUSTOM MESSAGE"]
    Hello World!
    [/wpmu-custom-ms-protect-content]

    In above example access is set to NO and ID's are 125 and 126, so all users that are not in memberships 125 and 126 will see Hello World! while members that have 125 or 126 membership will see msg content, or in this case YOUR CUSTOM MESSAGE.

    Hope this clears things up :slight_smile:

    Best regards,
    Predrag

  • kalico

    Wow, Predrag Dubajic that is very helpful.

    I just have one little point of clarification, if you please....above, in the two examples for "silent", when you refer to the "protection message" that users will or won't see, that is the protection message I've set in admin -- either for a specific membership, or the default message -- not the text (e.g., Hello World) that is between the opening and closing shortcodes. Yes?

  • kalico

    My question above (just prior to this) remains....but.....I HAVE IT WORKING NOW!!!!!!

    I am SO excited and so FREAKIN' GRATEFUL to you WPMUDEV gurus who have so generously helped with this crazy, complex thing I wanted to do. You guys are worth your weight in gold. Or hero points. :wink:

    I'm going to share the code I used in my /membership and /protected-content pages. It might help someone else someday. :slight_smile:

    In my examples below, I will use membership names in place of IDs for clarity. I'm calling our memberships APPLES and ORANGES because there is no hierarchy. We don't have a "good, better, best" model, but rather just levels of access based on the user's "security clearance level" or "need to know" status. APPLES is a special security area, and ORANGES is on a need-to-know basis. Invitation Codes are required for each one. Members can belong to one, neither, or both -- and we need to have special instructions in each case to tell the user how to sign up for another membership (or two), if they have an Invitation Code (or Codes).

    For my memberships, I have enabled:

    - Guest membership
    - Default membership
    - Standard membership -> APPLES
    - Standard membership -> ORANGES

    "Protected Content" Page

    The first part is for non-logged in users (Guest membership). It provides an option to log in via the [ms-membership-login] shortcode, and also warns the user that they still might not be able to see the page, even if they do log in.

    [ms-protect-content id="GUEST"]
    This resource is only available to users with APPLES membership.
    NOTE: You are not logged in. After logging in, you will be able to access this page if you have sufficient permissions.
    [ms-membership-login register="no"]
    [/ms-protect-content]

    The next part is for users after they log in, but they still do not have the right membership to see the protected content. Note that we are also using Invitation Codes add-on, so this tells the user how to get their APPLES membership (in other words, not everyone can sign up for APPLES, you must have an invitation).

    [ms-protect-content id="DEFAULT,ORANGES"]
    You are logged in.
    However, you do not have sufficient permissions to access this page.
    If you have an INVITATION CODE, you can use it to <a href="/memberships">upgrade</a> your account to the required permission level.
    If you do not have one, contact _________.
    [/ms-protect-content]

    "Memberships" Page

    Our membership model is complex, requires Invitation Codes, and users can belong to more than one membership (Multiple Memberships add-on), so we wanted a fully custom workflow here. The default /memberships page layout wasn't working well for us.

    (Note: There is nothing on this page for the GUEST membership, because this page is only shown to logged in users.)

    The first part here is for logged in users who do not belong to any membership.

    [ms-protect-content id="DEFAULT"]
    
    You are logged in and you have basic access to this site.
    Have you been given an INVITATION CODE? If so, click a link below to join the appropriate membership.
    [ms-membership-buy id="ORANGES" label="Join Oranges"]
    [ms-membership-buy id="APPLES" label="Join Apples"]
    
    [/ms-protect-content]

    The next part is where things get interesting. I have nested two shortcodes, thanks to the inspiration provided by Predrag Dubajic (above): the standard [ms-protect-content] shortcode that ships with M2Pro, and the awesome [wpmu-custom-ms-protect-content] shortcode that Milan cooked up in response to my plea for a "both/and" scenario to accommodate users who have two memberships.

    Here we go....

    [ms-protect-content id="APPLES" ]
    
    [wpmu-custom-ms-protect-content id="APPLES,ORANGES" access="no" msg="BLANK_SPACE"]
    
    You have the APPLES membership.
    Have you been given an ORANGES invitation code?
    [ms-membership-buy id="ORANGES" label="Join Oranges"]
    
    [/wpmu-custom-ms-protect-content]
    
    [/ms-protect-content]

    The above message displays for users that have APPLES because of the [ms-protect-content] shortcode on the outside. But nested inside, we have the [wpmu-custom-ms-protect-content] with access="no" and a blank message (really this is an empty space, but I wrote BLANK_SPACE here for clarity).

    The nested shortcode is aimed at users who have BOTH memberships, and with access set to "no" they do not see the message contained between the opening and closing shortcode tags. Instead, they see the custom message inside the msg argument -- in this case, that's nothing! That's exactly what we want, because these "both/and" users do not have only the APPLES membership -- they already have both, so they can't upgrade their membership any further. We'll explain this to them in a custom message further down the page.

    Now we do the same thing in reverse for those who have ORANGES only. In this case,

    [ms-protect-content id="ORANGES"]
    
    [wpmu-custom-ms-protect-content id="APPLES,ORANGES" access="no" msg="BLANK_SPACE"]
    
    You have access to the ORANGES section of this site.
    Have you been given an APPLES invitation code?
    [ms-membership-buy id="APPLES" label="Join Apples"]
    
    [/wpmu-custom-ms-protect-content]
    
    [/ms-protect-content]

    Again, here ^ we are showing nothing to the both/and users.

    And now, the Grande Finale....we get to show our special custom message to our both/and users:

    [wpmu-custom-ms-protect-content id="APPLES,ORANGES" silent="no"]
    
    You have both APPLES and ORANGES access to this site. That's as good as it gets!
    
    [/wpmu-custom-ms-protect-content]

    The silent="no" argument says we DO want to display this content to users of this membership.

    I have to admit I was actually surprised when it all clicked. In spite of all the great advice, I didn't think I really understood what I was doing, but I just kept reading the posts above over and over until a lightbulb went on...and it was exactly the right formula to achieve our desired results.

    Once again, HUMONGOUS THANKS to the WUPMUDEV team. You guys totally rock!!

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.