I have now lol. I took a look in the 2.9 branch and it doesn't look to be fixed to me. It looks like a few lines of code that had been commented out that break in MU have been un-commented out:
/* Breaks WordPress MU image upload path
elseif ( false !== strpos($file, 'wp-content/uploads') )
$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
else
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
*/
has become:
elseif ( false !== strpos($file, 'wp-content/uploads') )
$url = $uploads['baseurl'] . substr( $file, strpos($file, 'wp-content/uploads') + 18 );
else
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
This seems to me like re-introducing an old bug. The fix I have made I believe addresses the problem by fixing those lines to work under MU correctly. Of course there could be a very good reason that it is now ok to un-comment these lines that I am unaware of and I would be happy to be told that I have misunderstood something. I am new to delving into the core code (but very keen!) so I'd appreciate the feedback. I have rewritten the wp_get_attachment_url() code slightly to the following:
function wp_get_attachment_url( $post_id = 0 ) {
$post_id = (int) $post_id;
if ( !$post =& get_post( $post_id ) )
return false;
$url = '';
if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true) ) { //Get attached file
// Files path
$uploads = wp_upload_dir();
$file_path = explode('wp-content', $uploads['basedir']);
$file_path = 'wp-content' . $file_path[1];
if ( $uploads && false === $uploads['error'] ) { //Get upload directory
if ( 0 === strpos($file, $uploads['basedir']) ) //Check that the upload base exists in the file location
$url = str_replace($uploads['basedir'], $uploads['baseurl'], $file); //replace file location with url location
elseif ( false !== strpos($file, $file_path) )
$url = $uploads['baseurl'] . substr( $file, strpos($file, $file_path) + strlen($file_path) );
else
$url = $uploads['baseurl'] . "/$file"; //Its a newly uploaded file, therefor $file is relative to the basedir.
}
}
if ( empty($url) ) //If any of the above options failed, Fallback on the GUID as used pre-2.7, not recomended to rely upon this.
$url = get_the_guid( $post->ID );
if ( 'attachment' != $post->post_type || empty($url) )
return false;
return apply_filters( 'wp_get_attachment_url', $url, $post->ID );
}