Membership 2 Protect Fields

Hello, we would like to protect the content of some fields, for example telephone, or email of custom type post, in order to show these fields only to members.
It will be great to protect certain custom press fields
Is that possible?.


  • Milan
    • WordPress Wizard

    Hello @Estela Cantabra,

    I hope you are having a good day and thanks for asking. :slight_smile:

    At this moment this is not possible out of box with membership 2 pro. You can protect whole custom post type post via Individual Custom Post Type addon of membership 2 pro which you can find via Membership > Addon > Individual Custom Post Type

    Custom Press's custom field is not tightly integrated with Membership 2 pro. So there isn't any inbuilt mechanism like granular custom field protection with membership 2 pro. But this can be good feature. So I am moving this thread to features request category so other member can also show their support for this.

    One workaround i think you can implement, but it requires editing core template files of custom post type. Membership 2 pro comes with nice API for checking current user is in specific membership level or not. You can determine current user's membership and then use some kind of conditional logic to protect output of custom field.

    If you need help with it let me know. :slight_smile:

    I hope this helps you.

    Please let me know if there is anything else I can help you with.


  • Estela Cantabra
    • New Recruit

    Hello, and thanks for your answer. We have used shortcodes in the fields we would like to protect and it´s working. But i would like to try your solution to determine the user membership level. Can you tell me what files I have to modify. Also, if you can send me an example of this, will be great.


  • Milan
    • WordPress Wizard

    Hello @Estela Cantabra,

    I hope you are having a good day.

    Ohkay I hope you are ready to do some custom coding. :slight_smile:

    #1) First of all you need to create single template file for your custom post type. You can do this vai Custompress > Settings > Template fiel > Select your custom post typye ( slug ). And finally save changes.

    This will create "single-[post_type].php" file inside your active theme directory by copying your current single.php template. This file will be the custom template for your custom post type. You can then edit and customize it.
    In some cases you may not want to do that. For example if you don't have a template for your custom post type the default "single.php" will be used.
    Your active theme folder permissions have to be set to 777 for this option to work. After the file is created you can set your active theme directory permissions back to 755.

    Once your file is ready you can review it and customize its content markup the way you want to. :slight_smile:

    #2) Now navigate to Custompress > Content Types > Custom Fields . And create custom fields for your custom post type. I am sure you already have setup custom fields. :slight_smile:

    Now you need to understand the shortcode syntax of custom fields, to know more how it works, just click on link saying "Embed Code" which displays when you hover over custom field.

    Digest each piece of information paragraph provides you. :slight_smile: You required it when you use those code with membership 2 pro api.

    #3) Now final step :slight_smile:. In this step you will integrate membership 2 pro api with custom press custom fields. :slight_smile:

    To do so please first understand how membership determines which member is in which membership.

    You can know more about different function membership 2 pro provides which you can use to determine member's current membership from here,

    Once you determine current user's membership, you can combine custompress custom field php code snippet with conditional tags. :slight_smile:

    I hope this helps you.

    Feel free to ask me if you need further help with this. :slight_smile: I am happy to help you. :slight_smile:


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.