Action
uncanny-automator
litespeed_purge_post
Fires after a post is purged from the LiteSpeed Cache, providing the post ID for custom actions.
add_action( 'litespeed_purge_post', $callback, 10, 1 );
Description
Fires after LiteSpeed Cache for a specific post has been purged. Developers can use this hook to perform custom actions, such as clearing related transients or updating external services, after a post's cache is invalidated. This hook is triggered directly within the LiteSpeed Cache plugin's post cache purging process.
Usage
add_action( 'litespeed_purge_post', 'your_function_name', 10, 1 );
Parameters
-
$post_id(mixed) - This parameter contains the ID of the post whose cache should be purged.
Examples
add_action( 'litespeed_purge_post', 'my_custom_litespeed_post_purge', 10, 1 );
/**
* Example function to handle the litespeed_purge_post action.
* This function might perform additional logging or custom actions
* when a post's LiteSpeed cache is being purged.
*
* @param int $post_id The ID of the post whose cache is being purged.
*/
function my_custom_litespeed_post_purge( $post_id ) {
// Log the cache purge for debugging or monitoring purposes.
if ( is_numeric( $post_id ) && $post_id > 0 ) {
error_log( sprintf( 'LiteSpeed cache purged for post ID: %d', $post_id ) );
// You could also trigger other custom actions here, for example:
// do_action( 'my_plugin_post_cache_purged', $post_id );
// Or update a custom meta field on the post to track purge events.
// update_post_meta( $post_id, '_litespeed_last_purged', time() );
} else {
error_log( 'LiteSpeed cache purge triggered with an invalid post ID.' );
}
}
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:43
public function purge_post_cache( $post_id ) {
do_action( 'litespeed_purge_post', $post_id );
}