wpmu_delete_blog( int $blog_id, bool $drop = false )
- Since
- 3.0.0, 5.1.0
- Source
wp-admin/includes/ms.php:64
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
- Scaling
- Scales with input
- Instructions
- 33–86
- Plugin surface
- 2 hooks
- Called by
- 0
Reaches the database via get_users().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 95.
Third-party callbacks on 'delete_blog', 'deleted_blog' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
do_action_deprecated()called directly - querycontent query
get_users()called directly - cacheobject cache
wp_cache_switch_to_blog()one call below wpmu_delete_blog() - serializeserialisation
maybe_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.
| When | Instructions | Calls it makes |
|---|---|---|
$blog_id === false | 33–42 | get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site() |
$blog_id === false | 35–44 | get_current_blog_id(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site(), restore_current_blog() |
$blog_id !== false | 37–46 | get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), get_site_option(), wp_delete_site() |
$blog_id !== false | 39–48 | get_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 !== 1 | 42–54 | get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), get_site_option(), wp_delete_site() |
$blog_id === false && $blog_id !== 1 | 44–56 | get_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 !== 1 | 46–58 | get_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 !== 1 | 48–60 | get_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 === false | 51–60 | get_current_blog_id(), get_site(), get_network(), get_option(), blog_id(), update_blog_status() |
$blog_id === false | 53–62 | get_current_blog_id(), get_site(), get_network(), get_option(), blog_id(), update_blog_status(), restore_current_blog() |
$blog_id !== false | 55–64 | get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), blog_id(), update_blog_status() |
$blog_id === false | 56–68 | get_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 !== false | 57–66 | get_current_blog_id(), switch_to_blog(), get_site(), get_network(), get_option(), blog_id(), update_blog_status(), restore_current_blog() |
$blog_id === false | 58–70 | get_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 !== 1 | 60–72 | get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status() |
$blog_id !== false | 60–72 | get_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 !== 1 | 62–74 | get_current_blog_id(), get_site(), get_network(), is_main_site(), get_option(), blog_id(), update_blog_status(), restore_current_blog() |
$blog_id !== false | 62–74 | get_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 !== 1 | 64–76 | get_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 !== 1 | 65–80 | get_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 !== 1 | 66–78 | get_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 !== 1 | 67–82 | get_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 !== 1 | 69–84 | get_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 !== 1 | 71–86 | get_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
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 95 | 33–86 | 16 | |
| 8.5 | 95 | 33–86 | 16 | |
| 8.4 | 95 | 33–86 | 16 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 98 | 36–89 | 16 | |
| 8.2 | 98 | 36–89 | 16 | |
| 8.1 | 98 | 36–89 | 16 | |
| 7.4 | 98 | 36–89 | 16 |
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:
- do_action( delete_blog )action_deprecatedline 101 (+37 into the body)
Fires before a site is deleted.
- do_action( deleted_blog )action_deprecatedline 120 (+56 into the body)
Fires after the site is deleted from the network.
Uses · 13
- get_current_blog_id()Retrieves the current site ID.
- switch_to_blog()Switches the current blog.
- get_site()Retrieves site data given a site ID or site object.
- get_network()Retrieves network data given a network ID or network object.
- is_main_site()Determines whether a site is the main site of the current network.
- get_option()Retrieves an option value based on an option name.
- get_site_option()Retrieve an option value for the current network based on name of option.
- wp_delete_site()Deletes a site from the database.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- get_users()Retrieves list of users matching criteria.
- remove_user_from_blog()Removes a user from a blog.
- update_blog_status()Updates a blog details field.
Show all 13
- restore_current_blog()Restores the current blog, after calling switch_to_blog().
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-blogs.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-blogs.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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.