I have a resource on my WordPress page that I only want to show X times per day per logged in user. I'm using the twenty sixteen WordPress theme.

Currently, Guests / visitors / non logged in users are forced via redirects to authenticate to my site in order to access any content.

How do impose a http request limit / pageview limit on a per-logged-in-user per day or per hour basis? I don't want to do it by IP address, I want to do it by unique user.

Has anyone seen this done? The closet I've seen is : https://premium.wpmudev.org/forums/topic/technical-question-how-to-limit-the-number-of-page-views-for-a-specific-site-under-a-wpmu-instsall#post-384060 but is there a solution already for this? I've searched for throttle, page view, http , limit, restrict, expire, but nothing seems to be restricting content on a logged-in-user-per-day-basis.

Thank you



**UPDATE: I am overriding the default page.php file of twenty sixteen theme to implement basic page-view limiting for logged-in users. **



       <?php
//First, check for get_current_user_id.

$current_user = wp_get_current_user();
if ( 0 == $current_user->ID ) {
    // Logged out
} 	else {
	    // Logged in.

		//Then create a log of visits by adding information to a user's metadata with update_user_meta & get_user_meta. 

		$COUNT_VISITS_TOTAL_LIMIT = 20;
		$countVisitsUsed = 0;

		if (get_user_meta($current_user->ID, 'countVisitsUsed', true)) {
		    $countVisitsUsed = get_user_meta($current_user->ID,'countVisitsUsed',true);
		    update_user_meta($current_user->ID, 'countVisitsUsed', $countVisitsUsed+1); //increment
		}else{
		      update_user_meta( $current_user->ID, 'countVisitsUsed', 1, false );
		      $countVisitsUsed = get_user_meta($current_user->ID,'countVisitsUsed',true);
		}


		if ($countVisitsUsed == null || $countVisitsUsed ==false || $countVisitsUsed < $COUNT_VISITS_TOTAL_LIMIT) { //allow page load

			
			
			//start of page.php

				/**
				 * The template for displaying pages
				 *
				 * This is the template that displays all pages by default.
				 * Please note that this is the WordPress construct of pages and that
				 * other "pages" on your WordPress site will use a different template.
				 *
				 * @package WordPress
				 * @subpackage Twenty_Sixteen
				 * @since Twenty Sixteen 1.0
				 */

				get_header(); ?>
				<div id="primary" class="content-area">
					<main id="main" class="site-main" role="main">
						<?php
						// Start the loop.
						while ( have_posts() ) : the_post();

							// Include the page content template.
							get_template_part( 'template-parts/content', 'page' );

							// If comments are open or we have at least one comment, load up the comment template.
							if ( comments_open() || get_comments_number() ) {
								comments_template();
							}

							// End of the loop.
						endwhile;
						?>

					</main><!-- .site-main -->

					<?php get_sidebar( 'content-bottom' ); ?>

				</div><!-- .content-area -->

				<?php get_sidebar(); ?>
				<?php get_footer(); ?>
<?php
		} else {wp_die('Limit reached.')}
	}