2

when using wp multisites it gets messed up pretty fast. Is there any solution available removing the automatic /sites/{id}/ folder structure?

I'm able to adjust the site-upload-dir within site-settings but it always adds " /sites/{id}/ " to the uploaded file through the media-manager.

Is there any snippet available removing/disabling these extra folder structure?

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Horst
  • 21
  • 2
  • Why do you want to get rid of it? That's how it keeps the different sites' data separate. – ceejayoz Jul 29 '15 at 14:29
  • 1
    thanks for asking. the site's data still gets seperated, it is in our custom-named-subfolder which we define through site>settings. This way we do have a nice name within our uploads/sites folder and it is easier to find the specific page. Instead of looking up the id. Does this make sense to you? – Horst Jul 29 '15 at 19:38

1 Answers1

4

First I ended up changing the core in wp-includes/functions.php in order to disable the addition:

if ( defined( 'MULTISITE' ) )
    $ms_dir = '/sites/' . get_current_blog_id();
else
    $ms_dir = '/' . get_current_blog_id();

And one line below that my hack:

$ms_dir = '';

But after a while I found this solution where one can use a hook. Example:

add_filter( 'upload_dir', 'same_upload_dir' );
function same_upload_dir( array $uploads ) {
    $baseurl = WP_CONTENT_URL . '/uploads';
    $basedir = ABSPATH . 'wp-content/uploads';
    $subdir = $uploads['subdir'];

    return array(
        'path'    => $basedir . $subdir,
        'url'     => $baseurl . $subdir,
        'subdir'  => $subdir,
        'basedir' => $basedir,
        'baseurl' => $baseurl,
        'error'   => false,
    );
}
Oli
  • 9,766
  • 5
  • 25
  • 46
zyrup
  • 691
  • 2
  • 10
  • 18