Created
June 13, 2014 18:57
-
-
Save bcole808/15902f41aef91087c006 to your computer and use it in GitHub Desktop.
wp_upload_dir() multsite fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/*************************************************** | |
* Filter the results of wp_upload_dir() | |
* | |
* In WordPress Multisite systems that were installed prior to 3.5 the system uses the folder structure /wp-content/blogs.dir/XX to store uploaded files for each blog. | |
* | |
* The URL used to access these files follows the format /SITENAME/files/ but the function wp_upload_dir() does not match this format | |
***************************************************/ | |
function wpms_fix_upload_paths($data) { | |
// Check if the base URL matches the format 'wp-content/blogs.dir/00/files' | |
$needs_fixing = preg_match("/wp-content\/blogs\.dir\/(\d+)\/files/", $data['baseurl'], $uri_part); | |
if ($needs_fixing) { | |
$data['url'] = str_replace($uri_part[0], 'files', $data['url']); | |
$data['baseurl'] = str_replace($uri_part[0], 'files', $data['baseurl']); | |
} | |
return $data; | |
} | |
// Fix upload paths | |
add_filter('upload_dir', 'wpms_fix_upload_paths'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment