wppaste
WordPress

delete_network_option( int|null $network_id, string $option ): bool

Since
4.4.0
Source
wp-includes/option.php:2280
Removes a network option by name.

Compatibility

WordPress
since 4.4.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$network_idint|null
ID of the network. Can be null to default to the current network ID.
$optionstring
Name of the option to delete. Expected to not be SQL-escaped.

Return value

bool
True if the option was deleted, false otherwise.

Performance profile

How much work a call to delete_network_option() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reaches the database via ->get_row().

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
7–84

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 92.

Plugin surface
3 hooks

Third-party callbacks on 'pre_delete_site_option_{$option}', 'delete_site_option_{$option}', 'delete_site_option' run inside this call, and their cost is not bounded by anything here.

Called by
2

2 places in core call this, so the cost is paid more often than your own code shows.

What it touches

  • hookthird-party callbacksdo_action()called directly
  • optionoption read or writedelete_option()called directly
  • cacheobject cachewp_cache_delete()called directly
  • sqldatabase query->get_row()called directly

Further down the call graph this can also reach serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 13 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost delete_network_option() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!$network_id7none
!is_multisite()23–25do_action(), is_multisite(), delete_option()
!is_multisite()26–28get_current_network_id(), do_action(), is_multisite(), delete_option()
is_multisite()32–36do_action(), is_multisite(), ->prepare(), ->get_row()
!is_multisite()34–36do_action(), is_multisite(), delete_option(), do_action(), do_action()
is_multisite()35–39get_current_network_id(), do_action(), is_multisite(), ->prepare(), ->get_row()
!is_multisite()37–39get_current_network_id(), do_action(), is_multisite(), delete_option(), do_action(), do_action()
is_multisite() && $row !== null && $row51–53do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key()
is_multisite() && $row !== null && $row54–56get_current_network_id(), do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key()
is_multisite() && $row !== null && $row67–70do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key(), wp_cache_get(), wp_cache_set()
is_multisite() && $row !== null && $row70–73get_current_network_id(), do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key(), wp_cache_get(), wp_cache_set()
is_multisite() && $row !== null && $row78–81do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key(), wp_cache_get(), wp_cache_set(), do_action(), do_action()
1 further outcome, up to 84 instructions
is_multisite() && $row !== null && $row81–84get_current_network_id(), do_action(), is_multisite(), ->prepare(), ->get_row(), wp_cache_delete(), meta_key(), wp_cache_get(), wp_cache_set(), do_action(), do_action()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev927–849
8.5927–849
8.4927–8492 fewer instructions than PHP 8.3
8.3949–869
8.2949–869
8.1949–869
7.4949–869

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 3

3 hooks fire while delete_network_option() runs, in this order:

  1. do_action( pre_delete_site_option_{$option} )actionline 2306 (+26 into the body)

    Fires immediately before a specific network option is deleted.

  2. do_action( delete_site_option_{$option} )actionline 2352 (+72 into the body)

    Fires after a specific network option has been deleted.

  3. do_action( delete_site_option )actionline 2363 (+83 into the body)

    Fires after a network option has been deleted.

Uses · 7

Used by · 2

Source code

function delete_network_option( $network_id, $option ) {	global $wpdb; 	if ( $network_id && ! is_numeric( $network_id ) ) {		return false;	} 	$network_id = (int) $network_id; 	// Fallback to the current network if a network ID is not specified.	if ( ! $network_id ) {		$network_id = get_current_network_id();	} 	/**	 * Fires immediately before a specific network option is deleted.	 *	 * The dynamic portion of the hook name, `$option`, refers to the option name.	 *	 * @since 3.0.0	 * @since 4.4.0 The `$option` parameter was added.	 * @since 4.7.0 The `$network_id` parameter was added.	 *	 * @param string $option     Option name.	 * @param int    $network_id ID of the network.	 */	do_action( "pre_delete_site_option_{$option}", $option, $network_id ); 	if ( ! is_multisite() ) {		$result = delete_option( $option );	} else {		$row = $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM {$wpdb->sitemeta} WHERE meta_key = %s AND site_id = %d", $option, $network_id ) );		if ( is_null( $row ) || ! $row->meta_id ) {			return false;		}		$cache_key = "$network_id:$option";		wp_cache_delete( $cache_key, 'site-options' ); 		$result = $wpdb->delete(			$wpdb->sitemeta,			array(				'meta_key' => $option,				'site_id'  => $network_id,			)		); 		if ( $result ) {			$notoptions_key = "$network_id:notoptions";			$notoptions     = wp_cache_get( $notoptions_key, 'site-options' ); 			if ( ! is_array( $notoptions ) ) {				$notoptions = array();			}			$notoptions[ $option ] = true;			wp_cache_set( $notoptions_key, $notoptions, 'site-options' );		}	} 	if ( $result ) { 		/**		 * Fires after a specific network option has been deleted.		 *		 * The dynamic portion of the hook name, `$option`, refers to the option name.		 *		 * @since 2.9.0 As "delete_site_option_{$key}"		 * @since 3.0.0		 * @since 4.7.0 The `$network_id` parameter was added.		 *		 * @param string $option     Name of the network option.		 * @param int    $network_id ID of the network.		 */		do_action( "delete_site_option_{$option}", $option, $network_id ); 		/**		 * Fires after a network option has been deleted.		 *		 * @since 3.0.0		 * @since 4.7.0 The `$network_id` parameter was added.		 *

Changelog

Introduced in 4.4.0. One change between 6.7.7 and 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.8.8
Parameter $network_id retyped from int to int|null.verified against source
4.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/option.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.