Support » Plugin: Jetpack Post Views » I have a patch request

  • Resolved Nikola Nikolov


    I installed your plugin and it’s pretty awesome 🙂

    Unfortunately it wasn’t updating the posts views(even after a couple of hours – I even made sure that the cron was actually running).

    So, I looked at your code and I enabled debug and then I saw that cached data was returned to me – meaning I was only seeing stats for 2 posts, even though in the Jetpack stats I was seeing that more posts have views.
    Initially I thought that the Jetpack Stats function is caching somewhere(even though the cache was never coming from the DB option cache), so I disabled the check for the stats_get_csv() function so that the plugin would use your custom requests.

    Here comes another small issue that I found – you set the default value for the blog_uri option to get_bloginfo( 'wpurl' ) and that is different from home_url( '/' ) when you have your WordPress files in a different location. It seems though that Jetpack cares about the URL of the home page of the blog – so you should instead be using home_url( '/' ).

    After playing around with the custom requests I noticed that I’m always getting the same exact result. The problem in this case was that you were always querying for days=-1 – and it seems like has a pretty sturdy caching system(that’s to be expected), so you never get new results.

    What I did to make things easier was to add a new property to the class called apiArgs – it’s an array of key/value pairs and makes it much easier to construct URL’s, by utilizing WordPress’ add_query_arg() function 🙂

    So a couple of tweaks here and there and everything is working perfect on my end. Of course I don’t expect you to take my word for granted and I advise you on testing the code yourself, so that nothing goes wrong if you update the plugin and it suddenly breaks for someone.

    You can find a diff of the latest version of the plugin(1.0.8) and my patched version here –

    If you have any questions about the patch, feel free to comment here.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Steven Lambert


    Thats a very interesting find. I took a look through your code and it seems that you use the $random variable to break caching for all calls (stats_get_scv, blog_uri, and blog_id), but then you use those results to update the view count for all posts. Are you finding that your post views remain accurate doing that?

    Well, I currently only have about 4 posts in the blog(where I’m displaying the view counts) and so far it seems just fine, yes.

    I believe that generally it shouldn’t matter that I’m breaking the caching for all methods, since technically only one method is used(either stats_get_csv(), via blog_uri or via blog_id).

    Unless I’m missing something, since I’m not familiar with the Stats system of Jetpack(nor it’s API).

    Plugin Author Steven Lambert


    Added patches to version 1.0.9. The add_query_arg() function is pretty awesome, thanks for letting me know about it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘I have a patch request’ is closed to new replies.