From fd4e3023d6aa21e2a7d336345d991c654b2cd3c3 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 2 Oct 2014 15:32:16 +0000 Subject: [PATCH] In `wp_delete_attachment()`: account for orphan sizes by looping over the sizes stored in metadata, instead of relying on the current sizes stored in `$_wp_additional_image_sizes`. Props JoshuaAbenazer, desrosj, markoheijnen. Fixes #24518. Built from https://develop.svn.wordpress.org/trunk@29816 git-svn-id: http://core.svn.wordpress.org/trunk@29582 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 170e2e31dc..e9d93172fe 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4771,12 +4771,6 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { $backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true ); $file = get_attached_file( $post_id ); - $intermediate_sizes = array(); - foreach ( get_intermediate_image_sizes() as $size ) { - if ( $intermediate = image_get_intermediate_size( $post_id, $size ) ) - $intermediate_sizes[] = $intermediate; - } - if ( is_multisite() ) delete_transient( 'dirsize_cache' ); @@ -4825,10 +4819,13 @@ function wp_delete_attachment( $post_id, $force_delete = false ) { } // Remove intermediate and backup images if there are any. - foreach ( $intermediate_sizes as $intermediate ) { - /** This filter is documented in wp-admin/custom-header.php */ - $intermediate_file = apply_filters( 'wp_delete_file', $intermediate['path'] ); - @ unlink( path_join($uploadpath['basedir'], $intermediate_file) ); + if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) { + foreach ( $meta['sizes'] as $size => $sizeinfo ) { + $intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file ); + /** This filter is documented in wp-admin/custom-header.php */ + $intermediate_file = apply_filters( 'wp_delete_file', $intermediate_file ); + @ unlink( path_join( $uploadpath['basedir'], $intermediate_file ) ); + } } if ( is_array($backup_sizes) ) {