Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Created August 13, 2015 15:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save strangerstudios/480651b9131bd6b36885 to your computer and use it in GitHub Desktop.
Save strangerstudios/480651b9131bd6b36885 to your computer and use it in GitHub Desktop.
Make any post older than 18 months available for free with Paid Memberships Pro.
/*
Make any post older than 18 months available for free.
Add this code to your active theme's functions.php or a
custom plugin.
*/
function make_old_posts_free($hasaccess, $post, $user, $post_membership_levels)
{
//if they already have access, let them at it
if($hasaccess)
return $hasaccess;
//only make posts of type post (i.e. not pages or other CPTs) free
if($post->post_type != 'post')
return $hasaccess;
//now check the publish date
$published = strtotime($post->post_date, current_time('timestamp'));
if($published < strtotime("-18 Months", current_time('timestamp')))
$hasaccess = true;
return $hasaccess;
}
add_filter('pmpro_has_membership_access_filter', 'make_old_posts_free', 10, 4);
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Lock or Unlock Posts Based on Age and Post Date" at Paid Memberships Pro here: https://www.paidmembershipspro.com/lock-unlock-posts-based-age-post-date/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment