我的WordPress页面上有一个资源,我每天只想为每个登录用户显示X次。我用的是216字新闻的主题。
目前,访客/访客/未登录用户必须通过重定向对我的网站进行身份验证,才能访问任何内容。
如何对每个登录用户每天或每小时施加http请求限制/页面浏览限制?我不想按IP地址来做,我想按唯一用户来做。
有人看到过吗?我看到的壁橱是: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 但是否已经有了解决方案?我搜索了throttle、page view、http、limit、restrict、expire,但似乎没有任何内容限制登录用户每天的内容。
非常感谢。
**更新:我正在覆盖默认页面。二十一世纪主题的php文件,为登录用户实现基本的页面视图限制**
<?php
//首先,检查get\\u current\\u user\\u id。
$current\\u user=wp\\u get\\u current\\u user();如果(0==$当前用户->ID){//注销}其他{//登录。
//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(); ?>