Bug in multisite in short code and switch_to_blog.
-
This is a bit niche but of course I manage to trigger it.
If you in a short code do a switch_to_blog() on a multisite install and try to fetch an image from the blog you are not visiting you will get a faulty image src when using fly_get_attachment_image_src.To recreate.
Have a multisite with at least 2 blogs.Upload an image each blog and save the ids.
Replace the ids in the code below, $image_id with the image on the blog you are adding the shortcode to. $other_image_id should have the image id on the blog you switch to in the code.
Change $blog_id to the id of the blog that has the $other_image_id
Add a post with shortcode [fly_test] on the blog that has the $image_id.
<?php /* Plugin Name: Fly Bug Description: bug test Version: 2.0.4 Author: Joel Bernerman */ add_shortcode('fly_test', 'fly_test'); function fly_test() { // set an existing id to blog in multisite you are not using the shortcode on. $blog_id = 2; // set an existing id to image on the blog switched to. $other_image_id = 10; // set an existing id to image on the blog you are using the short code on. $image_id = 193; fly_add_image_size('test_size', 500, 500, true); // Make sure _fly_dir is set in fly image plugin. fly_get_attachment_image_src($image_id, 'test_size'); switch_to_blog($blog_id, true); // Use an image id from blog switched to. $src = fly_get_attachment_image_src($other_image_id, 'test_size'); restore_current_blog(); print '<pre>'; var_dump($src); }
The result is the src gets a absolute path in the url.
array(3) { ["src"]=> string(107) "https://wp.local/wp-content/uploads/sites/2/var/www/html/wp-content/uploads/fly-images/10/load-500x500-c.png" ["width"]=> int(500) ["height"]=> int(306) }
I will try to find a fix for this. and will return about it.
- The topic ‘Bug in multisite in short code and switch_to_blog.’ is closed to new replies.