Skip to content

Instantly share code, notes, and snippets.

@andrewlimaza
Created September 19, 2017 11:32
Show Gist options
  • Save andrewlimaza/fd536150d84a606f58263f74f97fd529 to your computer and use it in GitHub Desktop.
Save andrewlimaza/fd536150d84a606f58263f74f97fd529 to your computer and use it in GitHub Desktop.
Make posts older than 30 days free in PMPro
<?php
// Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
/*
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' ) );
$check_date = strtotime( '-30 Days', current_time( 'timestamp' ) ); //30 days older than todays date.
if( pmpro_hasMembershipLevel('5') && ( $published < $check_date ) ){
$hasaccess = true;
}
return $hasaccess;
}
add_filter('pmpro_has_membership_access_filter', 'make_old_posts_free', 15, 4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment