wordpress多站点删除/sites/{ID}/自动上传网址 [英] wordpress multisite remove /sites/{ID}/ automatic upload url

查看:83
本文介绍了wordpress多站点删除/sites/{ID}/自动上传网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用wp多站点时,它很快就混乱了.是否有任何解决方案可以删除自动的/sites/{id}/文件夹结构?

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

我可以在站点设置中调整site-upload-dir,但是它总是通过媒体管理器将"/sites/{id}/"添加到上传的文件中.

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?

推荐答案

首先,我最终更改了 wp-includes/functions.php 中的核心,以禁止添加:

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

在我的hack的下面一行:

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

}

这篇关于wordpress多站点删除/sites/{ID}/自动上传网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆