WordPress.org

Make WordPress Core

Ticket #18489: 18489.php

File 18489.php, 1.2 KB (added by nacin, 10 years ago)
Line 
1<?php
2/**
3 * Makes sure MU-like upload paths are valid.
4 *
5 * Explanation: In a nutshell, the $main_override in wp_upload_dir() that would
6 * normally prevent these str_replace() calls from occurring is set to
7 * `defined('MULTISITE') && is_main_site()`. Thus, the main site for multisite.
8 * However, this doesn't take multi-networks into account. And it especially
9 * doesn't take into account that we want consistent MU-like handling for all of
10 * our sites, including the main blog.
11 *
12 * We actually don't want MU-like handling for every single site, but we're not
13 * forcing that here. We're just running an str_replace() for blogs.dir-like strings.
14 * Thus, as long as the database specifies wp-content/uploads, then it'll work.
15 *
16 * @todo Figure out if the need for untrailingslashit() is indicative of a core bug.
17 *
18 * @since 2010 July 30
19 * @author Nacin
20 */
21function filter_upload_dir( $uploads ) {
22        $uploads['url'] = str_replace( untrailingslashit( UPLOADS ), 'files', $uploads['url'] );
23        $uploads['baseurl'] = str_replace( untrailingslashit( UPLOADS ), 'files', $uploads['baseurl'] );
24        return $uploads;
25}
26add_filter( 'upload_dir', array( __CLASS__, 'filter_upload_dir' ) );