WordPress.org

Make WordPress Core

Changeset 22222


Ignore:
Timestamp:
10/12/12 22:05:02 (18 months ago)
Author:
nacin
Message:

Have wp_upload_dir() account for blog switching, ms-files rewriting, and the UPLOADS constant properly. This type of logic needs a lot of code comments.

Prevents wp_upload_dir() from obeying the UPLOADS constant when ms-files rewriting is enabled and a blog is switched.

Reverts [22106] thanks to [22108].

see #19235.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r22108 r22222  
    15041504    } 
    15051505 
    1506     if ( defined( 'UPLOADS' ) ) { 
     1506    // Obey the value of UPLOADS. This happens as long as ms-files rewriting is disabled. 
     1507    // We also sometimes obey UPLOADS when rewriting is enabled -- see the next block. 
     1508    if ( defined( 'UPLOADS' ) && ! ( is_multisite() && get_site_option( 'ms_files_rewriting' ) ) ) { 
    15071509        $dir = ABSPATH . UPLOADS; 
    15081510        $url = trailingslashit( $siteurl ) . UPLOADS; 
    15091511    } 
    15101512 
    1511     // If multisite (if not the main site in a post-MU network) 
    1512     $blog_id = get_current_blog_id(); 
    1513     if ( is_multisite() && ! ( is_main_site( $blog_id ) && defined( 'MULTISITE' ) ) ) { 
     1513    // If multisite (and if not the main site in a post-MU network) 
     1514    if ( is_multisite() && ! ( is_main_site() && defined( 'MULTISITE' ) ) ) { 
    15141515 
    15151516        if ( ! get_site_option( 'ms_files_rewriting' ) ) { 
    1516             // Append sites/%d if we're not on the main site (for post-MU networks). The extra directory 
     1517            // If ms-files rewriting is disabled (networks created post-3.5), it is fairly straightforward: 
     1518            // Append sites/%d if we're not on the main site (for post-MU networks). (The extra directory 
    15171519            // prevents a four-digit ID from conflicting with a year-based directory for the main site. 
    15181520            // But if a MU-era network has disabled ms-files rewriting manually, they don't need the extra 
    1519             // directory, as they never had wp-content/uploads for the main site. 
    1520  
    1521             $ms_dir = defined( 'MULTISITE' ) ? '/sites/' : '/'; 
    1522             $dir .= $ms_dir . $blog_id; 
    1523             $url .= $ms_dir . $blog_id; 
    1524         } elseif ( ! ms_is_switched() ) { 
     1521            // directory, as they never had wp-content/uploads for the main site.) 
     1522 
     1523            if ( defined( 'MULTISITE' ) ) 
     1524                $ms_dir = '/sites/' . get_current_blog_id(); 
     1525            else 
     1526                $ms_dir = '/' . get_current_blog_id(); 
     1527 
     1528            $dir .= $ms_dir; 
     1529            $url .= $ms_dir; 
     1530 
     1531        } elseif ( defined( 'UPLOADS' ) && ! ms_is_switched() ) { 
    15251532            // Handle the old-form ms-files.php rewriting if the network still has that enabled. 
     1533            // When ms-files rewriting is enabled, then we only listen to UPLOADS when: 
     1534            //   1) we are not on the main site in a post-MU network, 
     1535            //      as wp-content/uploads is used there, and 
     1536            //   2) we are not switched, as ms_upload_constants() hardcodes 
     1537            //      these constants to reflect the original blog ID. 
     1538 
    15261539            if ( defined( 'BLOGUPLOADDIR' ) ) 
    15271540                $dir = untrailingslashit( BLOGUPLOADDIR ); 
  • trunk/wp-includes/ms-default-constants.php

    r21892 r22222  
    2929        define( 'UPLOADBLOGSDIR', 'wp-content/blogs.dir' ); 
    3030 
    31     // The main site in a post-MU network uses wp-content/uploads. 
    32     // This used to be handled in wp_upload_dir() by ignoring UPLOADS for this case. Avoid defining it instead. 
     31    // Note, the main site in a post-MU network uses wp-content/uploads. 
     32    // This is handled in wp_upload_dir() by ignoring UPLOADS for this case. 
    3333    if ( ! defined( 'UPLOADS' ) ) { 
    34         if ( ! ( is_main_site() && defined( 'MULTISITE' ) ) ) 
    35             define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); 
     34        define( 'UPLOADS', UPLOADBLOGSDIR . "/{$wpdb->blogid}/files/" ); 
    3635 
    3736        // Uploads dir relative to ABSPATH 
Note: See TracChangeset for help on using the changeset viewer.