Skip to content

Instantly share code, notes, and snippets.

@azanebrain
Created January 27, 2014 20:20
Show Gist options
  • Save azanebrain/fa912c4b20415e7bc728 to your computer and use it in GitHub Desktop.
Save azanebrain/fa912c4b20415e7bc728 to your computer and use it in GitHub Desktop.
Set a unique upload path for each site on a multisite network (MU Plugin)
<?php
add_filter('upload_dir', 'mu_media_upload_dir');
function mu_media_upload_dir($upload) {
$site_title=str_replace( ' ' , '_' , get_bloginfo('name','raw') );
$upload['path'] = ABSPATH . '/shared/' . $site_title;
switch_to_blog(1);
$upload['url'] = site_url() . '/shared/' . $site_title;
restore_current_blog();
$upload['subdir'] = "";
$upload['basedir'] = $upload['path'];
$upload['baseurl'] = $upload['url'];
return $upload;
}
@azanebrain
Copy link
Author

This is an MU Plugin that automatically saves media uploads to /shared/<your site's name>
It replaces spaces in the name with an underscore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment