Action
uncanny-automator
litespeed_purge_all
Fires when LiteSpeed Cache purges all cached content.
add_action( 'litespeed_purge_all', $callback, 10, 1 );
Description
Fires after all LiteSpeed Cache data, including page cache, CSS/JS, object cache, OPcache, and image caches, has been purged. Developers can hook into this action to perform custom cleanup or integrate with other caching mechanisms after LiteSpeed's purge process is complete.
Usage
add_action( 'litespeed_purge_all', 'your_function_name', 10, 1 );
Examples
// Example function to purge all LiteSpeed caches and optionally log the action.
function my_custom_litespeed_purge_all_handler() {
// Perform the actual cache purging using LiteSpeed Cache's internal functions.
// This is a hypothetical example; actual functions might vary.
if ( function_exists( 'LiteSpeed_Cache_Admin_Display::purger_init' ) ) {
LiteSpeed_Cache_Admin_Display::purger_init( 'all' );
} elseif ( class_exists( 'LiteSpeed_Cache' ) && method_exists( LiteSpeed_Cache::get_instance(), 'clear_all_cache' ) ) {
LiteSpeed_Cache::get_instance()->clear_all_cache();
}
// Optional: Log that all caches were purged.
// This could be written to a custom log file or WordPress debug log.
error_log( 'All LiteSpeed caches purged by custom handler.' );
// You could also add additional logic here, like invalidating external cache services
// or triggering other related actions.
}
// Add the custom handler to the litespeed_purge_all action hook.
// We use a priority of 10 (default) and 0 accepted arguments, as the hook itself doesn't pass any.
add_action( 'litespeed_purge_all', 'my_custom_litespeed_purge_all_handler', 10, 0 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/litespeed-cache/helpers/litespeed-cache-helpers.php:21
public function purge_all_caches() {
do_action( 'litespeed_purge_all' );
}