multisite-global-media icon indicating copy to clipboard operation
multisite-global-media copied to clipboard

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

Open gRoberts84 opened this issue 5 years ago • 3 comments

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 avatar Apr 19 '19 06:04 gRoberts84

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

gRoberts84 avatar Apr 19 '19 07:04 gRoberts84

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 ?

widoz avatar Apr 20 '19 17:04 widoz

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.

bowser845 avatar Nov 01 '19 11:11 bowser845