Possible solutions for Memberships 2 Pro and CPT

First of all, I really love my switch to the Memberships 2 plugin. Love to work with that!

I'll present as clearly but short as I can. Here's what I'm working on (site is open for now:slight_smile:

I'm building a site in Norway for alternative practitioners. Two main functions of this site.

• To list practitioners, being able to filter them
• To display a user profile for them

The CPT, filtering, list views and profile pages is built using the complex Toolset plugin series. (https://wp-types.com/)

It's fine to set up CPT to display the profiles with custom fields. It's also fine, by using Toolset, to add frontend forms for the CPT.

But here's my dilemma:

• If a user signs out of the membership, how can I hide their profile/CPT?

A CPT is not connected to a user any other than as an author. Could that be a method? That CPT post does not know about any membership status.

In Toolset plugin, there are conditional output functions without programming using their plugin interface, like here: https://monosnap.com/file/Oqss4TFNl7cjBf2fcRgLOsCppbNOcK

I was thinking there was some custom field having a status for membership valid or not. But still, when adding this to the loop for the CPT list, it's not connected to who the post belongs to.

Hoping this makes sense.

What I would like to acheive is when users either sign out or don't pay the membership, their CPT profile posts go offline on the site.


  • Rupok

    Hi Johnny,

    Thanks for sending all these details but I'm afraid, I'm still a little bit confused. Can you please help me in understanding those?

    First of all, which profile are you referring to? The Dashboard user profile, or did you create front-end profiles for your users with any plugin? If Dashboard user profile, then you can protect User Profile link in backend for subscribed members by enabling the "Admin Side Protection" add-on from "Dashboard > Membership 2 Pro > Add-ons" section. After enabling the addon, please go to "Dashboard > Membership 2 Pro > Protection Rules" section. From there, you can hide user profile page from non-members. If you have a front-end profile for your users, and want to protect that, then I think the easiest workaround will be editing that front-end profile template and using Membership 2 Pro protection shortcode.

    For example, you can protect that profile template code in the following way:

    <?php echo do_shortcode( '[ms-protect-content id="1, 2"]' . your_profile_template_code_goes_here. '[/ms-protect-content]' ); ?>
    So when your front-end profile page code will be rendering, it will only render if the viewer is already logged in and a member of either membership ID 1 or 2.

    You don't need to put full template code inside the shortcodes, you can just put the part responsible for the output which you want to lock for members in profile page.

    As you said "their CPT profile posts go offline on the site", I got a little bit confused. Did you mean profile page or Custom Post Type posts? Can you please describe a little more? That will help us to understand your requirements better and we can guide you better if we are 100% clear about your configuration and requirement.

    Please send us as much details as you can with real examples. I'm looking forward to hearing from you and resolving this issue as soon as possible.

    Have a nice day. Cheers!

  • Johnny


    Hm, this is not really what I mean. Did you check the first link in my first post? This shows the example.

    1. I'm using Memberships 2 to have users join a membership
    2. I have created front-end forms for adding an online public profile, which is a custom post type I made with the Toolset plugin.

    What I'm trying to figure out is how I control if their public profile listing should be visible or not, based on their paid or canceled membership.

    If they don't pay or cancel, that custom post type showing their public practitioner profile should go away.

    I have granted support access for that site regarding another ticket. So it's open.

  • Rupok

    Hi Johnny,

    Thanks for the clarification. Now it's clear to me. Usually, we restrict custom post type posts based on the viewer's membership status. But in this case, you want to hide custom post type posts according to the profile person's membership status, which is complex. Here, you will have to bind these posts to users programmatically because currently, there is no way to find out if that profile person has any real account on your site or not (unless I'm missing something). When each profile is attached with any real member, then you can check if that member has any paid membership or not (that will be complex too). So the workaround will be:

    1. Attach real users to posts.
    2. Create a custom field called "Status" (you can name it whatever you want actually).
    3. Populate that custom field value to "active" or "inactive" programmatically by checking the attached user’s membership status.
    4. Customize your custom post type archive loop in such a way that it will first check the value of "Status" custom field. If the value is "active", it will add in the loop, if "inactive", then it will skip that post and proceed.

    Please let us know what you think about this. If you want to know how you can check a user's membership status, this might give you idea regarding how you can check that: https://premium.wpmudev.org/forums/topic/how-to-check-if-a-user-belongs-to-a-subscription-level#post-899342

    It's an old thread but it should work.

    Please let us know if you have any confusion. We will be glad to help further.

    Have a nice day. Cheers!

  • Johnny

    Good day,

    Thank you for this fulfilling explanation. I see what you mean, and it's what I have been thinking about. But what stops me is that I'm not really a programmer. I'm good at figuring things out, though. But this one is a little too much for my designer brain :slight_smile:

    I have spent a few hours today trying to figure out how, first of all, to attach users to their posts. With the Toolset plugin, I can create custom fields, and I did. It also seems like I can attach existing custom fields to posts. I find a lot of them relating to the plugin, but don't know which one that would return a useful membership status.

    How to popular that custom field programmatically is out of my range. I studied the codes in the links, but where to I stuff that code? ^^

    4. In Toolset there is a Conditional Output short-coder that I can use. This can bring in different custom fields and post fields, and display content based on the value.

    But the first steps have to be in place first.

    Btw, I have also asked the support forum for the Toolset plugin. He basically gave the same (shorter) reponse:

    Hello. Thank you for contacting the Toolset support.

    Well - here you need one custom field which stores the value that user is paid or not. If user pays the field should be saved with 1 and if the user does not pay the field should be saved with 0 and this field should be associated with CPT you create. You should ask membership pro about the available API hooks/filters Docs and on payment success hook you should update this field

    F.ex, here's the code for the "View" I have created for the members listing:

    As you see, I have been hacking on this myself, based on what I observed in the code template via your link. Even if that statement would work, the posts is stil probably not attached to a user.

    My site is still open for support access if you wanna have a look.

    Thanks so much btw.

  • Rupok

    Hi Johnny,

    I really appreciate your effort. But I'm afraid, the way you made the condition in your given screenshot, won't work. A quick workaround (though it won't be automatic) will be creating an additional custom field and manually set value as "active" or "inactive" in that custom field. Then in the loop, check the value of that custom field. If the value is "active", then continue, if the value is "inactive", then skip that post. And for attaching users, you can add another custom post and enter user ID as value. In this way, you can get which user is referred by each posts. What do you think?

    If you still want to automate this (which will require very advance custom coding), and as you said, you are not an advanced programmer, I think, the best way will be hiring a developer. You can always hire a developer from our Jobs Section for custom jobs like this one. If this was something which can be done in 10 - 15 minutes, we would be glad to do this for you. But I'm afraid, this will take much longer than that, and will require very advanced custom coding which is beyond our scope. Please keep in mind, developers found in our Jobs Section are not associated with us in any way. So please communicate with them well before you make any payments to them.

    Please let us know if you have any confusion. We will be glad to help.

    Have a nice day. Cheers!

  • Johnny


    Okey, I see. Yes, I have already done like you suggested. But only for the user to decide if the profile should be visible or not. I'm thinking I can combine that condition with both use filed and a hidden admin field, condition both to yes, and keep it like this for now.

    I would like to automate this function soon and will look into finding a programmer. I got a guy on my team. If not I will check your job boards.

    Thanks :slight_smile:

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.