diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index c614a7793e..2a6f6af0ea 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -825,6 +825,21 @@ function wp_save_image( $post_id ) { $success = $delete = $nocrop = true; } + /* + * We need to remove any existing resized image files because + * a new crop or rotate could generate different sizes (and hence, filenames), + * keeping the new resized images from overwriting the existing image files. + * https://core.trac.wordpress.org/ticket/32171 + */ + if ( defined( 'IMAGE_EDIT_OVERWRITE' ) && IMAGE_EDIT_OVERWRITE && ! empty( $meta['sizes'] ) ) { + foreach ( $meta['sizes'] as $size ) { + if ( ! empty( $size['file'] ) && preg_match( '/-e[0-9]{13}-/', $size['file'] ) ) { + $delete_file = path_join( $path_parts['dirname'], $size['file'] ); + wp_delete_file( $delete_file ); + } + } + } + if ( isset( $sizes ) ) { $_sizes = array(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 43bc0baa91..f02e1a75a2 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.6-beta3-38112'; +$wp_version = '4.6-beta3-38113'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.