Skip to content

Commit

Permalink
update cache_controller.php
Browse files Browse the repository at this point in the history
  • Loading branch information
shyambaseapp committed Nov 11, 2024
1 parent fde63a5 commit 9a8afea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
1 change: 0 additions & 1 deletion source/admin/class-wpoven-triple-cache-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,6 @@ function wildcard_match($pattern, $subject)

if (!preg_match($pattern, $subject, $regs))
return false;

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion source/libs/backend.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function autoprefetch_config_wp_enqueue_scripts()
*
* https://wordpress.stackexchange.com/questions/298762/wp-add-inline-script-without-dependency/311279#311279
*/
wp_register_script('wpocf_auto_prefetch_url', '', [], '', true);
wp_register_script('wpocf_auto_prefetch_url', '', [], '1.0.0', true);
wp_enqueue_script('wpocf_auto_prefetch_url');

// Making sure we are not adding the following inline script for AMP endpoints as they are not gonna work anyway and will be striped out by the AMP system
Expand Down
16 changes: 12 additions & 4 deletions source/libs/cache_controller.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ function purge_cache_queue_write($urls = array(), $purge_all = false)

if (file_exists($cache_queue_path)) {

$wpocf_cache_queue = json_decode(file_get_contents($cache_queue_path), true);
$wpocf_cache_queue = json_decode(wp_remote_get($cache_queue_path), true);

if (!is_array($wpocf_cache_queue) || (is_array($wpocf_cache_queue) && (!isset($wpocf_cache_queue['purge_all']) || !isset($wpocf_cache_queue['urls'])))) {
$this->unlock_cache_purge_queue();
Expand All @@ -1539,7 +1539,15 @@ function purge_cache_queue_write($urls = array(), $purge_all = false)
$urls = array();
$wpocf_cache_queue = array('purge_all' => $purge_all, 'urls' => $urls);
}
file_put_contents($cache_queue_path, wp_json_encode($wpocf_cache_queue));

global $wp_filesystem;
// Load the WP_Filesystem API if not already loaded
if (empty($wp_filesystem)) {
require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();
}

$wp_filesystem->put_contents($cache_queue_path, wp_json_encode($wpocf_cache_queue), FS_CHMOD_FILE);

$this->unlock_cache_purge_queue();
}
Expand Down Expand Up @@ -1608,15 +1616,15 @@ function purge_cache_queue_job()

$this->lock_cache_purge_queue();

$wpocf_cache_queue = json_decode(file_get_contents($cache_queue_path), true);
$wpocf_cache_queue = json_decode(wp_remote_get($cache_queue_path), true);

if (isset($wpocf_cache_queue['purge_all']) && $wpocf_cache_queue['purge_all']) {
$this->purge_all(false, false);
} else if (isset($wpocf_cache_queue['urls']) && is_array($wpocf_cache_queue['urls']) && count($wpocf_cache_queue['urls']) > 0) {
$this->purge_urls($wpocf_cache_queue['urls'], false);
}

@unlink($cache_queue_path);
@wp_delete_file($cache_queue_path);

$this->unlock_cache_purge_queue();

Expand Down

0 comments on commit 9a8afea

Please sign in to comment.