Implement warm on edit
-
Currently, although the legend say
On their publication and edit
, the implementation doesn’t trigger the warmer upon edit.public function populate_enqueue( $new_status, $old_status, $post ) {
if ( 'publish' === $new_status ) {
$posts_enqueue = Cache_Warmer::$options->get( 'cache-warmer-posts-enqueue' );
if ( ! in_array( $post->ID, $posts_enqueue, true ) ) {
$posts_enqueue[] = $post->ID;
Cache_Warmer::$options->set( 'cache-warmer-posts-enqueue', $posts_enqueue );
}
}
}Here’s an example of a trigger that does respond to an edit, from the CF page cache plugin:
$purge_actions = array(
'deleted_post', // Delete a post
'wp_trash_post', // Before a post is sent to the Trash
'clean_post_cache', // After a post’s cache is cleaned
'edit_post', // Edit a post - includes leaving comments
'delete_attachment', // Delete an attachment - includes re-uploading
'elementor/editor/after_save', // Elementor edit
'elementor/core/files/clear_cache', // Elementor clear cache
);
foreach ($purge_actions as $action) {
add_action($action, array($this, 'purge_cache_on_post_edit'), PHP_INT_MAX, 2);
}
function purge_cache_on_post_edit($postId)
{
static $done = [];
if (isset($done[$postId])) {
return;
}
// Do not run this on the WordPress Nav Menu Pages
global $pagenow;
if ($pagenow === 'nav-menus.php') return;
if (($this->main_instance->get_single_config('cf_auto_purge', 0) > 0 || $this->main_instance->get_single_config('cf_auto_purge_all', 0) > 0) &&
$this->is_cache_enabled()) {
$current_action = function_exists('current_action') ? current_action() : "";
$this->modules = $this->main_instance->get_modules();
$error = '';
$validPostStatus = ['publish', 'trash', 'private'];
$thisPostStatus = get_post_status($postId);
if (get_permalink($postId) != true || !in_array($thisPostStatus, $validPostStatus)) {
return;
}
if (is_int(wp_is_post_autosave($postId)) || is_int(wp_is_post_revision($postId))) {
return;
}
if ($this->main_instance->get_single_config('cf_auto_purge_all', 0) > 0) {
$this->purge_all();
return;
}
$savedPost = get_post($postId);
if (is_a($savedPost, 'WP_Post') == false) {
return;
}
$urls = $this->get_post_related_links($postId);
$this->purge_urls($urls);
$this->modules['logs']->add_log('cache_controller::purge_cache_on_post_edit', "Purge Cloudflare cache for only post id {$postId} and related contents - Fired action: {$current_action}");
$done[$postId] = true;
}
}
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- You must be logged in to reply to this topic.