Answered

Show single posts with the excerpt and a call to action

Hi I am wondering how I can change the default behaviour of MM to display a single post page (rather than redirect to the error page) regardless of access rights, and lock down certain aspects of the page if the user doesn't actually have access. I would like to display the feature image, the excerpt and some meta data to everyone, but the bulk of the article will be behind a paywall - a call to action displayed to anyone who doesn't have access. (to log in or buy a membership).



I'm assuming filters and actions will be the key here, but I'm a bit of a novice with this stuff and a newcomer to MM.
Answer Hi David. We're working on doing a very similar thing. To accomplish this we have done the following:

1. Protect the content via MemberMouse's interface

2. In your theme's functions.php put this function. It tells MM to show the content even when a user does not have access.

function customContentProtection($data)
{
error_log('customContentProtection');
return true;
}
add_filter('mm_bypass_content_protection', 'customContentProtection');

3. Then again in functions.php use Wordpress's the_content filter to only show an excerpt of your content when the current user does not have access to the post. Like so:

add_filter( 'the_content', 'my_the_content_filter' );
function my_the_content_filter( $content ) {
global $post;

if ( !is_singular() )
return $content;

$new_content = $content;

/* only show an excerpt if the member doesn't actually have access to this */
if ( mm_access_decision(array("access"=>"true")) != true ) {
$new_content = $post->post_excerpt; // whatever you want the user to see instead seeing the whole post
}

return $new_content;
}
Hi Seth, I tried the code you provided and it does not work on my installation. When I try this I get a blank page when looking at the page as a non-member. (closer than an error page, but still not the effect we are going for here.)

The "blank" page issue occurs when an excerpt is not defined int the edit post section.  Since the  

$new_content

  variable is defined as  

$post->post_excerpt

 you need to have an excerpt defined in your post for it to display anything in single post view.  


Login or Signup to post a comment