Ensure that thumbnails are removed when the media file is deleted. Fixes #8309 props jacobsantos.

git-svn-id: https://develop.svn.wordpress.org/trunk@9846 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Westwood 2008-11-22 23:01:28 +00:00
parent 4c1fe59e34
commit 9b46a07ac6
1 changed files with 6 additions and 4 deletions

View File

@ -21,8 +21,8 @@
* @since 2.0.0
* @uses apply_filters() Calls 'get_attached_file' on file path and attachment ID.
*
* @param int $attachment_id Attachment ID
* @param bool $unfiltered Whether to apply filters or not
* @param int $attachment_id Attachment ID.
* @param bool $unfiltered Whether to apply filters or not.
* @return string The file path to the attached file.
*/
function get_attached_file( $attachment_id, $unfiltered = false ) {
@ -2418,12 +2418,14 @@ function wp_delete_attachment($postid) {
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE post_id = %d ", $postid ));
$uploadPath = wp_upload_dir();
if ( ! empty($meta['thumb']) ) {
// Don't delete the thumb if another attachment uses it
if (! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%'.$meta['thumb'].'%', $postid)) ) {
$thumbfile = str_replace(basename($file), $meta['thumb'], $file);
$thumbfile = apply_filters('wp_delete_file', $thumbfile);
@ unlink($thumbfile);
@ unlink( path_join($uploadPath['basedir'], $thumbfile) );
}
}
@ -2432,7 +2434,7 @@ function wp_delete_attachment($postid) {
foreach ( $sizes as $size ) {
if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
@ unlink($intermediate_file);
@ unlink( path_join($uploadPath['basedir'], $intermediate_file) );
}
}