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
This commit is contained in:
parent
468dc35b8b
commit
fd4e3023d6
|
@ -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 );
|
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
|
||||||
$file = get_attached_file( $post_id );
|
$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() )
|
if ( is_multisite() )
|
||||||
delete_transient( 'dirsize_cache' );
|
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.
|
// Remove intermediate and backup images if there are any.
|
||||||
foreach ( $intermediate_sizes as $intermediate ) {
|
if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
|
||||||
/** This filter is documented in wp-admin/custom-header.php */
|
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
||||||
$intermediate_file = apply_filters( 'wp_delete_file', $intermediate['path'] );
|
$intermediate_file = str_replace( basename( $file ), $sizeinfo['file'], $file );
|
||||||
@ unlink( path_join($uploadpath['basedir'], $intermediate_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) ) {
|
if ( is_array($backup_sizes) ) {
|
||||||
|
|
Loading…
Reference in New Issue