Jul
29
2009

How to stop WordPress 2.8 from deleting enclosures

[update: this bug seems to be fixed in WordPress 2.9 Beta 2]

After a couple of days of agony thinking that my WordPress database was seriously messed up, I discovered the bug that was causing enclosures to disappear turns out be considered a “fix/feature” by WordPress Org.

WordPress 2.8 not only places auto-enclosures like previous versions of WordPress, but it also auto-removes enclosures if there’s no link to the media file in the post body.

To keep your enclosures from disappearing in 2.8, you can place a link to the media file in your post body…of course this may be a redundant link or an unwanted link.

Why anyone would want auto-enclosures is beyond me. This functionality is really annoying and problematic. It also saves no time as entering the URL in the enclosure field and then using the enclosure to place a download link where the post is displayed is much more efficient…and logical…aren’t these templates we’re talking about? Why would we duplicate copy and code in every post?

So to fix this fix without having to place the redundant link to the media file, you need to edit the file at:
../wp-includes/functions.php

Simply delete or comment out lines 1164-1168. They look like:
foreach ( $pung as $link_test ) {
if ( !in_array( $link_test, $post_links_temp[0] ) ) { // link no longer in post
$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id = %d AND meta_key = 'enclosure' AND meta_value LIKE (%s)", $post_ID, $link_test . '%') );
}
}

Unfortunately of course this code will be added back again if you update WordPress (unless they see the error of their ways).

I would love to offer this as a free plug-in, but I don’t think there are any hooks for this in the WordPress API. I could be wrong as I’m not experienced at all in plug-in development for WordPress.

Discussions about this issue are taking place on WordPress.org.

  • Share/Bookmark

4 Comments »

  • There is a way to add this logic as a plugin to prevent WordPress from doing this behavior. We added the exact logic to the Blubrry PowerPress podcasting plugin. If you don’t specify that you want to make a podcast episode, then you don’t make a podcast episode, whether or not you have links to media in your posts.

    I’ve left a comment on the WordPress.org trac system with some thoughts on the problem and included my own suggested solution. Here’s a link: http://core.trac.wordpress.org/ticket/10511

  • Scott says:

    Thanks much Kevin! I had 3 episodes not feeding because of this and didn’t even realize it… awesome!

  • Tried this, and it made absolutely no difference, which I find baffling.

  • kevine says:

    Hmmm…I’m not sure how that’s possible, but I’ve found that the WordPress team did listen to our complaints and fixed this in 2.9.x, so maybe just upgrading will help you.

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com