Answered

Protecting Content After the <!-- more --> Tag

Hello,

I was looking for a simple solution to protect content after the standard Wordpress <!-- more --> tag.  I contacted support and they responded with:


Thank you for contacting MemberMouse support. The <!--more--> tag is something that MemberMouse takes into account but only in certain scenarios as described in this article:

Protect Content in RSS Feeds, Search Results and Archives


In order to have the control you are looking for, I recommend that you use the MM_Access_Decision SmartTag: Access Decision SmartTag (MM_Access_Decision)


That didn't really work for me so I came up with a quick solution for it.  I am looking to improve it so if anyone has any better options than please let me know!


  

<?php
add_filter( 'the_content', 'restrict_mm_access' );

function restrict_mm_access($content) {

    if(is_super_admin()){
        return $content;
    }

    $moreLink = '<span id="more-' . get_the_ID() . '"></span>';

    $contentData = explode( $moreLink, $content );

    if ( count( $contentData ) > 1 ) {
        $return = $contentData[0];
        $return .= "[MM_Member_Decision isMember='false']";
        $return .= '<div id="access-restricted-box">
						<h3>You have to be a member to access this content.</h3>
						<h4>Already a Member?</h4>
						<a href="/login/?redirect_to=' . get_the_permalink() . '" class="button">Log In for Access</a>
						<h4>Not a Member Yet?</h4>
						<a href="/join/" class="button">Register Now</a>
					</div>';
        $return .= "[/MM_Member_Decision]";
        $return .= "[MM_Member_Decision membershipId='2']";
        $return .= $contentData[1];
        $return .= "[/MM_Member_Decision]";

        return $return;
    } else {
        return $content;
    }
}
?>

  

Again, this works great for my situation, I was just looking to improve upon it.


Thanks!


This looks like the solution I'm trying to accomplish -- displaying a teaser (anything above the more tag) on protected pages.


However, I can't seem to get the snippet to work.


I've placed the snippet in my functions file, and ensured my membership ID is 2.


What else am I missing?



What I would try is to disable all plugins (minus MM) and test base wordpress theme and see if that works.  


It could be that another plugin or your theme is filtering the content too.


One thing to try would be to add a priority of 0 to the filter to make sure that fires before any other filter


 

add_filter( 'the_content', 'restrict_mm_access', 0 );

 

Ok, I seem to have tracked down the issue.  


The above code works, but on blog postings.  Is there a way to modify it, so that it applies to all of the custom post types (CPT) I'm using on the site?


I don't need it to restrict blog postings (they're publicly available), but rather two CPT called, Tools, and Articles.


Thanks!

Answer
You'll need to make sure that your custom posts have page capabilities in order to apply MM content protection to them. See this article for details:
http://support.membermouse.com/support/solutions/articles/9000059678-protect-custom-post-types

 


Login or Signup to post a comment