Using WordPress ‘delete_site_transient_{$transient}’ PHP action

The delete_site_transient_{$transient} WordPress PHP action fires immediately before a specific site transient is deleted.

Usage

add_action('delete_site_transient_example_transient', 'my_custom_function');
function my_custom_function() {
    // your custom code here
}

Parameters

  • $transient: string – Transient name.

More information

See WordPress Developer Resources: delete_site_transient_{$transient}

Examples

Log deletion of a site transient

Log when the ‘example_transient’ site transient is deleted.

add_action('delete_site_transient_example_transient', 'log_transient_deletion');
function log_transient_deletion() {
    error_log('The example_transient site transient was deleted.');
}

Invalidate a related cache when the ‘user_stats’ site transient is deleted.

add_action('delete_site_transient_user_stats', 'invalidate_related_cache');
function invalidate_related_cache() {
    wp_cache_delete('user_stats_cache_key');
}

Send email notification on transient deletion

Send an email notification when the ‘critical_data’ site transient is deleted.

add_action('delete_site_transient_critical_data', 'send_email_notification');
function send_email_notification() {
    wp_mail('[email protected]', 'Critical Data Transient Deleted', 'The critical_data site transient has been deleted.');
}

Trigger custom event on transient deletion

Trigger a custom event when the ‘custom_event_transient’ site transient is deleted.

add_action('delete_site_transient_custom_event_transient', 'trigger_custom_event');
function trigger_custom_event() {
    do_action('my_custom_event');
}

Update related data when the ‘related_data_transient’ site transient is deleted.

add_action('delete_site_transient_related_data_transient', 'update_related_data');
function update_related_data() {
    update_option('related_data_option', 'Updated value');
}