Restrict access to old content

Hello,

We have a client that’s going to be posting video content every month. The client does not want users to have access to videos that were posted prior to registration.

I’ve looked into the s2Drip shortcode, but as I understand it these shortcodes will post up fixed content after certain intervals so users will see a fixed drip feed of content. Instead of this, we want users to be able to see all new content that’s posted after registration but no old content posted before registration.

Is there a way to do this in S2member. That is, give users access to only content or Wordpress posts that are posted AFTER their registration and onward?

Thanks.

This kit may help you. Also look at all the “drip content” solutions.

1 Like

I have just knocked up a function that might do the trick. I haven’t tested it, but it should at least get you most of the way. Try adding it as an mu-plugin:

<?php
function kts_hide_earlier_posts() {	
	if ( current_user_can( 'access_s2member_level2' ) ) {
		return; // Allow access to earlier posts if member has the specified level or higher
	}	
	if ( !is_singular( 'post' ) ) {
		return; // function is irrelevant if this is not a post
	}
	global $post;
	$post_id = $post->ID;
	$published_date = get_the_date( 'U', $post_id );
	
	$current_user = wp_get_current_user();
	$registered = $current_user->user_registered;
	$user_reg_date = date( 'U', strtotime( $registered ) ); // or use alternative below
	// $user_reg_date = S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME; // alternative that takes date from paid registration, not initial (free) registration on site
	
	if ( $user_reg_date > $published_date ) {
		wp_safe_redirect( S2MEMBER_MEMBERSHIP_OPTIONS_PAGE_URL );
		exit;
	}
}
add_action( 'template_redirect', 'kts_hide_earlier_posts' );

1 Like

Is there a way to extend and tweak this to restrict all content before X days from “today”. So it doesn’t matter when a user registers. Instead, it just automatically makes all archive Posts restricted before X days from today.

Sure. Delete the following lines:

$current_user = wp_get_current_user();
$registered = $current_user->user_registered;
$user_reg_date = date( 'U', strtotime( $registered ) ); // or use alternative below
// $user_reg_date = S2MEMBER_CURRENT_USER_PAID_REGISTRATION_TIME; // alternative that takes date from paid registration, not initial (free) registration on site

and change this line:

if ( $user_reg_date > $published_date ) {

to this:

if ( strtotime( '-7 days' ) > $published_date ) {

Ah, wonderful! I shall test this shortly.