Forked from strangerstudios/make_old_posts_free.php
Last active
February 23, 2022 20:27
-
-
Save kimwhite/534cbf6f8647b1061de0ed893f124676 to your computer and use it in GitHub Desktop.
Make any post older than 7 days, form a specific category available for free with Paid Memberships Pro.
This file contains hidden or 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 7 Days available for free. | |
*/ | |
function make_old_posts_free($hasaccess, $post, $user, $post_membership_levels) | |
{ | |
//if they already have access, let them at it | |
if($hasaccess) | |
return $hasaccess; | |
// Categories that this code should apply to. Categories not here will assume default functionality. | |
$categories = array( 'catone', 'cattwo' ); | |
if ( ! in_category( $categories, $thepost ) ) { | |
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("-7 Days", 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