• Resolved Nico

    (@gooloode)


    Hello,

    i was wondering if it would be possible to make new posts for a Period of X days (lets say three) exclusive to paid Memberships in Level Y and Z and afterwards free of charge or Public to anyone (like a regular post)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Kim White

    (@kimwhite)

    Hello @gooloode ,

    We have a post on our site about how this can be done. https://www.paidmembershipspro.com/lock-unlock-posts-based-age-post-date/
    The post may be behind a firewall, so here is the gist you can work with to help you get started. https://gist.github.com/strangerstudios/480651b9131bd6b36885#file-make_old_posts_free-php

    Kim W

    Thread Starter Nico

    (@gooloode)

    Hi Kim, thank you very much!

    Could i change that to only one category specifically? I really am not that handy with PHP, but would that work?

    if($post->post_type != 'post')
    elseif($post->post_category != 'Beauty')

    Thread Starter Nico

    (@gooloode)

    Hi @kimwhite would that be the correct code? 3 Days upon publishing, restricted to the Category “Beauty”?

    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 ( in_category( 'category-name', $post )) $hasaccess = true;
    		
    	//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);
    Plugin Support Kim White

    (@kimwhite)

    Hello, you need to add it to the check the the category along with the date.

    if($published < strtotime("-3 Days", current_time('timestamp')) && in_category( 'category-name', $post ))
    		$hasaccess = true;

    I hope this helps to get started. Code recipes are provided as is, you may need to reach out to a local developer for additional customizations..

    Kim W

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Make content exclusive for X days to paid Membership Y?’ is closed to new replies.