Support » Plugin: Fly Dynamic Image Resizer » Bug in multisite in short code and switch_to_blog.

  • Resolved Joel Bernerman


    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.

    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');
        print '<pre>';

    The result is the src gets a absolute path in the url.

    array(3) {
      string(107) "http://wp.local/wp-content/uploads/sites/2/var/www/html/wp-content/uploads/fly-images/10/load-500x500-c.png"

    I will try to find a fix for this. and will return about it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Joel Bernerman


    This fixes it but I’m not sure if it is the best approach.
    Would it hurt the performace?
    Its pretty edge case so it would probably not be done that often.

    public function get_fly_dir( $path = '' ) {
      if ( empty($this->_fly_dir) || ( function_exists('ms_is_switched') && ms_is_switched() ) ) {
        $wp_upload_dir = wp_upload_dir();
        return $wp_upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'fly-images' . ( '' !== $path ? DIRECTORY_SEPARATOR . $path : '' );
      } else {
        return $this->_fly_dir . ( '' !== $path ? DIRECTORY_SEPARATOR . $path : '' );
    Plugin Author Junaid Bhura


    Hey @yo-l1982,

    Thanks for bringing this up. I’ve created an issue for this in Github:

    I’ll take a deeper look into this issue, and add an update on Github. You can feel free to participate on this issue, and directly create future issues on Github, because that’s where all the development happens.

    Plugin Author Junaid Bhura


    Hey @yo-l1982,

    This has been fixed. I’ve updated the new version 2.0.5! 🙂

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bug in multisite in short code and switch_to_blog.’ is closed to new replies.