wp_delete_site( int $site_id ): WP_Site|WP_Error
- Since
- 5.1.0
- Source
wp-includes/ms-site.php:212
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
$site_idint- ID of the site that should be deleted.
Return value
WP_Site|WP_Error- The deleted site object on success, or error object on failure.
Performance profile
How much work a call to wp_delete_site() 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
- 12–77
- Plugin surface
- 5 hooks
- Called by
- 1
Reaches the database via ->delete().
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 110.
Third-party callbacks on 'wp_validate_site_deletion', 'delete_blog', 'wp_uninitialize_site' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()called directly - sqldatabase query
->delete()called directly - optionnetwork option
get_network_option()one call below wp_delete_site() - cacheobject cache
wp_cache_delete()one call below wp_delete_site()
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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_delete_site() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($site_id) | 12 | __() |
!empty($site_id) | 17 | get_site(), __() |
!empty($site_id) && !empty($errors) | 20 | get_site(), do_action() |
!empty($site_id) && empty($errors) && !is_site_meta_supported() | 55 | get_site(), do_action(), do_action(), is_site_meta_supported(), blog_id(), __(), ->delete() |
!empty($site_id) && empty($errors) && !is_site_meta_supported() | 60 | get_site(), do_action(), do_action(), is_site_meta_supported(), blog_id(), clean_blog_cache(), do_action() |
!empty($site_id) && empty($errors) && is_site_meta_supported() | 71–72 | get_site(), do_action(), do_action(), is_site_meta_supported(), ->prepare(), ->get_col(), blog_id(), __(), ->delete() |
!empty($site_id) && empty($errors) && is_site_meta_supported() | 76–77 | get_site(), do_action(), do_action(), is_site_meta_supported(), ->prepare(), ->get_col(), blog_id(), clean_blog_cache(), do_action() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 110 instructions, 12–77 executed per call, 7 branches. The work does not change between versions.
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 · 5
5 hooks fire while wp_delete_site() runs, in this order:
- do_action( wp_validate_site_deletion )actionline 237 (+25 into the body)
Fires before a site should be deleted from the database.
- do_action( delete_blog )action_deprecatedline 252 (+40 into the body)
Fires before a site is deleted.
- do_action( wp_uninitialize_site )actionline 261 (+49 into the body)
Fires when a site's uninitialization routine should be executed.
- do_action( wp_delete_site )actionline 283 (+71 into the body)
Fires once a site has been deleted from the database.
- do_action( deleted_blog )action_deprecatedline 294 (+82 into the body)
Fires after the site is deleted from the network.
Uses · 8
- __()Retrieves the translation of $text.
- get_site()Retrieves site data given a site ID or site object.
- do_action()Calls the callback functions that have been added to an action hook.
- do_action_deprecated()Fires functions attached to a deprecated action hook.
- is_site_meta_supported()Determines whether site meta is enabled.
- delete_metadata_by_mid()Deletes metadata by meta ID.
- clean_blog_cache()Clean the blog cache
- WP_Error::__construct()Initializes the error.
Used by · 1
- wpmu_delete_blog()Deletes a site.
Source code
function wp_delete_site( $site_id ) { global $wpdb; if ( empty( $site_id ) ) { return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) ); } $old_site = get_site( $site_id ); if ( ! $old_site ) { return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) ); } $errors = new WP_Error(); /** * Fires before a site should be deleted from the database. * * Plugins should amend the `$errors` object via its `WP_Error::add()` method. If any errors * are present, the site will not be deleted. * * @since 5.1.0 * * @param WP_Error $errors Error object to add validation errors to. * @param WP_Site $old_site The site object to be deleted. */ do_action( 'wp_validate_site_deletion', $errors, $old_site ); if ( ! empty( $errors->errors ) ) { return $errors; } /** * Fires before a site is deleted. * * @since MU (3.0.0) * @deprecated 5.1.0 * * @param int $site_id The site ID. * @param bool $drop True if site's table should be dropped. Default false. */ do_action_deprecated( 'delete_blog', array( $old_site->id, true ), '5.1.0' ); /** * Fires when a site's uninitialization routine should be executed. * * @since 5.1.0 * * @param WP_Site $old_site Deleted site object. */ do_action( 'wp_uninitialize_site', $old_site ); if ( is_site_meta_supported() ) { $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $old_site->id ) ); foreach ( $blog_meta_ids as $mid ) { delete_metadata_by_mid( 'blog', $mid ); } } if ( false === $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $old_site->id ) ) ) { return new WP_Error( 'db_delete_error', __( 'Could not delete site from the database.' ), $wpdb->last_error ); } clean_blog_cache( $old_site ); /** * Fires once a site has been deleted from the database. * * @since 5.1.0 * * @param WP_Site $old_site Deleted site object. */ do_action( 'wp_delete_site', $old_site ); /** * Fires after the site is deleted from the network. * * @since 4.8.0 * @deprecated 5.1.0 * * @param int $site_id The site ID.Changelog
Introduced in 5.1.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.9.7 tag, from
src/wp-includes/ms-site.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.