Membership Plugin

WordPress Membership Plugin

  • Home
  • Documentation
  • Addons
  • Support
    • Quick Setup
    • Documentation
    • Premium Addon Support
    • Paid Support
    • Support Forum
    • Support Forum Search
    • Forum Login
    • Forum Registration
  • Contact

Protect Custom Fields

Simple Membership Plugin › Forums › Simple Membership Plugin › Protect Custom Fields

Tagged: custom fields

  • This topic has 11 replies, 3 voices, and was last updated 9 years, 8 months ago by mbrsolution.
Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • September 13, 2016 at 11:49 pm #8273
    websydaisy
    Participant

    I have a protected page to which I am using Advanced Custom Fields to add various sections. Unfortunately those sections are showing to everyone; only the content from the main content editor is being protected. Is there any way to protect all of the content on the page?

    September 14, 2016 at 12:38 am #8276
    mbrsolution
    Moderator

    Hi, try the following documentation. Let me know if this helps you.

    Regards

    September 14, 2016 at 12:58 am #8277
    websydaisy
    Participant

    This appears to be for Custom Post Types, not for Custom Fields?

    September 14, 2016 at 1:06 am #8278
    websydaisy
    Participant

    Yeah, this does not do anything different for me than before. When I create my custom fields, there was already a place to to click the buttons to protect them — but on save, they go right back to “No, Do not protect this content.” being selected.

    I need to protect Custom Fields, not Custom Post Types.

    Looks like this question has come up before: https://simple-membership-plugin.com/forums/topic/protecting-advanced-custom-fields/

    If there is no way to protect custom fields, I will have to abandon this and look for a different plugin. Unfortunately I already paid $40 for the Form Builder Add-on.

    A LOT of people use Advanced Custom Fields. Surely there must be some way to make this work?

    September 14, 2016 at 1:12 am #8279
    mbrsolution
    Moderator

    Hi, I have submitted a message to the plugin developers to investigate further your issue.

    Kind regards

    September 14, 2016 at 1:18 am #8280
    websydaisy
    Participant

    Thanks! So I am able to get partway there by putting this around the section that contains my custom fields:

    <?php if(SwpmMemberUtils::is_member_logged_in()) { ?>
    <?php } ?>

    But since I have two different membership levels, I need to have it look to also make sure they are in a certain level. I am not great at figuring out php on my own — what can I add to this to have them also look to make sure they are in a certain level to display that content?

    September 14, 2016 at 10:19 pm #8292
    CSFLA
    Participant

    Hi Daisy,

    I have a similar issue. Do you put that PHP code inline with your page content in WordPress, and if so, do you use a plugin to allow you to use PHP code in page content?

    Thanks,

    David 🙂

    September 14, 2016 at 10:41 pm #8293
    websydaisy
    Participant

    I put it in my page template where I call the custom fields. Like this:

    <?php if(SwpmMemberUtils::is_member_logged_in()) { ?>
    <?php the_field(‘my_custom_field’); ?>
    <?php } ?>

    September 15, 2016 at 3:12 am #8300
    mbrsolution
    Moderator

    Hi, did you check the following PHP tweaks document? There are a few tweaks you might be able to combine to get the results you are after.

    Regards

    September 15, 2016 at 3:28 am #8301
    websydaisy
    Participant

    Yes, that’s where I got the php I used to see if someone is logged in. And I see things telling me how to get the user’s membership level, but I don’t know how to make my conditional statement say IF they are in Level 2, for example, then show this. That does not appear to be addressed.

    September 15, 2016 at 3:48 am #8302
    mbrsolution
    Moderator

    Hi, I just checked one of the plugins PHP file. This is what it says.

      if($permission->is_permitted($id)) {
                //This user's membership level has access to it. Show this post to this user.
                return true;
            } else {
                //User's level DOES NOT have access to this post.
                $text = SwpmUtils::_('This content is not permitted for your membership level.');
                $error_msg = '<div class="swpm-post-no-access-msg">'.$text.'</div>';
                $this->lastError = apply_filters ('swpm_restricted_post_msg', $error_msg);
                return false;
            }

    Perhaps the above can put you in the right direction.

    Regards

    September 15, 2016 at 5:13 am #8303
    mbrsolution
    Moderator

    Hi again, I did not paste the full PHP code above. Please make sure you include the following at the top and there is another line at the end.

    $permission = SwpmPermission::get_instance($auth->get('membership_level'));

    So the full code would be as follow.

    `//Check if this user’s membership level has access to this post
    $permission = SwpmPermission::get_instance($auth->get(‘membership_level’));
    if($permission->is_permitted($id)) {
    //This user’s membership level has access to it. Show this post to this user.
    return true;
    } else {
    //User’s level DOES NOT have access to this post.
    $text = SwpmUtils::_(‘This content is not permitted for your membership level.’);
    $error_msg = ‘<div class=”swpm-post-no-access-msg”>’.$text.'</div>’;
    $this->lastError = apply_filters (‘swpm_restricted_post_msg’, $error_msg);
    return false;
    }

    //All checks have passed. Show this post to the user.
    return true;
    }`

    Regards

  • Author
    Posts
Viewing 12 posts - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.
Log In

Please read this message before using our plugin.

Search

Featured Addons and Extensions

  • Membership Form Builder Addon
  • Member Directory Listing Addon
  • WooCommerce Payment Integration
  • Member Data Exporter Addon

Documentation

  • Documentation Index Page

Copyright © 2026 | Simple Membership Plugin | Privacy Policy