Simple Membership Plugin › Forums › Simple Membership Plugin › Custom Post Types does not seem to be able to be protected?
- This topic has 13 replies, 6 voices, and was last updated 6 years, 3 months ago by
Akira.
-
AuthorPosts
-
October 22, 2015 at 4:15 am #3589
stanusj
ParticipantHello there, while I manage to place a number of pages into protection, I am unable to do the same for a set of custom post types (in this case – Class Rooms)
Really appreciate help here! Thanks!
October 22, 2015 at 6:42 am #3602mbrsolution
ModeratorHi can you test the following PHP tweak? Look for the following header Check If Logged-in Member Has Access to a Post.
October 22, 2015 at 3:11 pm #3608stanusj
ParticipantWhere do I place this code?
global $post;
$post_id = $post->ID;
$access_ctrl = SwpmAccessControl::get_instance();
if ($access_ctrl->can_i_read_post($post_id)){
//This user can read the post with ID $post_id
//Add your custom code that does something
}October 22, 2015 at 8:12 pm #3609mbrsolution
ModeratorThat code needs to be placed in the template you are currently using to create your pages or post.
October 22, 2015 at 11:07 pm #3617stanusj
ParticipantI placed the code, here is the view of this page – logged in, and not logged in
vmswebsite.wpengine.com/classroom/the-alder-room/Appreciate any feedback or suggestions pls. Thanks!
October 22, 2015 at 11:21 pm #3618mbrsolution
ModeratorIf your content is not protected on custom posts then it is a theme related issue. Your custom post might not be following WordPress theme rules. Have you tried testing a different theme like WordPress default themes. Twenty Fourteen or Fifteen? How are you creating your custom post?
October 22, 2015 at 11:30 pm #3620stanusj
ParticipantI am using Ultimatum, which in turn is using ACF | Advanced Custom Fields Plugin for WordPress for the custom post.
October 23, 2015 at 12:19 am #3623mbrsolution
ModeratorThere might be a conflict with the ACF | Advanced Custom Fields Plugin.
October 23, 2015 at 5:10 pm #3641stanusj
ParticipantIs there a work around, or can you recommend someone that might be able to fix this for a fee?
October 26, 2015 at 1:21 am #3667nur
ParticipantHi,
Can you try switching to default wordpress theme and check if posts are protected or not. I think the theme you are using override some of the wordpress’s default hooks. Simple membership heavily relies on those hooks. if the hooks are disabled or modified then this plugin will stop functioning. if you want us to take a look into your server, we are happy to do that.January 27, 2020 at 5:10 pm #19685joshua
ParticipantI know this post is wicked old, but in case anyone is trying to solve this, here is what I did:
I am using a custom theme, with a custom post type (registered in my functions.php, not a plugin). I am using Advanced Custom Fields (ACF) to generate the content for the posts page. Like others, I’ve been trying to solve having ACF fields be hidden. It has to be in a wp-loop! There are many ways to achieve this, I opted to do this with a Custom Post Type (CPT).
By default, Simple Membership Plugin did not protect the CPT. So I needed to wrap the page content in
if(SwpmMemberUtils::is_member_logged_in())This only partially helped, as it checks to see if the user is logged in, but it does not protect based on membership levels, etc. So I needed the then check the account permissions, using
global $post; $access_ctrl = SwpmAccessControl::get_instance(); if ($access_ctrl->can_i_read_post($post)){The complete block of code on my single-customers.php page looks like:
<?php if(SwpmMemberUtils::is_member_logged_in()) { global $post; $access_ctrl = SwpmAccessControl::get_instance(); if ($access_ctrl->can_i_read_post($post)){ //This user can read the specified post //Add your custom code that does something ?> <?php while ( have_posts() ) : the_post(); ?> <h1 class="moldeB pull-left portal-name">CUSTOMER PORTAL — <?php the_field( 'client_name' ); ?> </h1> <?php $client_logo = get_field( 'client_logo' ); ?> <?php if ( $client_logo ) { ?> <div class="spacer-20"></div> <img src="<?php echo $client_logo['url']; ?>" alt="<?php echo $client_logo['alt']; ?>" class="pull-right customer-logo" /> <?php } ?> <div class="clearfix"></div> <div class="spacer-50"></div> <?php the_field( 'client_content' ); ?> <?php //get_template_part( 'template-parts/content', get_post_type() ); endwhile; // End of the loop. ?> <?php } else { ?> <p>You do not have access to this page.</p> <?php } ?> <?php } else { ?> <p>You are not logged in. Please login <a href="/customer-portal">here.</a></p> <?php } ?>I hope this helps someone else searching!
January 29, 2020 at 4:18 pm #19692Akira
ParticipantWhat is wicked, is that we needed this exact code to finish a project until friday. Thank you for thinking of people searching for an answer later and for coming up for the answer! Take some Internet Karma! Thank you soo much you saved us an extremely stressful week! Thanks from our whole Dev Team and our Client! <3
January 30, 2020 at 5:40 am #19700admin
KeymasterThank you for sharing your code.
Just wanted to mention that the following addon can be helpful for protecting custom post types:
https://simple-membership-plugin.com/full-page-protection-addon-simple-membership/January 30, 2020 at 12:22 pm #19702Akira
ParticipantThe Plug-In is just a bit of a overkill, is there an option to only hide everything except the footer and header, this would be more useful for this scenario we were dealing with.
-
AuthorPosts
- You must be logged in to reply to this topic.