Remove intermediate images when deleting an attachment. Props tellyworth. fixes #6142

git-svn-id: http://svn.automattic.com/wordpress/trunk@7271 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-03-12 23:15:31 +00:00
parent 2e439f5810
commit 6d0fa72e1d
2 changed files with 20 additions and 3 deletions

View File

@ -84,7 +84,9 @@ function image_downsize($id, $size = 'medium') {
list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size ); list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size );
} }
return array( $img_url, $width, $height ); if ( $img_url)
return array( $img_url, $width, $height );
return false;
} }
@ -284,7 +286,14 @@ function image_get_intermediate_size($post_id, $size='thumbnail') {
if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) ) if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) )
return false; return false;
return $imagedata['sizes'][$size]; $data = $imagedata['sizes'][$size];
// include the full filesystem path of the intermediate file
if ( empty($data['path']) && !empty($data['file']) ) {
$file_url = wp_get_attachment_url($post_id);
$data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
$data['url'] = path_join( dirname($file_url), $data['file'] );
}
return $data;
} }
// get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images // get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images
@ -321,7 +330,6 @@ function wp_get_attachment_image($attachment_id, $size='thumbnail', $icon = fals
return $html; return $html;
} }
add_shortcode('gallery', 'gallery_shortcode'); add_shortcode('gallery', 'gallery_shortcode');
function gallery_shortcode($attr) { function gallery_shortcode($attr) {

View File

@ -2180,6 +2180,15 @@ function wp_delete_attachment($postid) {
} }
} }
// remove intermediate images if there are any
$sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium'));
foreach ( $sizes as $size ) {
if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
@ unlink($intermediate_file);
}
}
$file = apply_filters('wp_delete_file', $file); $file = apply_filters('wp_delete_file', $file);
if ( ! empty($file) ) if ( ! empty($file) )