humanmade / humanmade/network-media-library

wp_uploads_dir still points towards the subsite folder

Open
#83 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
296
Forks
67
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the wp_uploads_dir entry point and the network-media-library/site_id filter in a WordPress Multisite setup. Reproduce the Fancy Media module case and compare the returned paths with the selected main media library location. Done means the function resolves the chosen library path instead of the subsite path and image resizing can find the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.