Tips and Tricks HQ Support Portal › Forums › WP eMember › eMember – Protecting content outside a post (custom fields and shortcodes)
Tagged: custom fields, shortcode
- This topic has 5 replies, 3 voices, and was last updated 11 years, 11 months ago by admin.
-
AuthorPosts
-
December 28, 2012 at 6:24 am #8225JuryDutyMember
I’m building a video teaching site and have the challenge that my theme uses a custom field to display the video at the top of the page. eMember doesn’t block this video since it’s located outside of the post area.
Here’s an example: [http://www.writingmomentum.com/vibrant/]
Is there some php code I could put around the video that would protect it? The shortcode doesn’t seem to work in the custom fields.
Or, is there code I could use for sitewide protection that sends anyone without access to the Sign Up page? The Sitewide Protection included in the settings is good, but it makes me include or exclude EVERY url which is daunting as every time I add a blog post, I’d have to exclude it here.
Thank you!
(Just read rule #3: Please understand I’m not asking for custom code help–I just thought this member solution could block access to an entire page…but it’s really only blocking access to the post itself, not what’s around it. I’m hoping there’s a work
around for that. Thanks for your help!)
December 28, 2012 at 4:28 pm #52658JuryDutyMemberJust to clarify, what would work best is something like this:
<?php CHECK TO SEE IF MEMBER HAS ACCESS TO THIS POST. IF SO ?>
DISPLAY VIDEO
<?php IF NOT ?>
DISPLAY ALTERNATE IMAGE
<?php ?>
December 28, 2012 at 8:55 pm #52659JuryDutyMemberSo while waiting for an answer, I’ve continued to dig and found that if I use this code…
<?php
global $auth;
$user_id = $auth-?>getUserInfo(‘member_id’);
if (!empty($user_id))
{
echo “This secret message is for member’s only”;
echo “Any content here can only be viewed by members”;
}
?>
…or this code…
<?php if(wp_emember_is_member_logged_in()) { ?>
//Place your special message for members here
<?php } ?>
…I can show or hide the content based on whether they’re a member or not. So we’re almost there. It’s just too broad as members could be various levels.
All I need to add to that is the ability for it to show or hide the content based on if they have access to this particular post.
What I don’t want to do is hard-code in items for each level, because I need it to adjust over time based on new levels I add, etc. Make sense?
December 28, 2012 at 10:21 pm #52660PeterMemberHi
Regarding protecting the section you are referring to based on membership levels, see the section in the following page called “Show Different Menus to Different Membership Levels” which might be what you’re looking for:
December 28, 2012 at 10:27 pm #52661JuryDutyMemberThat’s close–it’s differentiating between member/non-member, OR it’s allowing you to hard-code levels in. But what I need is for the code to check and see if the user–depending on their level–has access to the post on the page. We’re almost there, but I need it to dynamically match the post level with the user level rather than hard-coding it in.
I’m sure this is possible, as that’s what’s happening within the post itself. I just need to bring it out of the post and make it apply to other elements surrounding it.
Any other thoughts?
December 28, 2012 at 10:49 pm #52662adminKeymasterThe example in the following post should help (it shows you how to find out if the post or page is accessible for the member in question:
https://support.tipsandtricks-hq.com/forums/topic/bbpress-forums-lockdown/page/2
The following documentation is also a good reference:
http://www.tipsandtricks-hq.com/wordpress-membership/wp-emember-miscellaneous-tweaks-248
-
AuthorPosts
- You must be logged in to reply to this topic.