Make WordPress Core


Ignore:
Timestamp:
11/20/2014 06:52:07 AM (10 years ago)
Author:
jeremyfelt
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ms.php

    r30177 r30404  
    8686    $current_site = get_current_site();
    8787
     88    // If a full blog object is not available, do not destroy anything.
     89    if ( $drop && ! $blog ) {
     90        $drop = false;
     91    }
     92
    8893    // Don't destroy the initial, main, or root blog.
    89     if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) )
     94    if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_site->path && $blog->domain == $current_site->domain ) ) ) {
    9095        $drop = false;
     96    }
     97
     98    $upload_path = trim( get_option( 'upload_path' ) );
     99
     100    // If ms_files_rewriting is enabled and upload_path is empty, wp_upload_dir is not reliable.
     101    if ( $drop && get_site_option( 'ms_files_rewriting' ) && empty( $upload_path ) ) {
     102        $drop = false;
     103    }
    91104
    92105    if ( $drop ) {
     106        $uploads = wp_upload_dir();
     107
    93108        $tables = $wpdb->tables( 'blog' );
    94109        /**
     
    108123        $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $blog_id ) );
    109124
    110         $uploads = wp_upload_dir();
    111125        /**
    112126         * Filter the upload base directory to delete when the blog is deleted.
Note: See TracChangeset for help on using the changeset viewer.