wppaste
WordPress

wpmu_delete_blog( int $blog_id, bool $drop = false )

Since
3.0.0, 5.1.0
Source
wp-admin/includes/ms.php:64
Deletes a site.

Compatibility

WordPress
since 5.1.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

$blog_idint
Site ID.
$dropbooloptional
True if site's database tables should be dropped. Default false.Default: false

Performance profile

How much work a call to wpmu_delete_blog() 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_users().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
33–86

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

Plugin surface
2 hooks

Third-party callbacks on 'delete_blog', 'deleted_blog' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • optionoption read or writeget_option()called directly
  • hookthird-party callbacksdo_action_deprecated()called directly
  • querycontent queryget_users()called directly
  • cacheobject cachewp_cache_switch_to_blog()one call below wpmu_delete_blog()
  • serializeserialisationmaybe_unserialize()one call below wpmu_delete_blog()

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

What one call costs · 24 distinct outcomes

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

WhenInstructionsCalls it makes
$blog_id === false33–42get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site()
$blog_id === false35–44get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site(), restore_current_blog()
$blog_id !== false37–46get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site()
$blog_id !== false39–48get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site(), restore_current_blog()
$blog_id === false && $blog_id !== 142–54get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), wp_delete_site()
$blog_id === false && $blog_id !== 144–56get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), wp_delete_site(), restore_current_blog()
$blog_id !== false && $blog_id !== 146–58get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), wp_delete_site()
$blog_id !== false && $blog_id !== 148–60get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), wp_delete_site(), restore_current_blog()
$blog_id === false51–60get_current_blog_id(), get_site(), get_network(), get_option(), blog_id(), update_blog_status()
$blog_id === false53–62get_current_blog_id(), get_site(), get_network(), get_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id !== false55–64get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), blog_id(), update_blog_status()
$blog_id === false56–68get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), blog_id(), update_blog_status()
12 further outcomes, up to 86 instructions
$blog_id !== false57–66get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id === false58–70get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id === false && $blog_id !== 160–72get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status()
$blog_id !== false60–72get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), get_site_option(), blog_id(), update_blog_status()
$blog_id === false && $blog_id !== 162–74get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id !== false62–74get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), get_site_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id !== false && $blog_id !== 164–76get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status()
$blog_id === false && $blog_id !== 165–80get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), blog_id(), update_blog_status()
$blog_id !== false && $blog_id !== 166–78get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id === false && $blog_id !== 167–82get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), blog_id(), update_blog_status(), restore_current_blog()
$blog_id !== false && $blog_id !== 169–84get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), blog_id(), update_blog_status()
$blog_id !== false && $blog_id !== 171–86get_current_blog_id(), switch_to_blog(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), blog_id(), update_blog_status(), restore_current_blog()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9533–8616
8.59533–8616
8.49533–86163 fewer instructions than PHP 8.3
8.39836–8916
8.29836–8916
8.19836–8916
7.49836–8916

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 · 2

2 hooks fire while wpmu_delete_blog() runs, in this order:

  1. do_action( delete_blog )action_deprecatedline 101 (+37 into the body)

    Fires before a site is deleted.

  2. do_action( deleted_blog )action_deprecatedline 120 (+56 into the body)

    Fires after the site is deleted from the network.

Uses · 13

Show all 13

Source code

function wpmu_delete_blog( $blog_id, $drop = false ) {	$blog_id = (int) $blog_id; 	$switch = false;	if ( get_current_blog_id() !== $blog_id ) {		$switch = true;		switch_to_blog( $blog_id );	} 	$blog = get_site( $blog_id ); 	$current_network = get_network(); 	// If a full blog object is not available, do not destroy anything.	if ( $drop && ! $blog ) {		$drop = false;	} 	// Don't destroy the initial, main, or root blog.	if ( $drop		&& ( 1 === $blog_id || is_main_site( $blog_id )			|| ( $blog->path === $current_network->path && $blog->domain === $current_network->domain ) )	) {		$drop = false;	} 	$upload_path = trim( get_option( 'upload_path' ) ); 	// If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.	if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {		$drop = false;	} 	if ( $drop ) {		wp_delete_site( $blog_id );	} else {		/** This action is documented in wp-includes/ms-site.php */		do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.1.0' ); 		$users = get_users(			array(				'blog_id' => $blog_id,				'fields'  => 'ids',			)		); 		// Remove users from this blog.		if ( ! empty( $users ) ) {			foreach ( $users as $user_id ) {				remove_user_from_blog( $user_id, $blog_id );			}		} 		update_blog_status( $blog_id, 'deleted', 1 ); 		/** This action is documented in wp-includes/ms-site.php */		do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.1.0' );	} 	if ( $switch ) {		restore_current_blog();	}}

Changelog

Introduced in 3.0.0. Unchanged from 6.7.7 through 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.

5.1.0
Use wp_delete_site() internally to delete the site row from the database.from the docblock
3.0.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-admin/includes/ms.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.