<?php
/**
 * Makes sure MU-like upload paths are valid.
 *
 * Explanation: In a nutshell, the $main_override in wp_upload_dir() that would
 * normally prevent these str_replace() calls from occurring is set to
 * `defined('MULTISITE') && is_main_site()`. Thus, the main site for multisite.
 * However, this doesn't take multi-networks into account. And it especially
 * doesn't take into account that we want consistent MU-like handling for all of
 * our sites, including the main blog.
 *
 * We actually don't want MU-like handling for every single site, but we're not
 * forcing that here. We're just running an str_replace() for blogs.dir-like strings.
 * Thus, as long as the database specifies wp-content/uploads, then it'll work.
 *
 * @todo Figure out if the need for untrailingslashit() is indicative of a core bug.
 *
 * @since 2010 July 30
 * @author Nacin
 */
function filter_upload_dir( $uploads ) {
	$uploads['url'] = str_replace( untrailingslashit( UPLOADS ), 'files', $uploads['url'] );
	$uploads['baseurl'] = str_replace( untrailingslashit( UPLOADS ), 'files', $uploads['baseurl'] );
	return $uploads;
}
add_filter( 'upload_dir', array( __CLASS__, 'filter_upload_dir' ) );