wordpress multisite remove /sites/{ID}/ automatic upload url

被刻印的时光 ゝ 提交于 2019-12-10 11:16:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!