Subscribe via

Make WP-PostViews Work with WP-Super-Cache

In response to JTPratt’s comment on my post, ‘Make Popularity Contest Work with WP-Super-Cache,’ I am releasing a modification of Lester Chan’s WP-PostViews plugin to support counting using Javascript. Please try it out to see if this works for you.

A side note to Lester Chan and Richer Yang (WP-PostViews and WP-PostViews Plus authors repectively). Please feel free to contact me about incorporating these changes into WP-PostViews and/or WP-PostViews Plus so that it can be officially committed to the wp-plugins.org repository. I would create my own version of WP-PostViews in the repository, but do not want to steal your thunder :).

Download:
WP-PostViews JS Mod for WordPress 2.5

Note:
Modded Plugin only tested to work with WordPress 2.5 and is probably not backwards compatible with WordPress 2.3.3 or earlier versions.

Special Installation Instructions:
Intallation works the same way as the original WP-PostViews except that you will need to do ONE OF THE FOLLOWING:

  1. Place a symbolic link from wp-content/wp-postviews-js.php -> plugins/wp-postviews/wp-postviews-js.php
  2. Move wp-postviews-js.php directly under your wp-content/ directory

That should be all. I would really appreciate it if you can provide any feedback (security issues, better implementations, or other important thing that I’m totally not aware of). Also please feel free to email me with questions and keep me posted on how things are going with the plugin.

Update

Lester Chan has integrated this change into the official plugin release. Support for this hack will be limited from now on.

38 Responses to “Make WP-PostViews Work with WP-Super-Cache”

[go to last comment]
  1. Rosyidi

    Thanks a lot.

  2. Thaya Kareeson

    @Rosyidi
    You’re welcome! Please feel free to send me any questions or comments about this modification. And if you really like it, please write about it :-).

  3. VISH

    Hi, It is giving me a 404 error even after I have moved the postview-js.php to the wp-content direcory. Check it at my website
    Direct link= http://speedywap.com

  4. VISH

    Hi, It is giving me a 404 error even after I have moved the postview-js.php to the wp-content direcory. Check it at my website SpeedyWap

  5. Rosyidi

    I stil don’t understand abut “Place a symbolic link”. What is symbolic means?
    Maybe I’ll repost this plugin on May 3.

  6. Thaya Kareeson

    @Rosyidi

    You can find information about what symbolic links are at Wikipedia. Symbolic links are only available on a Unix/Linux environment. If you are hosting from a Windows machine, you can just move wp-postviews-js.php directly under your wp-content/ directory to achieve the same effect. Hope this helps.

  7. JTPratt’s Blogging Mistakes

    I thank you for this fix – it worked GREAT on one of my sites! It didn’t (and may never) on my main site though, since I use 4 dozen odd plugins. I wonder, sezwho was one problem I had, as well as wp-postratings by lester chan.

    What happens with the WP-Stats plugin (wordpress.com official stats) when wp-super-cache is enabled? Are views of cached pages counted in your stats, or not?

  8. justfrank

    It works. And it works GREAT!
    Moving wp-postviews-js.php into wp-content was enough, no need to mess with symbolic links, for who doesn’t know how to do this 😉

  9. Thaya Kareeson

    @JTPratt

    What is your main site? I’m not sure why it’s not working on your main site, but I believe the reason could be that the Javascript in this mod clashes with one of your other plugins’ Javascript. The mod I did here is supposed to work with any other cache plugin, but WP-Super-Cache is supposed to have a hook called “add_cacheaction” that can be used to add a count action. I’ll look into it to see if this method would work (and probably write a post about it if it does).

    @justfrank

    Thank you for visiting! I’m glad that the mod worked out for you.

  10. Thaya Kareeson

    @JTPratt

    I forgot to answer the second part of your question. I’m pretty sure the WP-Stats plugin will not record hits if WP-Super-Cache is enabled. That said, I think it can also benefit from the method of using WP-Super-Cache’s add_cacheaction hook. I’ll explore this further and keep you posted on my findings.

  11. JTPratt’s Blogging Mistakes

    My main site is www.jtpratt. Now, after 24 hours – my other site I thought everything was working on isn’t registering and counts on postviews at all. On the other hand, WP-Stats seems to be working fine ( so far )…

  12. Thaya Kareeson

    @JTPratt

    Interesting, I will have to look into WP-Stats to see how it works. Thank you.

  13. sylv3rblade

    I can’t seem to make it work. Postviews doesn’t count even when Super Cache is off. Do you have a list of compatible plugins or at least those that have conflicts with this?

  14. Thaya Kareeson

    @sylv3rblade

    Sorry I do not have a list of compatible/conflicting plugins. Please stay tuned, I will be releasing a non-javascript version soon (within the next day or two). Sorry for the delay!

  15. sylv3rblade

    Err no wait.. Scratch that. I forgot about the symbolic link. Umm… does shared hosting even support that? Can I use .htaccess?

  16. Thaya Kareeson

    @sylv3rblade

    It depends on your shared host. I recommend just moving wp-postviews-js.php directly under your wp-content/ directory if your hosting does not support symbolic links.

  17. sylv3rblade

    Thanks. I got it working now. I think I screwed up the first time because I had a copy of wp-postviews-js.php on both the wp-content directory and the wp-postviews directory

    Thanks again.

  18. hendra

    Thanks a lot. Just advice to the others, if you activate this plugin, its better to you to delete the cache of wp-super-cache, after activating this plugin.

  19. Thaya Kareeson

    @sylv3rblade

    I’m glad it works out for you.

    @hendra

    I’m glad it works out for you too, and thank you for your advice.

  20. Rosyidi

    I will be releasing a non-javascript version soon

    @ Thaya : Than, it still work on wp super cache?

  21. Thaya Kareeson

    @Rosyidi

    Yes, I will make use of WP-Super-Cache’s add_cacheaction hook to get WP-PostViews to count without Javascript while WP-Super-Cache is enabled. After evaluating the code, there is more work involved than I first thought, but it should be more efficient than the Javascript version when finished.

  22. Thaya Kareeson

    @All

    Unfortunately, it turns out that I misunderstood the add_cacheaction hook. Previously, I thought that add_cacheaction hook gets called every time before a cached page is delivered. I was wrong and there currently is no such hook available in WP-Super-Cache right now. I will definitely make a request to Donncha to add this to WP-Super-Cache. So as it stands, you are stuck with the JS Mod version of WP-PostViews.

    I have to appologize for getting your hopes up. The WP-Super-Cache code is quite complex (if Donncha doesn’t walk you through it :)), so it took me a while to figure this out.

  23. Rosyidi

    I think you are expert on wp-super-cache. Could you convert this plugin for wp-super cache?
    http://privism.org/blog/archives/12
    It’s simple plugin I think. Couse only 25 lines.
    Thanks a lot.

  24. Thaya Kareeson

    @Rosyidi
    Let me look into it. I will get back to you :-).

  25. Andy

    Hi man! Thanks for your small hack. Actually I’m quite some Validation and Clean-HTML-Freak and I found out the Tidy HTML has some problems with the code of wp-postview.php.. Looks like you’d have to change the Javascript-code quite a bit to get it validated. I’m not quite sure if there would be an easier solution than mine, but at least it validates fine and makes no problems… This is for line 76 and following:
    echo ”;
    echo ‘// <![CDATA[‘;
    echo ‘wp_postviews_js_url = “DOMAINNAME/wp-content/wp-postviews-js.php”;’;
    echo ‘document.write(“”;
    echo ‘”);’;
    echo ‘// ]]>’;
    echo ”;

  26. Andy

    Hmmm, of course this got f**ed up by the commenting system.. I’ll try again, instead of ** you’d have to use “<“:
    echo ‘**script type=”text/javascript”**’;
    echo ‘// **\/script>”;
    echo ‘”);’;
    echo ‘// ]]>’;
    echo ‘**/script>’;

  27. Thaya Kareeson

    @Andy

    Thank you for the clean-HTML fixes. I suffer from a mild code O.C.D myself so I totally understand. I will include this change into the zip archive and notify Lester Chan tonight. And please remember to write about it if you like it :).

  28. Thaya Kareeson

    I have incorporated Andy’s clean-HTML fixes and repacked it into the downloadable zip. Enjoy!

  29. funnylolfunny

    hi.. installed.. but not working (2.5.1) missed anything?
    i cannot make the symbolic link.. i just move the wp-postviews-js.php to /wp-content

    how? example http://funnylolfunny.com/orange-escape/

  30. funnylolfunny

    cool!!!! its working now.. thanks Thaya! you rock!

  31. Thaya Kareeson

    @funnylolfunny
    I’m so happy every time I get a message like yours. Thank you for the compliment and I’m glad that it works out for you.

  32. graphicscale

    thank very much thaya ^^.

  33. Chris SX

    Works like a charm! Thanks a lot … I spent my morning trying to figure out what was the reason for this bug, ’til i found it was due to WP Super Cache.

    Now i hope Lester will integrate the fix in his plugin, or if you can manage to upgrade your hack for v1.31 …

    Thanks !

  34. Thaya Kareeson

    @Chris SX
    Lester Chan did integrate this change into the WP-PostViews release. See my post about it.

  35. Chris SX

    Hey,
    yeah i know but it just doesnt work properly, sorry.
    I’m going to add your features in his 1.31 to get something working

    Thanks.

  36. Ajay

    Hi, I'm working on a plugin that is again conflicting with WP-Super-Cache. I took a look at Lester's PostViews which includes your fix, and incorporated that but it still won't update.

    Also, why exactly is a symbolic link needed? Can this be generated in PHP itself?

  37. Thaya Kareeson

    @Ajay
    I made this fix a long time ago before I learned the proper way for doing such things. There is really no need to create a symbolic link to do such a task and you are right that it can be generated by PHP itself.

    It sounds like I should write a tutorial for plugin developers on how to make their plugins WP-Super-Cache compliant.

  38. Ajay

    I guess you should!

[go to first comment]

Leave a Reply