Created
August 13, 2015 15:52
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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/