delete_network_option

Removes a network option by name.

Description

delete_network_option( (int) $network_id, (string) $option ); 

Parameters (2)

0. $network_id (int)
ID of the network. Can be null to default to the current network ID.
1. $option (string)
Name of option to remove. Expected to not be SQL-escaped.

Usage

  1. if ( !function_exists( 'delete_network_option' ) ) { 
  2. require_once ABSPATH . WPINC . '/option.php'; 
  3.  
  4. // ID of the network. Can be null to default to the current network ID. 
  5. $network_id = -1; 
  6.  
  7. // Name of option to remove. Expected to not be SQL-escaped. 
  8. $option = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = delete_network_option($network_id, $option); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/option.php  
  1. function delete_network_option( $network_id, $option ) { 
  2. global $wpdb; 
  3.  
  4. if ( $network_id && ! is_numeric( $network_id ) ) { 
  5. return false; 
  6.  
  7. $network_id = (int) $network_id; 
  8.  
  9. // Fallback to the current network if a network ID is not specified. 
  10. if ( ! $network_id ) { 
  11. $network_id = get_current_network_id(); 
  12.  
  13. /** 
  14. * Fires immediately before a specific network option is deleted. 
  15. * The dynamic portion of the hook name, `$option`, refers to the option name. 
  16. * @since 3.0.0 
  17. * @since 4.4.0 The `$option` parameter was added. 
  18. * @since 4.7.0 The `$network_id` parameter was added. 
  19. * @param string $option Option name. 
  20. * @param int $network_id ID of the network. 
  21. */ 
  22. do_action( "pre_delete_site_option_{$option}", $option, $network_id ); 
  23.  
  24. if ( ! is_multisite() ) { 
  25. $result = delete_option( $option ); 
  26. } else { 
  27. $row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) ); 
  28. if ( is_null( $row ) || ! $row->meta_id ) { 
  29. return false; 
  30. $cache_key = "$network_id:$option"; 
  31. wp_cache_delete( $cache_key, 'site-options' ); 
  32.  
  33. $result = $wpdb->delete( $wpdb->sitemeta, array( 'meta_key' => $option, 'site_id' => $network_id ) ); 
  34.  
  35. if ( $result ) { 
  36.  
  37. /** 
  38. * Fires after a specific network option has been deleted. 
  39. * The dynamic portion of the hook name, `$option`, refers to the option name. 
  40. * @since 2.9.0 As "delete_site_option_{$key}" 
  41. * @since 3.0.0 
  42. * @since 4.7.0 The `$network_id` parameter was added. 
  43. * @param string $option Name of the network option. 
  44. * @param int $network_id ID of the network. 
  45. */ 
  46. do_action( "delete_site_option_{$option}", $option, $network_id ); 
  47.  
  48. /** 
  49. * Fires after a network option has been deleted. 
  50. * @since 3.0.0 
  51. * @since 4.7.0 The `$network_id` parameter was added. 
  52. * @param string $option Name of the network option. 
  53. * @param int $network_id ID of the network. 
  54. */ 
  55. do_action( 'delete_site_option', $option, $network_id ); 
  56.  
  57. return true; 
  58.  
  59. return false;