I'm using DigitalOcean Spaces to store my static assets. All is working fine, my media library url point to my Spaces (e.g. foobar.sgp1.digitaloceanspaces.com).
The problem starts when I install multisite, as it's default WordPress behavior to add "sites/xxx" to all sub site's media url (e.g. foobar.sgp1.digitaloceanspaces.com/sites/2). Which of course, my assets are not there, and can't be found.
I've found this link:
Which gave me an idea.
I've tried this on functions.php
add_filter('upload_dir', 'multisite_path');
function multisite_path( $param ){
$path = str_replace('sites/2/', '', $param['path']);
$url = str_replace('sites/2/', '', $param['url']);
$param['path'] = $path;
$param['url'] = $url;
return $param;
}
But it's not working.
If there's a hook to remove "sites/2/" from the url, or any other way to disable this functionality, I'm open for suggestions.
Thanks.
Found the solution here:
wordpress multisite remove /sites/{ID}/ automatic upload url
Here's the working code:
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,
);
}