The delete_site_option_{$option} WordPress PHP action fires after a specific network option has been deleted. The dynamic portion of the hook name, $option
, refers to the option name.
Usage
add_action('delete_site_option_my_option', 'my_custom_function', 10, 2); function my_custom_function($option, $network_id) { // your custom code here }
Parameters
$option
(string) – Name of the network option.$network_id
(int) – ID of the network.
More information
See WordPress Developer Resources: delete_site_option_{$option}
Examples
Log network option deletion
Log when a specific network option is deleted.
add_action('delete_site_option_my_option', 'log_network_option_deletion', 10, 2); function log_network_option_deletion($option, $network_id) { // Log the deletion of the network option error_log("Network option '{$option}' deleted for network ID: {$network_id}"); }
Notify admin of option deletion
Send an email notification to the admin when a specific network option is deleted.
add_action('delete_site_option_my_option', 'notify_admin_network_option_deletion', 10, 2); function notify_admin_network_option_deletion($option, $network_id) { // Compose email content $subject = "Network option '{$option}' deleted"; $message = "The network option '{$option}' has been deleted for network ID: {$network_id}."; // Send email to admin wp_mail(get_option('admin_email'), $subject, $message); }
Update related option on deletion
Update a related network option when a specific network option is deleted.
add_action('delete_site_option_my_option', 'update_related_network_option', 10, 2); function update_related_network_option($option, $network_id) { // Update related network option update_site_option('my_related_option', 'default_value'); }
Perform cleanup on option deletion
Perform some cleanup tasks when a specific network option is deleted.
add_action('delete_site_option_my_option', 'cleanup_on_network_option_deletion', 10, 2); function cleanup_on_network_option_deletion($option, $network_id) { // Perform cleanup tasks }
Invalidate cache on option deletion
Invalidate cache when a specific network option is deleted.
add_action('delete_site_option_my_option', 'invalidate_cache_on_network_option_deletion', 10, 2); function invalidate_cache_on_network_option_deletion($option, $network_id) { // Invalidate cache wp_cache_delete('my_option', 'site-options'); }