Purging Cloudflare’s Wordpress APO Plugin when using WP Discourse?

With WordPress, we are running the Cloudflare plugin with APO. We are also using the WP Discourse plugin for blog comments. However, once a comment is added to a post, APO does not recognize a comment was added so the cache for that post is not purged. That means the comment count on the Wordpress post never updates.

We had a similar issue with WP Rocket not purging the cache when a new comment was added to the forum. I worked with those guys and they provided the following code which works.

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) {

The wpdc_after_webhook_post_update action was provided by the WP Discourse team. The rest of the code came from the WP Rocket team to fire the action.

My question, what code can we add to our site so when someone leaves a comment on the forum, it registers with the Cloudflare plugin so the APO cache for that post is purged and the comment count is updated on the Wordpress post?

Thank you!!

I recently opened a forum post about this which was closed. I’ve also opened a ticket with CF which said to reach out to the forum. :man_shrugging:t3:

@wwoodhead Would you be able to shed some insight on this?

Hi there,

From what I can see, the Cloudflare Wordpress Plugin has a similar function to rocket_clean_post. However the Cloudflare equivalent takes an array of post ids rather than single post id.

The function is called purgeCacheByRelevantURLs

This has not been tested but you could try the following code:

if( function_exists( 'purgeCacheByRelevantURLs' ) ){
	add_action( 'wpdc_after_webhook_post_update', 'purgeCacheByRelevantURLs’);

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.