Make WordPress Core


Ignore:
Timestamp:
10/12/2012 10:05:02 PM (12 years 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.

File:
1 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 );
Note: See TracChangeset for help on using the changeset viewer.