Solution to WordPress 2.7.1 Gallery Code Problem

I tried to find a solution to the WordPress 2.7.1 gallery code problem. I checked some templates first but I was not able to identify the right one. So I searched the web and I found the solution from this blog entry, Problem with WordPress 2.7.1 and images.

I was looking into several templates like link-template.php and post-template.php but did not think about the post.php file. With his solution, I was able to solve my problem that I told you in my previous blog entry.

This was the PHP function wp_get_attachment_url at WordPress 2.7.

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
		if ( ($uploads = wp_upload_dir()) && 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
		}
	}

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

If you read the blog entry where I found the solution, you will see there the present PHP function wp_get_attachment_url at WordPress 2.7.1.

I just commented (using // before each line) the following four lines which was added or included or inserted at the PHP function wp_get_attachment_url at the post.php when WordPress 2.7.1 was released. You will find post.php file under wp-includes folder.

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.

That’s it. That’s the solution to my gallery code problem. Thank you, emmanuel-georjon.

PHP,WordPress | 2 Comments »

2 Comments to “Solution to WordPress 2.7.1 Gallery Code Problem”

  1. [...] I just commented the particular codes which I already mentioned in my blog entry Solution to WordPress 2.7.1 Gallery Code Problem. [...]

  2. [...] have a problem with WordPress Image Gallery and you need a solution, kindly read this blog entry, Solution to WordPress 2.7.1 Gallery Code Problem. I have been having this problem with WordPress Image Gallery since upgrading to WordPress 2.7.1 [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word