WordPress Enclosure Fix

So, I’m setting up a website and it uses WordPress. One cool featutre of wordpress 1.5 is that it will automatically add enclosure tags for media files you link to in your posts. (this lets bloggers easily become podcasters and video bloggers)

However, the feature doesn’t work if you use a hosting service for your media files whose published permalink to the media file issues a redirect behind the scenes to the actual file at a different uri. Most services do this I think. Blip.tv, OurMedia, The Archive, etc. (Just for clarity sake: This is not a problem with the hosting, but rather a limitation in wordpress.)

Anyway, I wrote up a quick modifcation to the wordpress code to allow for this. If you use word press and would like to use it’s auto-enclosure feature but it’s not working because you are using a hosting provider for your media files, here’s how you can fix it (in most cases).

Edit the wp-includes/functions.php file

FIND:


Code:
for ( $i = 0; $i < $count; $i++) {

$key = strtolower($matches[1][$i]);

$headers["$key"] = $matches[2][$i];

}



(the above should be around line line 818)

AFTER the above code, ADD:


Code:
$headers[’status_code’] = substr($response,0,strpos( $response, "\r\n", 0));

FIND:


Code:
if ( $headers = wp_get_http_headers( $url) ) {



(the above should be around line 783)

AFTER the above code, ADD:


Code:
if ($headers[’status_code’] == ‘HTTP/1.1 302 Found’ )

{

$headers = wp_get_http_headers($headers[’location’]);

}

SAVE

There you have it. WordPress will now correctly add enclosures for the media files you link to in your blogs.

NOTE: use at your own risk, but it’s working for me.

  • do you remember watching the old Peanuts cartoons? You know, like “It’s the great pumpkin, Charlie Brown”, that kind of thing? And, when the adults talked to the children it was all garbled bullshit “waa waa waaa waaaa”? That is so what I got off that post. But, dammit, I read it anyway! I didn’t make on F-ing bit of sense to me, but I read it. Now, that is dedication. Or obsession. Now that I think about it, it’s probably obsession.

You can follow any responses to this entry through the RSS 2.0 feed.