humanmade / network-media-library

Network Media Library plugin for WordPress Multisite
MIT License
290 stars 55 forks source link

wp_uploads_dir still points towards the subsite folder #83

Open celinenicolas opened 3 years ago

celinenicolas commented 3 years ago

The WP core function wp_uploads_dir still returns the subsite directory paths and not the directory for the main media library as defined in the filter network-media-library/site_id.

This means that instead of returning wp-content/uploads/, it returns wp-content/uploads/sites/2.

The issue is seen when using the Fancy Media module in WP Bakery Page Builder. The image is still displayed, but not resized to the correct dimensions, because it cannot find the file in wp-content/uploads/sites/2.

I found a workaround by adding this filter

add_filter( 'upload_dir', 'multisite_upload_dir' ); 
function multisite_upload_dir( $dirs ) {
    $dirs['baseurl'] = network_site_url( '/wp-content/uploads') ;
    $dirs['basedir'] = ABSPATH . 'wp-content/uploads';
    $dirs['path'] = $dirs['basedir'] . $dirs['subdir'];
    $dirs['url'] = $dirs['baseurl'] . $dirs['subdir'];
    return $dirs;
}

Ideally, we'd want this to use the exact path of the media library we chose in network-media-library/site_id.