I use WP-Rocket on our site, but page caching (same issue if only using Cloudflare APO) is preventing the comment count from updating. I verified this by disabling WP-Rocket (and/or APO), posted a reply on the corresponding forum post and the comment count updates, but erratically. As in, not instant or as you might expect.
So I found a tip on adding a web hook and that allowed the comment count to reliably update.
However, with page caching on (WP-Rocket or APO), and using that web hook, the comment counts are not updating when someone posts a new reply in the forum.
The gist, it seems, the web hook is not triggering the WP environment properly to trigger the refresh of the cached page. It seems we might have a glitch in the matrix.
Edit: Another bit. I have WP-Rocket setup so when I am logged into Wordpress, the pages are not cached for me. Only for visitors. I noticed, I see comment counts update when I am logged into Wordpress, but I do not see them when I am a visitor in private browser mode.
I donāt have any answers, but as you know WP Rocket is trying to do a static copy and eliminate PHP and database calla. It is not a cache per se, but sure ā that is matter of definition.
But WP Rocket has a lot issues nowadays, and this is perhaps one of the most minor ones when thinking WordPress site itself.
Hey @Brandon007, thanks for explaining your issue. As I understand it:
The WP Discourse Plugin is updating comment counts correctly.
The WP Rocket cache is not being cleared when the comment counts are updated.
Iāve changed the title of your post from āWP Discourse Plugin Not Updating Comment Countā to āWP Discourse comment webhook does not trigger a WP Rocket Cache refreshā.
The basic answer to your issue is that this is expected behavior. The WP Discourse plugin doesnāt have any specific integration with WP Rocket and wonāt be adding one in the foreseeable future.
But I can still help you here by adding in an action that fires after the comment sync webhook callback has updated the topic metadata (where the comment count is stored). You could then write your own action callback to do whatever cache clearing you desired. Would that work for your situation?
Iāll probably be lost writing code haha, but if you can make it possible. That puts me and other users one step in the right direction. It sounds like, with your modification it will allow user end code to be added to clear caching for any caching plugin. That would be even better than focusing on one product. I tried several cache methods on a dev site and they all had the same result anyway.
So carry on my good sir, and thanks for the response.
Hey Angus. Iām not sure if this was something you were still looking into?
Something else I wanted to add. Within native Wordpress, and using any form of page caching. Once a comment is left, the page cache purges on its own. Isnāt there a way where WP Discourse can mimic that behavior?
Hey Brandon, yes there will be an action for this, allowing you to clear the WP Rocket cache (or any other cache) in this scenario in the next release.
Iām not questioning your or anybodyās skills and I donāt know anything, but there canāt be anything like āor any cacheā because AFAIK WP Rocket needs different tools to purge its caching than W3 Total Cache than WP Fastest Cache than any reverse proxy like Varnish or Nginx.
And if WP Rocket is creating static part of page, aka. cache, from comment section there is much bigger issues than purging.
Thatās correct. The WP Discourse plugin will simply provide an action that will allow sites using different caching solutions to purge the cache at the appropriate time using whatever method is appropriate to the caching solution being used.
Angus, thanks for the follow-up. Any general idea on the release date?
Also, is it possible for WP-Discourse to mimic the behavior of native Wordpress comments? Simply meaning, page cache solutions have an option, so the page cache can be cleared when a user leaves a new comment on that page. This is ideal.
As you know, as of today, we are unable to use page caching of any kind, if we want the comment count to increment. Thatās a big drawback for Wordpress users who are concerned with speed optimizations.
I forgot to mention, your update did fix the issue! Thank you.
For anyone else running into this issue while running WP-Rocket with WP-Discourse. The following code (insert in your Wordpress function file) will ensure once a comment is made on the corresponding Discourse post, it will purge the cache for that post.
if( function_exists( 'rocket_clean_post' ) ){
add_action( 'wpdc_after_webhook_post_update', 'bulk_rocket_clean_postā);
}
function bulk_rocket_clean_post(array $ids){
foreach ($ids as $id) {
rocket_clean_post($id);
}
}