Fire a Custom Function After Cache is Cleared for a URL

Hi

I have comet cache pro and I really need to do some tasks after the cache is cleared for a certain URL.

I can’t see any actions we can hook into from searching the code.

Is something like this possible? I can’t just use the wp save_post hook etc I need to fire a function when the cache is auto cleared by comet cache due to page age too.

add_action(‘comet_cache_cleared’, ‘my_function’);

function my_function($url)
{
//do what I need to with $url
}

I really hope someone can help.

Thanks,

1 Like

Hi Alex,

There isn’t a hook there for you to use… I’ll see what I can do.

In the meantime, what you can do is add a hook there for your hack to kick in. You would need to add the hook again after updating the plugin, but in the meantime you’d be making progress.

If you share with me where the hook worked best, I may include it in a future release.

Would that help? :slight_smile:

Great, yes I was going to go down that route.

I will do some testing tomorrow. But from searching I think I could add do_action() to

comet-cache-pro\src\includes\traits\Plugin\WcpPostUtils.php line 29

autoClearPostCache($post_id, $force = false)

I know the original plugin devs have moved on, but if you know a better place I could add this please let me know.

I will let you know how I get on.

Many thanks,

1 Like

Hi

I managed to get this working fairly well by adding the following on line 114 of /comet-cache-pro/src/includes/traits/Plugin/WcpPostUtils.php

do_action(‘comet_cache_url_cleared’, $post_id);

The above fires when you save a post or page in wp-admin/ and also if you visit a page on the front end where the cache needs to be rebuilt.

Hopefully something like this can be added so I don’t need to hack it in.

Are you still accepting pull requests, though I am not sure I have placed it 100% in the best place anyway.

Cheers

1 Like