How to limit the access of the content based on user’s registration date

A friend of mine has a paid and subscription based site. He wanted the site to limit access to content based on a user’s registration date. For example, if a user registered in August, he didn’t want him to be able to see the content from July and past content. This is one way to do it:

$user_id = get_current_user_id();
$user_data = get_userdata( $user_id );
$registered_date = $user_data->user_registered;
$registerd_date = mysql2date( 'Ym', $registered, true );
$post_date = get_the_date( 'Ym' );

if ( $post_date >= $registered_date) {
	echo the_content();
}

The above code will need to be placed directly into the template. Another way to do it is by using a filter.

Leave a Comment





This site uses Akismet to reduce spam. Learn how your comment data is processed.