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.
-
AuthorPosts
-
September 13, 2016 at 11:49 pm #8273
websydaisy
ParticipantI 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 #8276mbrsolution
ModeratorHi, try the following documentation. Let me know if this helps you.
Regards
September 14, 2016 at 12:58 am #8277websydaisy
ParticipantThis appears to be for Custom Post Types, not for Custom Fields?
September 14, 2016 at 1:06 am #8278websydaisy
ParticipantYeah, 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 #8279mbrsolution
ModeratorHi, I have submitted a message to the plugin developers to investigate further your issue.
Kind regards
September 14, 2016 at 1:18 am #8280websydaisy
ParticipantThanks! 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 #8292CSFLA
ParticipantHi 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 #8293websydaisy
ParticipantI 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 #8300mbrsolution
ModeratorHi, 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 #8301websydaisy
ParticipantYes, 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 #8302mbrsolution
ModeratorHi, 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 #8303mbrsolution
ModeratorHi 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
-
AuthorPosts
- You must be logged in to reply to this topic.