purge problem
-
i have set not to purge cache on plugin updates but many plugins still force purge un updates (like elementor) , can it be suppressed?
-
i want only manual purge
@edmundspriede have you look into other settings from here: https://docs.litespeedtech.com/lscache/lscwp/cache/#purge-tab ?
-
This reply was modified 3 weeks, 2 days ago by
litetim.
it is off on all my sites but still happens
@edmundspriede other settings are done so purges should not happen, yes?
@edmundspriede how did you updated the plugin? Did you uploaded a package and click install?
may be both, but it definitely purges after elementor updates and then i discovered
/thirdparty directory which overrides purge settings.
so in my case i would still need hard purge disable.@edmundspriede
OK let’s backtrack a little bit.
Purge All On Upgrade purge is the setting that will stop purge on any plugins update. Please confirm that is working as expected even with module uploaded from computer.
Elementor purge: that is expected behaviour because in most cases that is needed. Let’s test a small change to code and see if this stops the clear: https://github.com/litespeedtech/lscache_wp/blob/master/thirdparty/elementor.cls.php#L70 add a comment to this line pls and see what happens.We can adjust the behaviour in some ways, but not many requests came for this behaviour. Let’s see what are results after the test and I can talk to devs.
Thank you-
This reply was modified 2 weeks, 6 days ago by
litetim.
Hi, I investigated this on my site and found that the purge is not being triggered by the normal LiteSpeed “Purge All Hooks” setting, but by the Elementor integration inside LiteSpeed.
In my purge log, the chain is consistently:
wp_version_check–wp_maybe_auto_update–upgrader_process_complete–elementor/core/files/clear_cache–litespeed_purge_all.
The key point is that Elementor hooksupgrader_process_completeand then calls its ownclear_cache()logic when that hook fires.What seems wrong is that Elementor does not appear to check whether an actual update really happened; it reacts to the fact that
upgrader_process_completefired, and that is enough to triggerelementor/core/files/clear_cache.After that, LiteSpeed’s Elementor integration catches the Elementor cache-clear event and runs a full purge. In my logs, the callback comes from
wp-content/plugins/litespeed-cache/thirdparty/elementor.cls.php, and the payload isElementor - Regenerate CSS & Data.So the root problem does not seem to be the crawler, TTL, or the standard purge settings. The actual trigger is:
upgrader_process_completefires, Elementor clears its cache, and LiteSpeed translates that intopurge_all.
I also found Elementor issue #33057, which reports that Elementor deletes CSS files daily, and there are duplicate reports linked to the same behavior. That seems closely related to what is happening here. (https://github.com/elementor/elementor/issues/33057)In short: the issue is not simply “a purge happens after a real update,” but rather that Elementor seems to react to
upgrader_process_completetoo broadly, even in cases where no meaningful update appears to have taken place, and LiteSpeed then amplifies that into a full cache purge.
My mu-plugin’s output:{"time_local":"2026-05-21 07:06:10","event":"litespeed_purge_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purge_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":["Elementor - Regenerate CSS & Data"],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/thirdparty/elementor.cls.php:92 | #6 LiteSpeed\\Thirdparty\\Elementor::regenerate_litespeed_cache wp-includes/class-wp-hook.php:341 | #7 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #8 WP_Hook->do_action wp-includes/plugin.php:522 | #9 do_action wp-content/plugins/elementor/core/files/manager.php:130"}
{"time_local":"2026-05-21 07:06:10","event":"filter:litespeed_purge_tags","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purge_tags","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purge_tags"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":{"is_private":0,"tags":["*"]}}
{"time_local":"2026-05-21 07:06:10","event":"litespeed_purged_all_lscache","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_lscache","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_lscache"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:267 | #6 LiteSpeed\\Purge->_purge_all_lscache wp-content/plugins/litespeed-cache/src/purge.cls.php:220 | #7 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #8 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #9 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365"}
{"time_local":"2026-05-21 07:06:10","event":"filter:litespeed_purge_tags","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purge_tags","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purge_tags"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":{"is_private":0,"tags":["*","_LOCALRES"]}}
{"time_local":"2026-05-21 07:06:10","event":"litespeed_purged_all_object","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_object","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_object"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""]}
{"time_local":"2026-05-21 07:06:10","event":"litespeed_purged_all_opcache","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_opcache","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_opcache"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""]}
{"time_local":"2026-05-21 07:06:10","event":"litespeed_purged_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:239 | #6 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #7 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #8 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #9 WP_Hook->do_action wp-includes/plugin.php:522"}
{"time_local":"2026-05-21 07:06:11","event":"litespeed_purge_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purge_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":["Elementor - Regenerate CSS & Data"],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/thirdparty/elementor.cls.php:92 | #6 LiteSpeed\\Thirdparty\\Elementor::regenerate_litespeed_cache wp-includes/class-wp-hook.php:341 | #7 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #8 WP_Hook->do_action wp-includes/plugin.php:522 | #9 do_action wp-content/plugins/elementor/core/files/manager.php:130"}
{"time_local":"2026-05-21 07:06:11","event":"litespeed_purged_all_lscache","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_lscache","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_lscache"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:267 | #6 LiteSpeed\\Purge->_purge_all_lscache wp-content/plugins/litespeed-cache/src/purge.cls.php:220 | #7 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #8 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #9 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365"}
{"time_local":"2026-05-21 07:06:11","event":"litespeed_purged_all_object","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_object","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_object"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""]}
{"time_local":"2026-05-21 07:06:11","event":"litespeed_purged_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:239 | #6 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #7 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #8 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #9 WP_Hook->do_action wp-includes/plugin.php:522"}
{"time_local":"2026-05-21 07:06:13","event":"litespeed_purge_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purge_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":["Elementor - Regenerate CSS & Data"],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/thirdparty/elementor.cls.php:92 | #6 LiteSpeed\\Thirdparty\\Elementor::regenerate_litespeed_cache wp-includes/class-wp-hook.php:341 | #7 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #8 WP_Hook->do_action wp-includes/plugin.php:522 | #9 do_action wp-content/plugins/elementor/core/files/manager.php:130"}
{"time_local":"2026-05-21 07:06:13","event":"litespeed_purged_all_lscache","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_lscache","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_lscache"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:267 | #6 LiteSpeed\\Purge->_purge_all_lscache wp-content/plugins/litespeed-cache/src/purge.cls.php:220 | #7 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #8 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #9 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365"}
{"time_local":"2026-05-21 07:06:13","event":"litespeed_purged_all_object","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all_object","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all_object"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""]}
{"time_local":"2026-05-21 07:06:13","event":"litespeed_purged_all","request_uri":"/wp-cron.php?doing_wp_cron","method":"GET","referer":"","remote_addr":"127.0.0.1","doing_ajax":0,"doing_cron":1,"doing_rest":0,"is_admin":0,"current_filter":"litespeed_purged_all","filter_stack":["wp_version_check","wp_maybe_auto_update","upgrader_process_complete","elementor/core/files/clear_cache","litespeed_purge_all","litespeed_purged_all"],"query_action":"","query_lscwp_ctrl":"","user_id":0,"payload":[""],"backtrace":"#0 lscpl_backtrace_summary wp-content/mu-plugins/litespeed-purge-log.php:239 | #1 lscpl_write_log wp-content/mu-plugins/litespeed-purge-log.php:260 | #2 lscpl_log_generic wp-includes/class-wp-hook.php:341 | #3 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #4 WP_Hook->do_action wp-includes/plugin.php:522 | #5 do_action wp-content/plugins/litespeed-cache/src/purge.cls.php:239 | #6 LiteSpeed\\Purge->_purge_all wp-content/plugins/litespeed-cache/src/purge.cls.php:209 | #7 LiteSpeed\\Purge::purge_all wp-includes/class-wp-hook.php:341 | #8 WP_Hook->apply_filters wp-includes/class-wp-hook.php:365 | #9 WP_Hook->do_action wp-includes/plugin.php:522"}but there shoud just be shortcircut to disable all auto purges. or i just have to kill it in code.
@estalhun
I will go with your findings. We added the purge in Elementor so we refresh CSS/JS changes that happen on page edits.
I think this purges must be discussed with Elementor team.
@edmundspriede We keep in mind the request to stop automatically purge(from plugins, theme or WP) but, for now, nothing concrete here.-
This reply was modified 2 weeks, 3 days ago by
litetim.
Dear @edmundspriede
Until a better solution is found, I’ve added this line as a comment:
// add_action( 'elementor/core/files/clear_cache', __CLASS__ . '::regenerate_litespeed_cache' );https://github.com/elementor/elementor/issues/35983
-
This reply was modified 2 weeks, 3 days ago by
estalhun.
but it still happens also on other plugins activate/deactivate. so i want to be sure i am not left with purged cache as ir takes long time to build. one time i just commented you purge all code, but it is not ideal.
@edmundspriede I am willing to look into and try to debug the clear.
I looked for a hooks/actions that trigger on any plugin activate/deactivate.
Please check purge logs too, it might give you more details of why is happening.
As for the purge stop, we will add a change that will help your case(disable purges from functions).
Thank youI reported the issue to the Elementor developers: https://github.com/elementor/elementor/issues/35983
Incidentally, there is a similar issue with the LiteSpeed Cache plugin, and the solution is similar.
In the /litespeed-cache/src/core.cls.php file, on line 106, the “upgrader_process_complete” hook is being monitored.
Unfortunately, this hook is called even when no actual update has taken place, but only when checking to see if an update is available.To modify this behavior, here is a code snippet that only performs a full cache flush if an update has actually occurred.
Developers, please check whether these code changes are usable (since I am not a very experienced PHP developer).
<?php
/**
* The core plugin class.
*
* This is the main class for the LiteSpeed Cache plugin, responsible for initializing
* the plugin's core functionality, registering hooks, and handling cache-related operations.
*
* Note: Core doesn't allow $this->cls( 'Core' )
*
* @since 1.0.0
* @package LiteSpeed
*/
namespace LiteSpeed;
defined( 'WPINC' ) || exit();
/**
* Class Core
*
* @since 1.0.0
*/
class Core extends Root {
const NAME = 'LiteSpeed Cache';
const PLUGIN_NAME = 'litespeed-cache';
const PLUGIN_FILE = 'litespeed-cache/litespeed-cache.php';
const VER = LSCWP_V;
const ACTION_DISMISS = 'dismiss';
const ACTION_PURGE_BY = 'PURGE_BY';
const ACTION_PURGE_EMPTYCACHE = 'PURGE_EMPTYCACHE';
const ACTION_QS_PURGE = 'PURGE';
const ACTION_QS_PURGE_SINGLE = 'PURGESINGLE'; // This will be same asACTION_QS_PURGE(purge single URL only)
const ACTION_QS_SHOW_HEADERS = 'SHOWHEADERS';
const ACTION_QS_PURGE_ALL = 'purge_all';
const ACTION_QS_PURGE_EMPTYCACHE = 'empty_all';
const ACTION_QS_NOCACHE = 'NOCACHE';
const HEADER_DEBUG = 'X-LiteSpeed-Debug';
/**
* Whether to show debug headers.
*
* @var bool
* @since 1.0.0
*/
protected static $debug_show_header = false;
/**
* Footer comment buffer.
*
* @var string
* @since 1.0.0
*/
private $footer_comment = '';
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
! defined( 'LSCWP_TS_0' ) && define( 'LSCWP_TS_0', microtime( true ) );
$this->cls( 'Conf' )->init();
/**
* Load API hooks
*
* @since 3.0
*/
$this->cls( 'API' )->init();
if ( defined( 'LITESPEED_ON' ) ) {
// Load third party detection if lscache enabled.
include_once LSCWP_DIR . 'thirdparty/entry.inc.php';
}
if ( $this->conf( Base::O_DEBUG_DISABLE_ALL ) || Debug2::is_tmp_disable() ) {
! defined( 'LITESPEED_DISABLE_ALL' ) && define( 'LITESPEED_DISABLE_ALL', true );
}
/**
* Register plugin activate/deactivate/uninstall hooks
* NOTE: this can't be moved under after_setup_theme, otherwise activation will be bypassed
*
* @since 2.7.1 Disabled admin&CLI check to make frontend able to enable cache too
*/
$plugin_file = LSCWP_DIR . 'litespeed-cache.php';
register_activation_hook( $plugin_file, [ __NAMESPACE__ . '\Activation', 'register_activation' ] );
register_deactivation_hook( $plugin_file, [ __NAMESPACE__ . '\Activation', 'register_deactivation' ] );
register_uninstall_hook( $plugin_file, __NAMESPACE__ . '\Activation::uninstall_litespeed_cache' );
if ( defined( 'LITESPEED_ON' ) ) {
// Register purge_all actions
$purge_all_events = $this->conf( Base::O_PURGE_HOOK_ALL );
// Purge all on upgrade
if ( $this->conf( Base::O_PURGE_ON_UPGRADE ) ) {
$purge_all_events[] = 'automatic_updates_complete';
$purge_all_events[] = 'admin_action_do-plugin-upgrade';
// ↓ MODIFIED: 'upgrader_process_complete' has been removed from the array;
// instead, we register it below using a dedicated wrapper with two parameters.
add_action( 'upgrader_process_complete', [ $this, 'purge_all_on_upgrade' ], 10, 2 );
}
foreach ( $purge_all_events as $event ) {
// Don't allow hook to update_option because purge_all will cause infinite loop of update_option
if ( in_array( $event, [ 'update_option' ], true ) ) {
continue;
}
add_action( $event, __NAMESPACE__ . '\Purge::purge_all' );
}
// Add headers to site health check for full page cache
// @since 5.4
add_filter( 'site_status_page_cache_supported_cache_headers', function ( $cache_headers ) {
$is_cache_hit = function ( $header_value ) {
return false !== strpos( strtolower( $header_value ), 'hit' );
};
$cache_headers['x-litespeed-cache'] = $is_cache_hit;
$cache_headers['x-lsadc-cache'] = $is_cache_hit;
$cache_headers['x-qc-cache'] = $is_cache_hit;
return $cache_headers;
} );
}
add_action( 'after_setup_theme', [ $this, 'init' ] );
// Check if there is a purge request in queue
if ( ! defined( 'LITESPEED_CLI' ) ) {
$purge_queue = Purge::get_option( Purge::DB_QUEUE );
if ( $purge_queue && '-1' !== $purge_queue ) {
$this->http_header( $purge_queue );
Debug2::debug( '[Core] Purge Queue found&sent: ' . $purge_queue );
}
if ( '-1' !== $purge_queue ) {
Purge::update_option( Purge::DB_QUEUE, '-1' ); // Use -1 to bypass purge while still enable db update as WP's update_option will check value===false to bypass update
}
$purge_queue = Purge::get_option( Purge::DB_QUEUE2 );
if ( $purge_queue && '-1' !== $purge_queue ) {
$this->http_header( $purge_queue );
Debug2::debug( '[Core] Purge2 Queue found&sent: ' . $purge_queue );
}
if ( '-1' !== $purge_queue ) {
Purge::update_option( Purge::DB_QUEUE2, '-1' );
}
}
/**
* Hook internal REST
*
* @since 2.9.4
*/
$this->cls( 'REST' );
/**
* Hook wpnonce function
*
* Note: ESI nonce won't be available until hook after_setup_theme ESI init due to Guest Mode concern
*
* @since 4.1
*/
if ( $this->cls( 'Router' )->esi_enabled() && ! function_exists( 'wp_create_nonce' ) ) {
Debug2::debug( '[ESI] Overwrite wp_create_nonce()' );
litespeed_define_nonce_func();
}
}
/**
* Conditionally purges the full cache after an upgrade process.
*
* Theupgrader_process_completehook fires for every WP_Upgrader run,
* including automatic background update *checks* that complete without
* actually installing anything (e.g. wp_version_check → wp_maybe_auto_update).
* In those cases $hook_extra is either empty or lacks a valid action/type,
* so we must guard against them before calling Purge::purge_all().
*
* @since 1.0.0 (hardened)
*
* @param \WP_Upgrader $upgrader The upgrader instance.
* @param array $hook_extra {
* Extra information about the upgrade.
*
* @type string $action 'install' | 'update'
* @type string $type 'plugin' | 'theme' | 'core' | 'translation'
* @type array $plugins Plugin file paths (bulk plugin update).
* @type string $plugin Plugin file path (single plugin update/install).
* @type array $themes Theme slugs (bulk theme update).
* @type string $theme Theme slug (single theme update/install).
* @type bool $bulk Whether this is a bulk upgrade.
* }
*/
public function purge_all_on_upgrade( $upgrader, $hook_extra ) {
// Empty or non-array $hook_extra means no real upgrade took place.
if ( empty( $hook_extra ) || ! is_array( $hook_extra ) ) {
Debug2::debug( '[Core] upgrader_process_complete: skip purge – hook_extra empty' );
return;
}
$action = isset( $hook_extra['action'] ) ? $hook_extra['action'] : '';
$type = isset( $hook_extra['type'] ) ? $hook_extra['type'] : '';
// Only react to real installs or updates of recognised asset types.
$valid_actions = [ 'install', 'update' ];
$valid_types = [ 'plugin', 'theme', 'core', 'translation' ];
if ( ! in_array( $action, $valid_actions, true ) || ! in_array( $type, $valid_types, true ) ) {
Debug2::debug( "[Core] upgrader_process_complete: skip purge – action={$action} type={$type}" );
return;
}
// For plugin upgrades verify that at least one plugin file is listed.
if ( 'plugin' === $type ) {
$plugins = isset( $hook_extra['plugins'] ) ? $hook_extra['plugins'] : [];
$plugin = isset( $hook_extra['plugin'] ) ? $hook_extra['plugin'] : '';
if ( empty( $plugins ) && empty( $plugin ) ) {
Debug2::debug( '[Core] upgrader_process_complete: skip purge – plugin list empty' );
return;
}
}
// For theme upgrades verify that at least one theme slug is listed.
if ( 'theme' === $type ) {
$themes = isset( $hook_extra['themes'] ) ? $hook_extra['themes'] : [];
$theme = isset( $hook_extra['theme'] ) ? $hook_extra['theme'] : '';
if ( empty( $themes ) && empty( $theme ) ) {
Debug2::debug( '[Core] upgrader_process_complete: skip purge – theme list empty' );
return;
}
}
Debug2::debug( "[Core] upgrader_process_complete: purge_all triggered – action={$action} type={$type}" );
Purge::purge_all();
}
/**
* The plugin initializer.
*
* This function checks if the cache is enabled and ready to use, then determines what actions need to be set up based on the type of user and page accessed. Output is buffered if the cache is enabled.
*
* NOTE: WP user doesn't init yet
*
* @since 1.0.0
*/
public function init() {
/**
* Added hook before init
* 3rd party preload hooks will be fired here too (e.g. Divi disable all in edit mode)
*
* @since 1.6.6
* @since 2.6 Added filter to all config values in Conf
*/
do_action( 'litespeed_init' );
add_action( 'wp_ajax_async_litespeed', 'LiteSpeed\Task::async_litespeed_handler' );
add_action( 'wp_ajax_nopriv_async_litespeed', 'LiteSpeed\Task::async_litespeed_handler' );
// Inafter_setup_theme, beforeinithook
$this->cls( 'Activation' )->auto_update();
if ( is_admin() && ! wp_doing_ajax() ) {
$this->cls( 'Admin' );
}
if ( defined( 'LITESPEED_DISABLE_ALL' ) && LITESPEED_DISABLE_ALL ) {
Debug2::debug( '[Core] Bypassed due to debug disable all setting' );
return;
}
do_action( 'litespeed_initing' );
ob_start( [ $this, 'send_headers_force' ] );
add_action( 'shutdown', [ $this, 'send_headers' ], 0 );
add_action( 'wp_footer', [ $this, 'footer_hook' ] );
/**
* Check if is non-optimization simulator
*
* @since 2.9
*/
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( ! empty( $_GET[ Router::ACTION ] ) && 'before_optm' === $_GET[ Router::ACTION ] && ! apply_filters( 'litespeed_qs_forbidden', false ) ) {
Debug2::debug( '[Core] ⛑️ bypass_optm due to QS CTRL' );
! defined( 'LITESPEED_NO_OPTM' ) && define( 'LITESPEED_NO_OPTM', true );
}
/**
* Register vary filter
*
* @since 1.6.2
*/
$this->cls( 'Control' )->init();
// Init Purge hooks
$this->cls( 'Purge' )->init();
$this->cls( 'Tag' )->init();
// Load hooks that may be related to users
add_action( 'init', [ $this, 'after_user_init' ], 5 );
// Load 3rd party hooks
add_action( 'wp_loaded', [ $this, 'load_thirdparty' ], 2 );
}
/**
* Run hooks after user init
*
* @since 2.9.8
*/
public function after_user_init() {
$this->cls( 'Router' )->is_role_simulation();
// Detect if is Guest mode or not
$this->cls( 'Vary' )->after_user_init();
// Register attachment delete hook
$this->cls( 'Media' )->after_user_init();
/**
* Preload ESI functionality for ESI request URI recovery
*
* @since 1.8.1
* @since 4.0 ESI init needs to be after Guest mode detection to bypass ESI if is under Guest mode
*/
$this->cls( 'ESI' )->init();
if ( ! is_admin() && ! defined( 'LITESPEED_GUEST_OPTM' ) ) {
$result = $this->cls( 'Conf' )->in_optm_exc_roles();
if ( $result ) {
Debug2::debug( '[Core] ⛑️ bypass_optm: hit Role Excludes setting: ' . $result );
! defined( 'LITESPEED_NO_OPTM' ) && define( 'LITESPEED_NO_OPTM', true );
}
}
// Heartbeat control
$this->cls( 'Tool' )->heartbeat();
if ( ! defined( 'LITESPEED_NO_OPTM' ) || ! LITESPEED_NO_OPTM ) {
// Check missing static files
$this->cls( 'Router' )->serve_static();
$this->cls( 'Media' )->init();
$this->cls( 'Placeholder' )->init();
$this->cls( 'Router' )->can_optm() && $this->cls( 'Optimize' )->init();
$this->cls( 'Localization' )->init();
// Hook CDN for attachments
$this->cls( 'CDN' )->init();
// Load cron tasks
$this->cls( 'Task' )->init();
}
// Load litespeed actions
$action = Router::get_action();
if ( $action ) {
$this->proceed_action( $action );
}
// Load frontend GUI
if ( ! is_admin() ) {
$this->cls( 'GUI' )->init();
}
}
/**
* Run frontend actions
*
* @since 1.1.0
* @param string $action The action to proceed.
*/
public function proceed_action( $action ) {
$msg = false;
// Handle actions
switch ( $action ) {
case self::ACTION_QS_SHOW_HEADERS:
self::$debug_show_header = true;
break;
case self::ACTION_QS_PURGE:
case self::ACTION_QS_PURGE_SINGLE:
Purge::set_purge_single();
break;
case self::ACTION_QS_PURGE_ALL:
Purge::purge_all();
break;
case self::ACTION_PURGE_EMPTYCACHE:
case self::ACTION_QS_PURGE_EMPTYCACHE:
define( 'LSWCP_EMPTYCACHE', true ); // Clear all sites caches
Purge::purge_all();
$msg = __( 'Notified LiteSpeed Web Server to purge everything.', 'litespeed-cache' );
break;
case self::ACTION_PURGE_BY:
$this->cls( 'Purge' )->purge_list();
$msg = __( 'Notified LiteSpeed Web Server to purge the list.', 'litespeed-cache' );
break;
case self::ACTION_DISMISS:
GUI::dismiss();
break;
default:
$msg = $this->cls( 'Router' )->handler( $action );
break;
}
if ( $msg && ! Router::is_ajax() ) {
Admin_Display::add_notice( Admin_Display::NOTICE_GREEN, $msg );
Admin::redirect();
return;
}
if ( Router::is_ajax() ) {
exit();
}
}
/**
* Callback used to call the detect third party action.
*
* The detect action is used by third party plugin integration classes to determine if they should add the rest of their hooks.
*
* @since 1.0.5
*/
public function load_thirdparty() {
do_action( 'litespeed_load_thirdparty' );
}
/**
* Mark wp_footer called
*
* @since 1.3
*/
public function footer_hook() {
Debug2::debug( '[Core] Footer hook called' );
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
define( 'LITESPEED_FOOTER_CALLED', true );
}
}
/**
* Trigger comment info display hook
*
* @since 1.3
* @param string|null $buffer The buffer to check.
* @return void
*/
private function check_is_html( $buffer = null ) {
if ( ! defined( 'LITESPEED_FOOTER_CALLED' ) ) {
Debug2::debug2( '[Core] CHK html bypass: miss footer const' );
return;
}
if ( wp_doing_ajax() ) {
Debug2::debug2( '[Core] CHK html bypass: doing ajax' );
return;
}
if ( wp_doing_cron() ) {
Debug2::debug2( '[Core] CHK html bypass: doing cron' );
return;
}
if ( empty( $_SERVER['REQUEST_METHOD'] ) || 'GET' !== $_SERVER['REQUEST_METHOD'] ) {
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
Debug2::debug2( '[Core] CHK html bypass: not get method ' . wp_unslash( $_SERVER['REQUEST_METHOD'] ) );
return;
}
if ( null === $buffer ) {
$buffer = ob_get_contents();
}
// Double check to make sure it is an HTML file
if ( strlen( $buffer ) > 300 ) {
$buffer = substr( $buffer, 0, 300 );
}
if ( false !== strstr( $buffer, '<!--' ) ) {
$buffer = preg_replace( '/<!--.*?-->/s', '', $buffer );
}
$buffer = trim( $buffer );
$buffer = File::remove_zero_space( $buffer );
$is_html = 0 === stripos( $buffer, '<html' ) || 0 === stripos( $buffer, '<!DOCTYPE' );
if ( ! $is_html ) {
Debug2::debug( '[Core] Footer check failed: ' . ob_get_level() . '-' . substr( $buffer, 0, 100 ) );
return;
}
Debug2::debug( '[Core] Footer check passed' );
if ( ! defined( 'LITESPEED_IS_HTML' ) ) {
define( 'LITESPEED_IS_HTML', true );
}
}
/**
* For compatibility with plugins that have 'Bad' logic that forced all buffer output even if it is NOT their buffer.
*
* Usually this is called after send_headers() if following original WP process
*
* @since 1.1.5
* @param string $buffer The buffer to process.
* @return string The processed buffer.
*/
public function send_headers_force( $buffer ) {
$this->check_is_html( $buffer );
// Hook to modify buffer before
$buffer = apply_filters( 'litespeed_buffer_before', $buffer );
/**
* Media: Image lazyload && WebP
* GUI: Clean wrapper mainly for ESI block NOTE: this needs to be before optimizer to avoid wrapper being removed
* Optimize
* CDN
*/
if ( ! defined( 'LITESPEED_NO_OPTM' ) || ! LITESPEED_NO_OPTM ) {
Debug2::debug( '[Core] run hook litespeed_buffer_finalize' );
$buffer = apply_filters( 'litespeed_buffer_finalize', $buffer );
}
/**
* Replace ESI preserved list
*
* @since 3.3 Replace this in the end to avoidInline JS Deferor other Page Optm features encoded ESI tags wrongly, which caused LSWS can't recognize ESI
*/
$buffer = $this->cls( 'ESI' )->finalize( $buffer );
$this->send_headers( true );
// Log ESI nonce buffer empty issue
if ( defined( 'LSCACHE_IS_ESI' ) && 0 === strlen( $buffer ) && ! empty( $_SERVER['REQUEST_URI'] ) ) {
// Log ref for debug purpose
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.PHP.DevelopmentFunctions.error_log_error_log
error_log( 'ESI buffer empty ' . wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
// Init comment info
$running_info_showing = defined( 'LITESPEED_IS_HTML' ) || defined( 'LSCACHE_IS_ESI' );
if ( defined( 'LSCACHE_ESI_SILENCE' ) ) {
$running_info_showing = false;
Debug2::debug( '[Core] ESI silence' );
}
/**
* Silence comment for JSON request
*
* @since 2.9.3
*/
if ( REST::cls()->is_rest() || Router::is_ajax() ) {
$running_info_showing = false;
Debug2::debug( '[Core] Silence Comment due to REST/AJAX' );
}
$running_info_showing = apply_filters( 'litespeed_comment', $running_info_showing );
if ( $running_info_showing && $this->footer_comment ) {
$buffer .= $this->footer_comment;
}
/**
* If ESI request is JSON, give the content JSON format
*
* @since 2.9.3
* @since 2.9.4 ESI request could be from internal REST call, so moved json_encode out of this condition
*/
if ( defined( 'LSCACHE_IS_ESI' ) ) {
Debug2::debug( '[Core] ESI Start 👇' );
if ( strlen( $buffer ) > 500 ) {
Debug2::debug( trim( substr( $buffer, 0, 500 ) ) . '.....' );
} else {
Debug2::debug( $buffer );
}
Debug2::debug( '[Core] ESI End 👆' );
}
if ( apply_filters( 'litespeed_is_json', false ) ) {
if ( null === \json_decode( $buffer, true ) ) {
Debug2::debug( '[Core] Buffer converting to JSON' );
$buffer = wp_json_encode( $buffer );
$buffer = trim( $buffer, '"' );
} else {
Debug2::debug( '[Core] JSON Buffer' );
}
}
// Hook to modify buffer after
$buffer = apply_filters( 'litespeed_buffer_after', $buffer );
Debug2::ended();
return $buffer;
}
/**
* Sends the headers out at the end of processing the request.
*
* This will send out all LiteSpeed Cache related response headers needed for the post.
*
* @since 1.0.5
* @param bool $is_forced If the header is sent following our normal finalizing logic.
*/
public function send_headers( $is_forced = false ) {
// Make sure header output only runs once
if ( defined( 'LITESPEED_DID_' . __FUNCTION__ ) ) {
return;
}
define( 'LITESPEED_DID_' . __FUNCTION__, true );
// Avoid PHP warning for headers sent out already
if ( headers_sent() ) {
self::debug( '❌ !!! Err: Header sent out already' );
return;
}
$this->check_is_html();
// Cache control output needs to be done first, as some varies are added in 3rd party hooklitespeed_api_control.
$this->cls( 'Control' )->finalize();
$vary_header = $this->cls( 'Vary' )->finalize();
// If not cacheable but Admin QS ispurgeorpurgesingle,tagstill needs to be generated
$tag_header = $this->cls( 'Tag' )->output();
if ( ! $tag_header && Control::is_cacheable() ) {
Control::set_nocache( 'empty tag header' );
}
//Purgeoutput needs to be aftertagoutput as Admin QS may need to sendtagheader
$purge_header = Purge::output();
// Generatecontrolheader in the end in case control status is changed by other headers
$control_header = $this->cls( 'Control' )->output();
// Give one more break to avoid Firefox crash
if ( ! defined( 'LSCACHE_IS_ESI' ) ) {
$this->footer_comment .= "\n";
}
$cache_support = 'supported';
if ( defined( 'LITESPEED_ON' ) ) {
$cache_support = Control::is_cacheable() ? 'cached' : 'uncached';
}
$this->comment(
sprintf(
'%1$s %2$s by LiteSpeed Cache %4$s on %3$s',
defined( 'LSCACHE_IS_ESI' ) ? 'Block' : 'Page',
$cache_support,
gmdate( 'Y-m-d H:i:s', time() + LITESPEED_TIME_OFFSET ),
self::VER
)
);
// Send Control header
if ( defined( 'LITESPEED_ON' ) && $control_header ) {
$this->http_header( $control_header );
if ( ! Control::is_cacheable() && !is_admin() ) {
$ori_wp_header = wp_get_nocache_headers();
if ( isset( $ori_wp_header['Cache-Control'] ) ) {
$this->http_header( 'Cache-Control: ' . $ori_wp_header['Cache-Control'] );
}
}
if ( defined( 'LSCWP_LOG' ) ) {
$this->comment( $control_header );
}
}
// Send PURGE header (Always send regardless of cache setting disabled/enabled)
if ( defined( 'LITESPEED_ON' ) && $purge_header ) {
$this->http_header( $purge_header );
Debug2::log_purge( $purge_header );
if ( defined( 'LSCWP_LOG' ) ) {
$this->comment( $purge_header );
}
}
// Send Vary header
if ( defined( 'LITESPEED_ON' ) && $vary_header ) {
$this->http_header( $vary_header );
if ( defined( 'LSCWP_LOG' ) ) {
$this->comment( $vary_header );
}
}
if ( defined( 'LITESPEED_ON' ) && defined( 'LSCWP_LOG' ) ) {
$vary = $this->cls( 'Vary' )->finalize_full_varies();
if ( $vary ) {
$this->comment( 'Full varies: ' . $vary );
}
}
// Admin QS show header action
if ( self::$debug_show_header ) {
$debug_header = self::HEADER_DEBUG . ': ';
if ( $control_header ) {
$debug_header .= $control_header . '; ';
}
if ( $purge_header ) {
$debug_header .= $purge_header . '; ';
}
if ( $tag_header ) {
$debug_header .= $tag_header . '; ';
}
if ( $vary_header ) {
$debug_header .= $vary_header . '; ';
}
$this->http_header( $debug_header );
} elseif ( defined( 'LITESPEED_ON' ) && Control::is_cacheable() && $tag_header ) {
$this->http_header( $tag_header );
if ( defined( 'LSCWP_LOG' ) ) {
$this->comment( $tag_header );
}
}
// Object cache comment
if ( defined( 'LSCWP_LOG' ) && defined( 'LSCWP_OBJECT_CACHE' ) && method_exists( 'WP_Object_Cache', 'debug' ) ) {
$this->comment( 'Object Cache ' . \WP_Object_Cache::get_instance()->debug() );
}
if ( defined( 'LITESPEED_GUEST' ) && LITESPEED_GUEST ) {
$this->comment( 'Guest Mode' );
}
if ( ! empty( $this->footer_comment ) ) {
self::debug( "[footer comment]\n" . trim( $this->footer_comment ) );
}
if ( $is_forced ) {
Debug2::debug( '--forced--' );
}
// If CLI and contains Purge Header, issue an HTTP request to Purge
if ( defined( 'LITESPEED_CLI' ) ) {
$purge_queue = Purge::get_option( Purge::DB_QUEUE );
if ( ! $purge_queue || '-1' === $purge_queue ) {
$purge_queue = Purge::get_option( Purge::DB_QUEUE2 );
}
if ( $purge_queue && '-1' !== $purge_queue ) {
self::debug( '[Core] Purge Queue found, issue an HTTP request to purge: ' . $purge_queue );
// Kick off HTTP request
$url = admin_url( 'admin-ajax.php' );
$resp = wp_safe_remote_get( $url );
if ( is_wp_error( $resp ) ) {
$error_message = $resp->get_error_message();
self::debug( '[URL]' . $url );
self::debug( 'failed to request: ' . $error_message );
} else {
self::debug( 'HTTP request response: ' . $resp['body'] );
}
}
}
}
/**
* Append one HTML comment
*
* @since 5.5
* @param string $data The comment data.
*/
public static function comment( $data ) {
self::cls()->append_comment( $data );
}
/**
* Append one HTML comment
*
* @since 5.5
* @param string $data The comment data.
*/
private function append_comment( $data ) {
$this->footer_comment .= "\n<!-- " . htmlspecialchars( $data ) . ' -->';
}
/**
* Send HTTP header
*
* @since 5.3
* @param string $header The header to send.
*/
private function http_header( $header ) {
if ( defined( 'LITESPEED_CLI' ) ) {
return;
}
if ( ! headers_sent() ) {
header( $header );
}
if ( ! defined( 'LSCWP_LOG' ) ) {
return;
}
Debug2::debug( '💰 ' . $header );
}
}@estalhun Thank you for debug and code changes.
Let me talk to the developers and see what changes we can add. -
This reply was modified 3 weeks, 2 days ago by
You must be logged in to reply to this topic.