Title: Broken for multisites
Last modified: August 21, 2016

---

# Broken for multisites

 *  Resolved [Arkadiusz Rzadkowolski](https://wordpress.org/support/users/fliespl/)
 * (@fliespl)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/broken-for-multisites/)
 * 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](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](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/](https://wordpress.org/plugins/instagram-slider-widget/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [Arkadiusz Rzadkowolski](https://wordpress.org/support/users/fliespl/)
 * (@fliespl)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/broken-for-multisites/#post-5026938)
 * 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&#8221](http://XXX.com/files/2014/06/0b1e655ca4722dbbb59b8366b506a329.jpg&#8221);
 *  Thread Starter [Arkadiusz Rzadkowolski](https://wordpress.org/support/users/fliespl/)
 * (@fliespl)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/broken-for-multisites/#post-5026940)
 * 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 );
       ```
   
 *  [JR Web Studio](https://wordpress.org/support/users/jetonr/)
 * (@jetonr)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/broken-for-multisites/#post-5027165)
 * 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.
 *  Thread Starter [Arkadiusz Rzadkowolski](https://wordpress.org/support/users/fliespl/)
 * (@fliespl)
 * [11 years, 10 months ago](https://wordpress.org/support/topic/broken-for-multisites/#post-5027166)
 *     ```
       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.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Broken for multisites’ is closed to new replies.

 * ![](https://ps.w.org/instagram-slider-widget/assets/icon-256x256.png?rev=2602786)
 * [Social Slider Feed – Social Media Feed & Gallery Widgets](https://wordpress.org/plugins/instagram-slider-widget/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/instagram-slider-widget/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/instagram-slider-widget/)
 * [Active Topics](https://wordpress.org/support/plugin/instagram-slider-widget/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/instagram-slider-widget/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/instagram-slider-widget/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [Arkadiusz Rzadkowolski](https://wordpress.org/support/users/fliespl/)
 * Last activity: [11 years, 10 months ago](https://wordpress.org/support/topic/broken-for-multisites/#post-5027166)
 * Status: resolved