On this page
wpmu_delete_blog( int $blog_id, bool $drop = false )
Delete a site.
Parameters
$blog_idint Required-
Site ID.
$dropbool Optional-
True if site's database tables should be dropped.
Default:
false
Source
File: wp-admin/includes/ms.php. View all references
function wpmu_delete_blog( $blog_id, $drop = false ) {
global $wpdb;
$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();
}
}
Hooks
- do_action_deprecated( 'deleted_blog',
int $site_id ,bool $drop ) -
Fires after the site is deleted from the network.
- do_action_deprecated( 'delete_blog',
int $site_id ,bool $drop ) -
Fires before a site is deleted.
Related
Uses
| Uses | Description |
|---|---|
| wp_delete_site() wp-includes/ms-site.php | Deletes a site from the database. |
| get_network() wp-includes/ms-network.php | Retrieves network data given a network ID or network object. |
| get_site() wp-includes/ms-site.php | Retrieves site data given a site ID or site object. |
| do_action_deprecated() wp-includes/plugin.php | Fires functions attached to a deprecated action hook. |
| is_main_site() wp-includes/functions.php | Determines whether a site is the main site of the current network. |
| get_users() wp-includes/user.php | Retrieves list of users matching criteria. |
| remove_user_from_blog() wp-includes/ms-functions.php | Removes a user from a blog. |
| switch_to_blog() wp-includes/ms-blogs.php | Switch the current blog. |
| update_blog_status() wp-includes/ms-blogs.php | Update a blog details field. |
| restore_current_blog() wp-includes/ms-blogs.php | Restore the current blog, after calling switch_to_blog() . |
| get_current_blog_id() wp-includes/load.php | Retrieve the current site ID. |
| get_site_option() wp-includes/option.php | Retrieve an option value for the current network based on name of option. |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Changelog
| Version | Description |
|---|---|
| 5.1.0 | Use wp_delete_site() internally to delete the site row from the database. |
| 3.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wpmu_delete_blog