mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 01:27:36 +01:00
Prevent wpmu_delete_blog from removing the wrong uploads directory
`wp_upload_dir()` includes some logic to fall back to the default site's upload directory if a specific directory for the requested site cannot be found. Because of this, if `wpmu_delete_blog()` is fired twice in a row for the same site, the main site's upload directory could be deleted as well. This adds some checks in `wpmu_delete_blog()` so that we are confident in the site and it's upload directory's existence before dropping the site. Tests are added for when `ms_files_rewriting` is enabled or disabled. Fixes #30121 Built from https://develop.svn.wordpress.org/trunk@30404 git-svn-id: http://core.svn.wordpress.org/trunk@30399 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d0b10b5022
commit
3a7b5748eb
@ -85,11 +85,26 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
|
|||||||
|
|
||||||
$current_site = get_current_site();
|
$current_site = get_current_site();
|
||||||
|
|
||||||
// Don't destroy the initial, main, or root blog.
|
// If a full blog object is not available, do not destroy anything.
|
||||||
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
|
if ( $drop && ! $blog ) {
|
||||||
$drop = false;
|
$drop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't destroy the initial, main, or root blog.
|
||||||
|
if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->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 ) {
|
if ( $drop ) {
|
||||||
|
$uploads = wp_upload_dir();
|
||||||
|
|
||||||
$tables = $wpdb->tables( 'blog' );
|
$tables = $wpdb->tables( 'blog' );
|
||||||
/**
|
/**
|
||||||
* Filter the tables to drop when the blog is deleted.
|
* Filter the tables to drop when the blog is deleted.
|
||||||
@ -107,7 +122,6 @@ function wpmu_delete_blog( $blog_id, $drop = false ) {
|
|||||||
|
|
||||||
$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
|
$wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
|
||||||
|
|
||||||
$uploads = wp_upload_dir();
|
|
||||||
/**
|
/**
|
||||||
* Filter the upload base directory to delete when the blog is deleted.
|
* Filter the upload base directory to delete when the blog is deleted.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user