The deleted_transient WordPress action fires after a transient is deleted.
Usage
add_action('deleted_transient', 'your_function_name');
function your_function_name($transient) {
// Your custom code here
}
Parameters
$transient: string – The deleted transient name.
More information
See WordPress Developer Resources: deleted_transient
Examples
Log Deleted Transient
Log the deleted transient name to a custom log file.
add_action('deleted_transient', 'log_deleted_transient');
function log_deleted_transient($transient) {
error_log("Deleted transient: {$transient}", 3, '/your-custom-path/deleted_transients.log');
}
Send Email Notification
Send an email notification when a specific transient is deleted.
add_action('deleted_transient', 'send_email_on_transient_deletion');
function send_email_on_transient_deletion($transient) {
if ($transient === 'your_transient_name') {
wp_mail('[email protected]', 'Transient Deleted', "The transient {$transient} was deleted.");
}
}
Update Cache
Update a cache entry when a transient is deleted.
add_action('deleted_transient', 'update_cache_on_transient_deletion');
function update_cache_on_transient_deletion($transient) {
wp_cache_delete("cache_key_{$transient}", 'your_cache_group');
}
Custom Action on Transient Deletion
Perform a custom action when a specific transient is deleted.
add_action('deleted_transient', 'custom_action_on_transient_deletion');
function custom_action_on_transient_deletion($transient) {
if ($transient === 'your_transient_name') {
// Your custom code here
}
}
Track Deleted Transients
Track deleted transients and store their names in an option.
add_action('deleted_transient', 'track_deleted_transients');
function track_deleted_transients($transient) {
$deleted_transients = get_option('deleted_transients', []);
$deleted_transients[] = $transient;
update_option('deleted_transients', $deleted_transients);
}