Skip to main content
deleted 474 characters in body
Source Link

**UPDATE: I am overriding the default page.php file of twenty sixteen theme to try to implement basic page-view limiting for logged-in users. However, When I log in and view any wordpress page, no entry is made to the wp_usermeta table. Why is there no "countVisitsUsed" field added to my user table when I view a page in wordpress? **

    <?php
//First, check for get_current_user_id.

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


    

//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; //each user may 
 only view a page$countVisitsUsed twenty= times.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( $user_id$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$COUNT_VISITS_TOTAL_LIMIT) { //allow page load and increment their visit

            
            $countVisitsUsed++;
            //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
        }
    }

**UPDATE: I am overriding the default page.php file of twenty sixteen theme to try to implement basic page-view limiting for logged-in users. However, When I log in and view any wordpress page, no entry is made to the wp_usermeta table. Why is there no "countVisitsUsed" field added to my user table when I view a page in wordpress? **

    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            $countVisitsUsed++;
            //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
        }
    }

**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(); ?>
added 19 characters in body
Source Link
    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            $countVisitsUsed++;
            //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
        }
    }
    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            
            //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
        }
    }
    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            $countVisitsUsed++;
            //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
        }
    }
added 2755 characters in body
Source Link

**UPDATE: I am overriding the default page.php file of twenty sixteen theme to try to implement basic page-view limiting for logged-in users. However, When I log in and view any wordpress page, no entry is made to the wp_usermeta table. Why is there no "countVisitsUsed" field added to my user table when I view a page in wordpress? **

    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            
            //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
        }
    }

**UPDATE: I am overriding the default page.php file of twenty sixteen theme to try to implement basic page-view limiting for logged-in users. However, When I log in and view any wordpress page, no entry is made to the wp_usermeta table. Why is there no "countVisitsUsed" field added to my user table when I view a page in wordpress? **

    <?php
//First, check for get_current_user_id.

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


        // 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; //each user may only view a page twenty times.

        if (get_user_meta($current_user, 'countVisitsUsed', true)) {
            $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
            update_user_meta($current_user, 'countVisitsUsed', $countVisitsUsed+1);
        }else{
              update_user_meta( $user_id, 'countVisitsUsed', 1, false );
              $countVisitsUsed = get_user_meta($current_user,'countVisitsUsed',true);
        }


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

            
            
            //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
        }
    }
Source Link
Loading