[wp-hackers] Post thumbnail remains after image is trashed

John Ford john at aldenta.com
Thu Nov 19 03:19:57 UTC 2009


I'm starting to use the new 2.9 post-thumbnail feature and have run
into a little quirk.  If you assign a post-thumbnail a post, and then
trash the image, the post-thumbnail is still associated with the post.
 The reason this happens is that _thumbnail_id still exists in the
postmeta table and all the functions in post-image-templates.php rely
on the post meta.

I've thought of a couple of options for a patch but I'd like to get
some ideas and opinions about the best way to solve this before I dive
in.

1. Update get_post_image_id() in post-image-template.php to check if
the image has been trashed before returning the id. This adds a little
bit of extra overhead but would keep the post thumbnail in place if
they restore the image. One possible downside is that if the user
later restores the image from the Media page then they may be
surprised that the post thumbnail has also returned.

2. Delete the _thumbnail_id when the photo is trashed. This would mean
that if the user clicks Undo then the photo thumbnail is no longer
attached. It may be nice to delete the _thumbnail_id when a photo is
deleted anyway to keep the table a little more tidy.

Any thoughts on the best approach to this?   Should the user get
alerted about this happening?

http://core.trac.wordpress.org/ticket/11149

Thanks.

John


More information about the wp-hackers mailing list