Unlocking Posts after 3 Days with Paid Memberships Pro

[ad_1]

Hello everybody,

i want to make Posts free to view after 3 Days with Paid Memberships Pro only on a specific category. The original code is this one:

[https://gist.github.com/strangerstudios/480651b9131bd6b36885#file-make\_old\_posts\_free-php])

​

/*
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);

I am not familiar with PHP but i changed it to this here:

/*
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_category != ‘Beauty’)
return $hasaccess;

//now check the publish date
$published = strtotime($post->post_date, current_time(‘timestamp’));
if($published < strtotime(“-3 Days”, current_time(‘timestamp’)))
$hasaccess = true;

return $hasaccess;
}
add_filter(‘pmpro_has_membership_access_filter’, ‘make_old_posts_free’, 10, 4);

Is that the correct attempt / would this work? Just changing out the Date and Type of content to restrict?

[ad_2]

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer