Viewing 4 replies - 1 through 4 (of 4 total)
  • 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) “https://XXX.com/files/2014/06/0b1e655ca4722dbbb59b8366b506a329.jpg”

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

    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.

    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.