you can count how many posts user can see like that: (int) ( ( time() - strtotime( get_userdata(get_current_user_id( ))->user_registered ) ) / ( 7 * 24 * 60 * 60 ) ) + 1;
So you add filter for pre_get_posts
to show user as many posts as compleate weeks he has spendt on your website.
And to prevent seeing content for custom entered links you add filter to content, where you chack if current post is in avalable posts for current user.
And of course you show all for admins
add_filter( 'pre_get_posts', 'prefix_pre_get_posts' );
function prefix_pre_get_posts( $query ) {
if( ! is_admin() && 'post' == $query->post_type ) { // is_main_query() ?
$post_pre_page = null;
if( is_user_logged_in() && ! current_user_can( 'administrator' ) ) {
$post_pre_page = (int) ( ( time() - strtotime( get_userdata(get_current_user_id( ))->user_registered ) ) / ( 7 * 24 * 60 * 60 ) ) + 1;
} elseif( ! is_user_logged_in() ) {
$post_pre_page = 0;
}
if( ! is_null( $post_pre_page ) ) {
$query->set( 'posts_per_page', $post_pre_page );
// Show pastest posts first
$query->set( 'order', 'DESC' );
$query->set( 'orderby', 'date' );
}
}
}
add_filter( 'the_content', 'prefix_filter_the_content' );
function prefix_filter_the_content( $content ) {
if( current_user_can( 'administrator' ) )
return $content;
$current_id = get_the_id();
$allowed_posts = get_posts( array( 'posts_per_page' => -1 ) );
$flag = false;
if( ! empty( $allowed_posts ) )
foreach( $allowed_posts as $p )
if( $current_id == $p->ID ){
$flag = true;
break;
}
if( ! $flag ) {
return __( 'Your are not able to see these post', 'your-textdomain' );
}
return $content;
}
Simply add these code to your functions.php
.
PS: to change 7 days to 3 ( for ex ) change it here ‘( 7 * 24 * 60 * 60 )’ to ‘( 3 * 24 * 60 * 60 )’