Title: cheating
Last modified: September 15, 2017

---

# cheating

 *  Resolved [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/cheating/)
 * hello
 * thanks for the plugin. works great
    but there is a big problem with it only one
   visit per post per IP should be counted or at least there should be an option
   for it
 * this way you will get true popular posts

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/cheating/#post-9499598)
 * Hi there!
 * While in your case that might be true (I’m guessing you’re running some kind 
   of site were popularity is actually an important feature, a movie site perhaps?),
   this plugin is meant to be a simple way to showcase your top posts. There are
   more advanced analytics tools out there that do what you need (like Google Analytics.)
 * With that being said, the plugin does offer some ways to implement mechanisms
   to prevent the views count inflating. See [here](https://github.com/cabrerahector/wordpress-popular-posts/issues/44)
   for more.
 *  Thread Starter [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/cheating/#post-9500389)
 * I believe popularity is an important feature for anyone who use this kind of 
   pluigns
    Google Analytics is completely another story.
 * i’m looking for a plugin which shows TOP 10 posts using shortcode (updating in
   real time)
 * your plugin does the job but the only problem with your plugin is
    it does not
   have an option to count ‘unique views’
 * I hope you add this option in future version!
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/cheating/#post-9500563)
 * > (…) your plugin does the job but the only problem with your plugin is it does
   > not have an option to count ‘unique views’
   > I hope you add this option in future version!
 * Chances are it won’t happen because of [this](https://github.com/cabrerahector/wordpress-popular-posts/issues/44#issuecomment-58655411).
   Performance is a great deal to me, and I’m sure it is for you as well.
 * I can provide you with a code snippet you can use to detect whether a visitor
   has already viewed a page or not (to prevent duplicate views from the same IP
   on the same date) as long as you’re aware of its implications and understand 
   you’ll be using it at your own risk (this almost sounds like a _Terms of Use_
   text haha). Would that be OK with you?
 *  Thread Starter [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 7 months ago](https://wordpress.org/support/topic/cheating/#post-9500600)
 * Yes Please, I will accept that.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502495)
 * Hey there!
 * Alright, please add this to your theme’s functions.php file:
 *     ```
       /*
        * Have WordPress Popular Posts store one view 
        * per entry per IP per day to keep visitors from 
        * inflating the views count.
        */
       function wpp_unique_view( $post_ID, $views ){
   
           $ip_address = $_SERVER['REMOTE_ADDR'];
           $transient_name = 'wpp_' . $post_ID . '_' . $_SERVER['REMOTE_ADDR'];
   
           // Visitor has already seen this page
           if ( get_transient( $transient_name ) ) {
               exit();
           }
   
           // Visitor has not seen this page yet
           $now = current_time( 'timestamp' );
           $midnight = strtotime( 'midnight +1 day' );
           $expire = $midnight - $now;
   
           // Keep this record until midnight
           set_transient( $transient_name, 1, $expire );
   
       }
       add_action( 'wpp_pre_update_views', 'wpp_unique_view', 10, 2 );
       ```
   
 * Basically, the function above keeps track of the pages visited by a given IP 
   address. If it’s the first time this IP address has visited this page, the function
   will create a transient that expires at midnight so the next time the visitor
   checks the same page on the same day it’ll prevent WPP from updating its views
   count.
 * By the way, if multiple users are viewing your site from the same IP address (
   office network, home network, etc.), all of them will be treated as one visitor.
 * Additionally, you might want to install the [Delete Expired Transients plugin](https://wordpress.org/plugins/delete-expired-transients/).
   Although its name pretty much explains what it does, I recommend reading its 
   description anyways to understand why you should use it.
 *  Thread Starter [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502581)
 * Thank you very much for the code
 * I try to add this code to check if it work and I noticed something else
 * does this plugin compatible with caching plugins (like WPFC)?
 * it seems when i publish new post, WPP counting views, even post is already cached
   
   but after a few hours or probably a day, it stop counting that post
    -  This reply was modified 8 years, 6 months ago by [saman27](https://wordpress.org/support/users/saman27/).
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502635)
 * > does this plugin compatible with caching plugins (like WPFC)?
 * Yep, it is. I’m using WP Fastest Cache as well and WPP works as intended. However,
   with WPFC you need some extra configurations:
    1. Go to _Dashboard > WP Fastest Cache > Settings_.
    2. Make sure that the option “Clear cache files when a post or page is published”
       is enabled.
    3. Go to _WP Fastest Cache > Cache Timeout_.
    4. Click on _Add New Rule_.
    5. Set rule as follows: _All_, _Once every 6 Hours_.
    6. Hit _Save_ to add the new rule.
    7. Finally, go to _WP Fastest Cache > Delete Cache_ and click on **Delete Cache
       and Minified CSS/JS files** to regenerate the cache.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502670)
 * Here’s a more modern version of the function above (requires PHP 5.3+):
 *     ```
       /**
        * Have WordPress Popular Posts store one view 
        * per entry per IP per day to keep visitors from 
        * inflating the views count.
        */
       function wpp_unique_view( $post_ID, $views ){
   
           $ip_address = $_SERVER['REMOTE_ADDR'];
           $transient_name = 'wpp_' . $post_ID . '_' . $_SERVER['REMOTE_ADDR'];
   
           // Visitor has already seen this page
           if ( get_transient( $transient_name ) ) {
               exit();
           }
   
           // Visitor has not seen this page yet
           $timezone = new DateTimeZone( 'GMT' . get_option( 'gmt_offset' ) );
           $now = new DateTime( 'now', $timezone );
           $midnight = new DateTime( 'tomorrow midnight -1 second', $timezone );
           $interval = $midnight->diff( $now );
   
           $expire = $interval->h * 3600 + $interval->i * 60 + $interval->s;
   
           // Keep this record until midnight
           set_transient( $transient_name, 1, $expire );
   
       }
       add_action( 'wpp_pre_update_views', 'wpp_unique_view', 10, 2 );
       ```
   
 *  Thread Starter [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502719)
 * Thanks again
 * Deleting all cache every 6 hours is not a good idea for my website
    I have more
   than 30000 posts
 * excluding WPP’s CSS/JS files is much better idea
    do you know what CSS/JS files
   I need to exclude
 * other than this:
    wp-content/plugins/wordpress-popular-posts/style/wpp.css?ver
   =3.3.4
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502755)
 * WPP relies on [WordPress’ nonces](https://codex.wordpress.org/WordPress_Nonces)
   to secure Ajax calls, and nonces expire every 24 hours.
 * If you set a expiry time longer than 24 hours this is what will happen:
    1. WPP creates a security token (nonce) and uses it to update the views count of
       your posts and pages safely.
    2. 24+ hours later your cached pages will still reflect the old security token (
       nonce), which has expired now.
    3. WPP will attempt to use the expired security token (nonce) when updating the
       views count of a given post / page, and since the token is no longer valid WPP
       will refuse it and not update the views count.
    4. And then:
    5. > (…) but after a few hours or probably a day, it stop counting that post
 * That’s why I suggested setting **Cache Timeout** to 6 hours. As long as it’s 
   less or equal than a day (eg. every 8-10 hours, or even once a day) it should
   be fine.
 * By the way, you don’t really need to exclude the wpp.css stylesheet. Feel free
   to remove it from the exclusion list.
 *  Thread Starter [saman27](https://wordpress.org/support/users/saman27/)
 * (@saman27)
 * [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502783)
 * I understand now
 * Expired respond :
    [https://picload.org/image/dgddclgr/11.png](https://picload.org/image/dgddclgr/11.png)—————
 * but trust me deleting 30000 posts EVEN every 10 days is not good idea for my 
   website
    I have daily more than 50K pageviews.
 * there is too much pressure for server to generate cache everytime
    I would prefer
   to not use caching plugins to re-generate them every X hours
 * anyway thank you very much for your time and help

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘cheating’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

## Tags

 * [views](https://wordpress.org/support/topic-tag/views/)

 * 11 replies
 * 2 participants
 * Last reply from: [saman27](https://wordpress.org/support/users/saman27/)
 * Last activity: [8 years, 6 months ago](https://wordpress.org/support/topic/cheating/#post-9502783)
 * Status: resolved