Action
uncanny-automator
litespeed_purge_url
Fires when a specific URL is purged from the LiteSpeed Cache.
add_action( 'litespeed_purge_url', $callback, 10, 1 );
Description
Fires after LiteSpeed Cache has been instructed to purge a specific URL. Developers can leverage this action to perform custom actions immediately following a URL purge request, such as logging the purged URL or triggering secondary cache invalidation processes. The `$url` parameter contains the URL that was targeted for purging.
Usage
add_action( 'litespeed_purge_url', 'your_function_name', 10, 1 );
Parameters
-
$url(mixed) - This parameter represents the URL of the content that needs to be purged from the cache.
Examples
/**
* Example of how to hook into the litespeed_purge_url action.
* This function will log the URL being purged by LiteSpeed Cache.
*/
add_action( 'litespeed_purge_url', function( $url ) {
// In a real-world scenario, you might want to:
// 1. Log the URL to a file for debugging purposes.
// 2. Trigger other custom caching mechanisms if you have them.
// 3. Send a notification if a specific URL is being purged.
// For this example, we'll just log it to the WordPress debug log.
if ( WP_DEBUG === true ) {
error_log( 'LiteSpeed Cache purged URL: ' . esc_url( $url ) );
}
}, 10, 1 ); // 10 is the priority, 1 is the number of accepted arguments.
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:32
public function purge_url_cache( $url ) {
do_action( 'litespeed_purge_url', $url );
}