2
votes

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?

1
Why do you want to get rid of it? That's how it keeps the different sites' data separate. - ceejayoz
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

1 Answers

2
votes

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,
    );

}