bueltge / multisite-global-media

Share a media library across the WordPress Multisite network
GNU General Public License v2.0
216 stars 50 forks source link

Query Attachments returns url based on current site and not global? #83

Open gRoberts84 opened 5 years ago

gRoberts84 commented 5 years ago

Hi there,

For some strange reason, when accessing the global media tab on any of my sites, the results are returned with the image URL based on the current site and not the site marked as the global site.

i.e. Site B is master and when accessing the Global Media tab on Site A, all images have the Site B url as a prefix.

I'm not seeing anyone else reporting the issue, so surely this must be something I have introduced, or that I am using the sub-folder multisite setup, rather than sub-domain?

Any thoughts would be really appreciated :)

gRoberts84 commented 5 years ago

wp_upload_dir is for some reason returning the correct file paths, but incorrect URL's.

As a dirty fix for now, I have had to apply the following:

add_filter( 'upload_dir', function($data) {
  if ($GLOBALS['current_blog']->blog_id !== MultisiteGlobalMedia\getSideId() && 
      $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && 
      $_POST['action'] == 'query-attachments' &&
      isset($_POST['query']) &&
      isset($_POST['query']['global_media'])
  ) {
    $data['url'] = str_replace($GLOBALS['current_blog']->path, '/', $data['url']);
    $data['baseurl'] = str_replace($GLOBALS['current_blog']->path, '/', $data['baseurl']);
  }
  return $data;
});
widoz commented 5 years ago

Hi @gRoberts84,

Have you tried with all of the plugin deactivated except for MultisiteGlobalMedia and the default theme?

Also, may I suggest you to try to use the newest version downloadable from https://github.com/bueltge/multisite-global-media/releases/download/0.1.0-beta/multisite-global-media-0.1.0-beta.zip ?

bowser845 commented 5 years ago

I am also experiencing the issue that @gRoberts84 described. However, I experienced it on localhost when testing, but not on my live site. The two have considerably different set ups (I was just testing it quickly), so I assume it is related to other plugins / themes I have installed on the live site that were not installed on localhost.