WordPress.org

Forums

Instagram Slider Widget
[resolved] Broken for multisites (5 posts)

  1. Arkadiusz Rzadkowolski
    Member
    Posted 10 months ago #

    I have checked this plugin and it has serious bug with multisite install - it will add medias to the library ALWAYS.

    The problem is that get_attachment_id_from_src function split the path using WP_CONTENT_URL, which is not the case with multisite where images have url as follow:

    $parse_url = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );

    // http://XXX.com/files/2014/06/89e9b5f396cce783703073a3adbea1e2.jpg

    In such case check will fail and file will be added to library. I have learned it the hard way: http://codeone.pl/ss/ss-2014-06-20_10-47-37-001.png

    As you can see there is 60 images used and 120000 added (not joined anywhere). All images are the same :)

    https://wordpress.org/plugins/instagram-slider-widget/

  2. Arkadiusz Rzadkowolski
    Member
    Posted 10 months ago #

    Also files is an alias for:

    /wp-content/blogs.dir/'.$current_blog->blog_id.'/files

    and guid (in database) is in format:

    ["guid"]=> string(75) "http://XXX.com/files/2014/06/0b1e655ca4722dbbb59b8366b506a329.jpg"

  3. Arkadiusz Rzadkowolski
    Member
    Posted 10 months ago #

    Possible fix I have used on my multisite:

    private function get_attachment_id_from_src( $url ) {
    
            // add multisite check for other types of links
            if(defined('MULTISITE') && MULTISITE) {
                global $wpdb;
    
                $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $url));
                if ( isset( $attachment[0] ) ) {
                    return $attachment[0];
                }
            }
    
    		// Split the $url into two parts with the wp-content directory as the separator.
    		$parse_url  = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
  4. jetonr
    Member
    Plugin Author

    Posted 10 months ago #

    Did you fix the problem because I haven't tried it on a multisite. If so I will include this fix on the next update.

  5. Arkadiusz Rzadkowolski
    Member
    Posted 10 months ago #

    private function get_attachment_id_from_src( $url ) {
    
            // add multisite check for other types of links
            if(defined('MULTISITE') && MULTISITE) {
                global $wpdb;
    
                $attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $url));
                if ( isset( $attachment[0] ) ) {
                    return $attachment[0];
                }
            }
    
    		// Split the $url into two parts with the wp-content directory as the separator.
    		$parse_url  = explode( parse_url( WP_CONTENT_URL, PHP_URL_PATH ), $url );
    
    		// Get the host of the current site and the host of the $url, ignoring www.
    		$this_host = str_ireplace( 'www.', '', parse_url( home_url(), PHP_URL_HOST ) );
    		$file_host = str_ireplace( 'www.', '', parse_url( $url, PHP_URL_HOST ) );
    
    		// Return false if there aren't any $url parts or if the current host and $url host do not match.
    		if ( ! isset( $parse_url[1] ) || empty( $parse_url[1] ) || ( $this_host != $file_host ) ) {
    			return false;
    		}
    
    		// Now we're going to quickly search the DB for any attachment GUID with a partial path match.
    		// Example: /uploads/2013/05/test-image.jpg
    		global $wpdb;
    
    		$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM {$wpdb->prefix}posts WHERE guid RLIKE %s;", $parse_url[1] ) );
    
    		// Returns attachment if isset.
    		if ( isset( $attachment[0] ) ) {
    			return $attachment[0];
    		}
    
    		return false;
    	}

    Yeap - we are using this code on our installation.

    Keep up the great work!

    --
    Regargs,
    A. Rz.

Reply

You must log in to post.

About this Plugin

  • Instagram Slider Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.