wp-rocket
wp-rocket copied to clipboard
Compatibility with Rocket.net hosting (sync cache purging)
Before submitting an issue please check that you’ve completed the following steps:
- [x] Made sure you’re on the latest version
3.11.4.2
- [x] Used the search feature to ensure that the bug hasn’t been reported before
Describe the bug Rocket.net uses Cloudflare to manage its page cache.
When cache is purged by WP Rocket, the website content will remain stale until it's purged on their end.
They use a must-use plugin with two specific methods that can help sync cache purging with WP Rocket:
- purge_cache_queue() for single URL purge
- purge_cache() to clear all cache
Attached the MU plugin: https://drive.google.com/file/d/1X7O-DLRHIEh6sj1GAr0UGz5KlDSv2IKA/view?usp=sharing
To Reproduce Steps to reproduce the behavior:
- Use the Rocket.net environment
- Purge cache
- See content not updated
Expected behavior WP Rocket can use the MU plugins methods to sync cache purging.
Screenshots N/A
Additional context Ticket - https://secure.helpscout.net/conversation/1947036106/355494
Backlog Grooming (for WP Media dev team use only)
- [ ] Reproduce the problem
- [ ] Identify the root cause
- [ ] Scope a solution
- [ ] Estimate the effort
Our Rocket.net MU plugin already ties into several WP-Rocket hooks and we haven’t seen any cases about this. Unless it’s some sort of update that recently took place.
Have you already contacted our Rocket.net support?
I didn't know that you guys had compatibility with WP Rocket, so I didn't look for our hooks on your MU plugin. Thank you for pointing that out, @bgabler.
Now I see that you are hooked up to rocket_purge_cache
and set_transient_rocket_preload_complete
.
Only manual cache purging and cache purging after preload are covered.
However, it doesn't cover other scenarios like purging individual posts/URLs or clearing cache after an update of WP Rocket, for example (that was the issue reported by the customer).
You should replace rocket_purge_cache
with after_rocket_clean_domain
. This will give a more accurate trigger when a full cache purge should happen.
Post cache can also be cleared using your MU plugin by post ID. To sync cache clearing with that, you can use the following hook:
- Clear cache by post ID -
after_rocket_clean_post
- that can be used with yourpurge_cache_queue
.
The following additional hooks can also be considered, but they will require extending your MU plugin to cover purging URLs:
- Clear home page -
after_rocket_clean_home
- Clear a specific URL -
after_rocket_clean_file
I will ask the customer to submit the above details through your ticket system so you guys can have a look.
Aweosme!! Thank you so much, we emailed in a while back and those where the only hooks we got so this is super helpful
@bgabler I was discussing the missing cache purge on Rocket.net Cloudflare implementation.
We pass an URL on our filters. And I can see that purge_cache_queue
is expecting an ID on your mu-plugin. You need a method that will process a URL.
Also, I added a couple of additional hooks that need to be added to make sure cache purge happens when RUCSS is doing its thing:
- rocket_rucss_after_clearing_usedcss
- rocket_rucss_complete_job_status
@bgabler I was discussing the missing cache purge on Rocket.net Cloudflare implementation. We pass an URL on our filters. And I can see that
purge_cache_queue
is expecting an ID on your mu-plugin. You need a method that will process a URL. Also, I added a couple of additional hooks that need to be added to make sure cache purge happens when RUCSS is doing its thing:
- rocket_rucss_after_clearing_usedcss
- rocket_rucss_complete_job_status
That's awesome, I'll get this added to our plugin ASAP.
Thank you!
As an FYI - I was able to get this working correctly by adding the following to the cdn_clear_cache_hooks.php of the rocket.net cdn plugin.
/**
- Custom code by Philip Brooks */ add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('after_rocket_clean_post', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('rocket_rucss_after_clearing_usedcss', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('rocket_rucss_complete_job_status', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('after_rocket_clean_domain', array($this, 'purge_wp_rocket_cache_clear'), PHP_INT_MAX ); add_action('after_rocket_clean_post', array($this, 'purge_wp_rocket_cache_clear'), PHP_INT_MAX );
Let me know if any changes or additions should be made
@Equinox-Webmaster it will work, but you are clearing the whole cache in scenarios where only specific URLs should be cleared.
Which function is clearing the whole cache? There are two that are in the cdn helper purge_cache and purge_everything_cache (not looking at the code so might be slightly off)
Philip Brooks Dragon-Kin The Equinox Apothecary
From: Adame Dahmani @.> Sent: Sunday, February 18, 2024 10:41:36 PM To: wp-media/wp-rocket @.> Cc: Philip B @.>; Mention @.> Subject: Re: [wp-media/wp-rocket] Compatibility with Rocket.net hosting (sync cache purging) (Issue #5252)
@Equinox-Webmasterhttps://github.com/Equinox-Webmaster it will work, but you are clearing the whole cache in scenarios where only specific URLs should be cleared.
— Reply to this email directly, view it on GitHubhttps://github.com/wp-media/wp-rocket/issues/5252#issuecomment-1951799135, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BFZYDBP7NQI3CTKSWD4BRTTYULX2BAVCNFSM54CKSJLKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJVGE3TSOJRGM2Q. You are receiving this because you were mentioned.Message ID: @.***>
Ah I see (not a programmer so it takes me a bit longer)
I am testing this change to the method:
public function purge_wp_rocket_cache_clear($type, $url = null){ if($type == 'all'){ $this->purge_cache(); } elseif ($url) { // Purge cache for specific URL CDN_Clear_Cache_Api::cache_api_call([$url], 'purge'); } }
And the following chamges to my calls:
//clear full site cache add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('rocket_purge_cache', array($this, 'purge_cache'), PHP_INT_MAX ); add_action('rocket_rucss_after_clearing_usedcss', array($this, 'purge_cache'), PHP_INT_MAX );
//clear single post cache
add_action('after_rocket_clean_post', array($this, 'purge_wp_rocket_cache_clear'), PHP_INT_MAX, 2);
add_action('rocket_rucss_complete_job_status', array($this, 'purge_wp_rocket_cache_clear'), PHP_INT_MAX, 2);
add_action('rocket_after_automatic_cache_purge', array($this, 'purge_wp_rocket_cache_clear'), PHP_INT_MAX, 2);
I'll do some testing and let you guys know
Ok i got this pretty close (note error_log triggers are for basic debugging) ALl code located in the cdn-clear-cache-hooks.php This is just a status report.
/**
* Custom code by Philip Brooks - Add action hooks from WPR
*/
//clear full site cache
add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_purge_cache', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_rucss_after_clearing_usedcss', array($this, 'purge_cache'), PHP_INT_MAX );
//clear single post cache
add_action('rocket_rucss_complete_job_status', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_post', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('rocket_after_automatic_cache_purge', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
// Custom function by Philip Brooks to translate any URLS passed by WP Rocket into post_id's
public function translate_wpr_urls_to_postid($array) {
// If $array is not an array, convert it to an array
if (!is_array($array)) {
$array = array($array);
}
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("Begin " . __FUNCTION__); // Fixed this line
// Initialize an empty array to hold post IDs
$post_ids = [];
// Loop through each item in the array
foreach ($array as $item) {
// Check if the item is a URL
if (filter_var($item, FILTER_VALIDATE_URL)) {
// Convert the URL to a post ID and add it to the post_ids array
$post_ids[] = url_to_postid($item);
error_log("I was a URL!" . print_r($item, true));
} else {
// The item is already a post ID, so add it to the post_ids array
$post_ids[] = $item;
error_log("I was a post ID!" . print_r($item, true));
}
}
// Now that we have an array of post IDs, pass each post ID to the purge_cache_queue function
foreach ($post_ids as $post_id) {
$this->purge_cache_queue($post_id);
}
error_log("The New function has finished");
}
/**
* purge post cache
*/
public function purge_cache_queue($post_id = null, $force = false){
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("I have fired the purge_cache_queue Value of \$post_id in " . __FUNCTION__ . ": " . print_r($post_id, true));
// static $purge_counter;
error_log("The purge post cache has finished");
// Autosaving never updates published content.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
/* // If we've purged "enough" times, stop already.
// Log the current value of $purge_counter
error_log("Current value of \$purge_counter in " . __FUNCTION__ . ": " . print_r($purge_counter, true));
if ( isset($purge_counter) && $purge_counter >= 2 && ! $force ) {
return false;
}
*/
if($this->get_wp_all_import_flag())
return false;
// Initialize $list_of_urls as an empty array
$list_of_urls = array();
if ( $post_id && $post_id > 1 && !! ( $post = get_post( $post_id ) ) ) {
$list_of_urls = array_merge($list_of_urls, $this->get_post_related_links($post_id, $post));
$list_of_urls = apply_filters('cdn_purge_cache_urls', $list_of_urls, $post_id);
// Log the value of $list_of_urls
error_log("Value of \$list_of_urls in " . __FUNCTION__ . ": " . print_r($list_of_urls, true));
$retval = CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
}
// At this point, we know we're going to purge, so let's bump the purge counter. This will prevent us from
// over-purging on a given request.
// BWD: I'm not sure this is necessary and may actually be harmful, depending on how many updates to a given
// post can happen within a single request.
/* if ( ! isset( $purge_counter ) ) {
$purge_counter = 1;
} else {
$purge_counter++;
}
*/ error_log("The purge post cache has finished");
}
I have commented out the purge_counter as it proved to be a point of failure when clearing more that one post at a time.
So far everything works exept any dynamically created page as they do not have post_id's. My next plan of attack is actually allowing the purge_cache_queue to accept post_id's or URL's because for some reason it takes only a post_id and turns it back into a url. Either that or i'll make a seperate purge_cache_queue function just for WPR.
Any feedback is appreciated. Also @DahmaniAdame do i have all the action_hooks WPR uses that should be cleared? Either site wide or single post?
OK, this version of things works a lot better, I am still having issues getting all the hooks to fire, but things seem to be working. I will continue to test, hence all the error_logs
All my action calls
/**
* Custom code by Philip Brooks - Add action hooks from WPR
*/
//clear full site cache
add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_purge_cache', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_rucss_after_clearing_usedcss', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('set_transient_rocket_preload_complete', array($this, 'purge_cache'), PHP_INT_MAX );
//clear single post cache
add_action('rocket_rucss_complete_job_status', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_post', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('rocket_after_automatic_cache_purge', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_file', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_home', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
This is where much of the magic happens.
// Custom function by Philip Brooks to translate any URLS passed by WP Rocket into post_id's
public function translate_wpr_urls_to_postid($array) {
static $last_url = null;
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("Begin " . __FUNCTION__);
// If $array is not an array, convert it to an array
if (!is_array($array)) {
$array = array($array);
}
// Loop through each item in the array
foreach ($array as $item) {
// Check if the item is a URL
if (filter_var($item, FILTER_VALIDATE_URL)) {
// If the current URL is the same as the last processed URL, skip processing
if ($item === $last_url) {
continue;
}
// Convert the URL to a post ID
$post_id = url_to_postid($item);
error_log("I was a URL!" . print_r($item, true));
// If the post_id is 0, pass the URL to the purge_cache_queue_url function
if ($post_id === 0) {
error_log("I was a Dynamic URL!" . print_r($item, true));
$parsed_url = parse_url($item);
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
$url_without_domain = $path . $query . $fragment;
// Ensure the URL ends with a trailing slash
if (substr($url_without_domain, -1) !== '/') {
$url_without_domain .= '/';
}
$this->purge_cache_queue_url($url_without_domain);
} else {
// The post_id is greater than 0, so pass it to the purge_cache_queue function
error_log("I was a URL that got transformed into a post_id" . print_r($item, true));
$this->purge_cache_queue($post_id);
}
// Store the current URL as the last processed URL
$last_url = $item;
} else {
// The item is already a post ID, so pass it to the purge_cache_queue function
$this->purge_cache_queue($item);
error_log("I was a post ID all along!" . print_r($item, true));
}
}
error_log("The New function has finished");
}
I had to make some adjustments to this existing method, all the $purge_counter references needed to be removed or half the time the wpr page cache would not rebuild:
/**
* purge post cache
*/
public function purge_cache_queue($post_id = null, $force = false){
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("I have fired the purge_cache_queue Value of \$post_id in " . __FUNCTION__ . ": " . print_r($post_id, true));
// static $purge_counter;
error_log("The purge post cache has finished");
// Autosaving never updates published content.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
/* // If we've purged "enough" times, stop already.
// Log the current value of $purge_counter
error_log("Current value of \$purge_counter in " . __FUNCTION__ . ": " . print_r($purge_counter, true));
if ( isset($purge_counter) && $purge_counter >= 2 && ! $force ) {
return false;
}
*/
if($this->get_wp_all_import_flag())
return false;
// Initialize $list_of_urls as an empty array
$list_of_urls = array();
// If post_id is 0, add the homepage URL to $list_of_urls
if ($post_id === 0) {
// Get the URL of the homepage
$homepage_url = get_home_url();
// Add the homepage URL to $list_of_urls
$list_of_urls[] = $homepage_url;
}
if ( $post_id && $post_id > 1 && !! ( $post = get_post( $post_id ) ) ) {
$list_of_urls = array_merge($list_of_urls, $this->get_post_related_links($post_id, $post));
$list_of_urls = apply_filters('cdn_purge_cache_urls', $list_of_urls, $post_id);
// Log the value of $list_of_urls
error_log("Value of \$list_of_urls in " . __FUNCTION__ . ": " . print_r($list_of_urls, true));
$retval = CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
}
// At this point, we know we're going to purge, so let's bump the purge counter. This will prevent us from
// over-purging on a given request.
// BWD: I'm not sure this is necessary and may actually be harmful, depending on how many updates to a given
// post can happen within a single request.
/* if ( ! isset( $purge_counter ) ) {
$purge_counter = 1;
} else {
$purge_counter++;
}
*/ error_log("The purge post cache has finished");
}
Here is a new CDN purge method when items are only URLs, because the post_id is 0 - like dynamic pages.
/**
* Purge cache for a specific URL
*/
public function purge_cache_queue_url($url = null, $force = false){
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("I have fired the purge_cache_queue_url Value of \$url in " . __FUNCTION__ . ": " . print_r($url, true));
// Autosaving never updates published content.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
if($this->get_wp_all_import_flag())
return false;
// Initialize $list_of_urls as an empty array
$list_of_urls = array();
// If url is not null, add it to $list_of_urls
if ($url !== null) {
// Add the URL to $list_of_urls
$list_of_urls[] = $url;
}
if (!empty($list_of_urls)) {
$list_of_urls = apply_filters('cdn_purge_cache_urls', $list_of_urls);
// Log the value of $list_of_urls
error_log("Value of \$list_of_urls in " . __FUNCTION__ . ": " . print_r($list_of_urls, true));
$retval = CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
}
error_log("The purge post cache has finished");
}
There is no need to translate URLs to IDs. It's an additional overhead to a method that will take ultimate a URL. And we happen to provide URLs on our actions.
All that is needed is to hook to our actions, and call CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
to purge URLs provided by our actions.
This one rocket_rucss_after_clearing_usedcss
will return an individual URL. There is no need trigger a full cache purge for it.
The issue, if I remember correctly as I tried a lot of things and am not a programmer, is that their function needs a post_id because it also parses out related tags, and other items from real posts based on post_id since Wordpress doesn't store any relationship data in the database per URL. it's the reliance on $this->get_post_related_links to ensure other related items are purged (a good idea BTW) that forces me to split the url's WPR sends into those with post_id's and those without then shoot them either to my new function or theirs. Again, not a programmer so I had to rely on those error_log checks you see and my own opbervation as to what worked, didn't work, crashed, etc...
rocket_rucss_after_clearing_usedcss
thanks for the info! I thought this fired on clearing all RUCSS, I'll update my code. I couldn't get it, nor a handful of other action_hooks to even fire... Mirna sent me a cache clear file debugger to see what is happening but there is a whole list of hooks I can't get to fire, no matter what.
@DahmaniAdame I wanted to say thank you for assisting me with this, you and the team have been really helpful in crossing this gap.
Ok, my last code update before I go on vacation.
What works:
- RUCSS generation now works 100% of the time and purges CDN when complete allowing the page cache to regenerate properly.
- Manually clearing the WPR page cache appears to work but I cannot get the action hooks to register as firing so more testing is needed.
- Purging a single URL via WPR - Clears the local cache and regenerates it correctly. Still need to test what happens when a real person steps in before the preload - more on that another day
- Preload - I know this is not required but I got this to work perfectly. Special code was required here as the array is (for lack of knowing the proper word) a multi-dimensional array that spit out some specific and not compatible url data.
- full RUCSS and partial RUCSS purging works
- Manual post updating still works
What doesn't work: I cannot get many of the action hooks to actually trigger. I have confirmed the correct hooks exist in code but I simply cannot get proof that they fire outside of WPR, within WPR the related actions are working:
add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_purge_cache', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('set_transient_rocket_preload_complete', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('after_rocket_clean_post', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_file', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_home', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('rocket_rucss_after_clearing_usedcss', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX );
At this point without more log files this will take more time to test to see if any of these are actually necessary or if they are redundant.
Here is the updated code:
/**
* Custom code by Philip Brooks - Add action hooks from WPR
*/
//clear full site cache
add_action('after_rocket_clean_domain', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('rocket_purge_cache', array($this, 'purge_cache'), PHP_INT_MAX );
add_action('set_transient_rocket_preload_complete', array($this, 'purge_cache'), PHP_INT_MAX );
//clear single post cache
add_action('rocket_rucss_complete_job_status', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_post', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_file', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('after_rocket_clean_home', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX);
add_action('rocket_rucss_after_clearing_usedcss', array($this, 'translate_wpr_urls_to_postid'), PHP_INT_MAX );
// WPR Auto purge array transform
add_action('rocket_after_automatic_cache_purge', function($data) {
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("Input data: " . print_r($data, true));
// Check if the first item in $data is an array and contains 'home_path', 'home_url' and 'files' keys
if (!is_array($data[0]) || !isset($data[0]['home_path']) || !isset($data[0]['files']) || !isset($data[0]['home_url'])) {
error_log("Missing 'home_path', 'home_url' or 'files' in data");
return;
}
$home_path = $data[0]['home_path'];
$home_url = $data[0]['home_url'];
$files = $data[0]['files'];
// Replace the home path with the home URL in each file path
$files = array_map(function($file) use ($home_path, $home_url) {
// Safety check: Ensure the file path starts with the home path
if (strpos($file, $home_path) === 0) {
return str_replace($home_path, $home_url, $file);
} else {
// Handle the case where the file path does not start with the home path
error_log("File path does not start with home path: " . $file);
return $file;
}
}, $files);
error_log("Processed data: " . print_r($files, true));
// Pass the modified files array to the translate_wpr_urls_to_postid method
$this->translate_wpr_urls_to_postid($files);
}, PHP_INT_MAX);
// Custom function by Philip Brooks to translate any URLS passed by WP Rocket into post_id's
public function translate_wpr_urls_to_postid($array) {
static $last_url = null;
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("Begining: " . __FUNCTION__);
// If $array is not an array, convert it to an array
if (!is_array($array)) {
$array = array($array);
}
// Loop through each item in the array
foreach ($array as $item) {
// Check if the item is a URL
if (filter_var($item, FILTER_VALIDATE_URL)) {
// If the current URL is the same as the last processed URL, skip processing
if ($item === $last_url) {
continue;
}
// Convert the URL to a post ID
$post_id = url_to_postid($item);
error_log("I was a URL! - " . print_r($item, true));
// If the post_id is 0, pass the URL to the purge_cache_queue_url function
if ($post_id === 0) {
error_log("I was a Dynamic URL! - " . print_r($item, true));
$parsed_url = parse_url($item);
$path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
$query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
$fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
$url_without_domain = $path . $query . $fragment;
// Ensure the URL ends with a trailing slash
if (substr($url_without_domain, -1) !== '/') {
$url_without_domain .= '/';
}
$this->purge_cache_queue_url($url_without_domain);
} else {
// The post_id is greater than 0, so pass it to the purge_cache_queue function
error_log("I was a URL that got transformed into a post_id - " . print_r($item, true));
$this->purge_cache_queue($post_id);
}
// Store the current URL as the last processed URL
$last_url = $item;
} else {
// The item is already a post ID, so pass it to the purge_cache_queue function
$this->purge_cache_queue($item);
error_log("I was a post ID all along!" . print_r($item, true));
}
}
error_log("The Translate WPR function has finished");
}
/**
* purge post cache
*/
public function purge_cache_queue($post_id = null, $force = false){
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("I have fired " . __FUNCTION__ . ". The following value was passed: " . print_r($post_id, true));
// static $purge_counter;
// Autosaving never updates published content.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
/* // If we've purged "enough" times, stop already.
// Log the current value of $purge_counter
error_log("Current value of \$purge_counter in " . __FUNCTION__ . ": " . print_r($purge_counter, true));
if ( isset($purge_counter) && $purge_counter >= 2 && ! $force ) {
return false;
}
*/
if($this->get_wp_all_import_flag())
return false;
// Initialize $list_of_urls as an empty array
$list_of_urls = array();
if ( $post_id && $post_id > 1 && !! ( $post = get_post( $post_id ) ) ) {
$list_of_urls = array_merge($list_of_urls, $this->get_post_related_links($post_id, $post));
$list_of_urls = apply_filters('cdn_purge_cache_urls', $list_of_urls, $post_id);
// Log the value of $list_of_urls
$retval = CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
}
// At this point, we know we're going to purge, so let's bump the purge counter. This will prevent us from
// over-purging on a given request.
// BWD: I'm not sure this is necessary and may actually be harmful, depending on how many updates to a given
// post can happen within a single request.
/* if ( ! isset( $purge_counter ) ) {
$purge_counter = 1;
} else {
$purge_counter++;
}
*/ error_log("The purge post cache has finished");
}
/**
* Purge cache for a specific URL
*/
public function purge_cache_queue_url($url = null, $force = false){
ini_set('error_log', 'public_html/wp-content/cache/error.log');
error_log("I have fired" . __FUNCTION__ . ". The following value was passed: " . print_r($url, true));
// Autosaving never updates published content.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
if($this->get_wp_all_import_flag())
return false;
// Initialize $list_of_urls as an empty array
$list_of_urls = array();
// If url is not null, add it to $list_of_urls
if ($url !== null) {
// Add the URL to $list_of_urls
$list_of_urls[] = $url;
}
if (!empty($list_of_urls)) {
$list_of_urls = apply_filters('cdn_purge_cache_urls', $list_of_urls);
// Log the value of $list_of_urls
$retval = CDN_Clear_Cache_Api::cache_api_call($list_of_urls, 'purge');
}
error_log("The purge post cache has finished");
}
I will return the core purge_cache_queue method to its original state and create a new function for use with WPR so that there are no surprises with rocket.net's code. for now, this is just for testing.
I know this seems like strange overkill but I have gone through 3 hosts with different levels of issues with cache creation and even on a pristine site with zero code adjustments I have seen this, but not until significant hunting on my part. Sometimes months of looking, feeling something is off, and finally having the time to really dig did I find that there was, in fact, a problem.
With these code changes, this is the very first time I have seen everything play nicely together. Thanks for having the openness to allow me to make these changes, if only to help myself :)