问题
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:
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,
);
}
来源:https://stackoverflow.com/questions/31703248/wordpress-multisite-remove-sites-id-automatic-upload-url