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
You are here: Home

joshua

  • Profile
  • Topics Started
  • Replies Created
  • Engagements
  • Favorites

Forum Replies Created

Viewing 1 post (of 1 total)
  • Author
    Posts
  • January 27, 2020 at 5:10 pm in reply to: Custom Post Types does not seem to be able to be protected? #19685
    joshua
    Participant

    I 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!

  • Author
    Posts
Viewing 1 post (of 1 total)
Next Page »

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