From 5cbec1348bf159844c572e4ff89043f4b95ca37a Mon Sep 17 00:00:00 2001 From: Peter Wilson Date: Wed, 9 Oct 2024 23:32:21 +0000 Subject: [PATCH] Media: Update file size meta data when editing images. Fixes an error in which the file size meta data retained the original upload's values follow a user editing the images in the media screen. The original images' file sizes are now stored in the backup image data to allow for them to be restored when a user restores the original image. Props ankit-k-gupta, antpb, audrasjb, chaion07, gauravsingh7, joedolson, oglekler, pls78, rajinsharwar, sayedulsayem, vertisoft. Fixes #59684. Built from https://develop.svn.wordpress.org/trunk@59202 git-svn-id: http://core.svn.wordpress.org/trunk@58597 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/image-edit.php | 32 ++++++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 5417eac45e..7f9ebf7f9f 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -826,9 +826,10 @@ function wp_restore_image( $post_id ) { } } elseif ( isset( $meta['width'], $meta['height'] ) ) { $backup_sizes[ "full-$suffix" ] = array( - 'width' => $meta['width'], - 'height' => $meta['height'], - 'file' => $parts['basename'], + 'width' => $meta['width'], + 'height' => $meta['height'], + 'filesize' => $meta['filesize'], + 'file' => $parts['basename'], ); } } @@ -839,6 +840,14 @@ function wp_restore_image( $post_id ) { $meta['file'] = _wp_relative_upload_path( $restored_file ); $meta['width'] = $data['width']; $meta['height'] = $data['height']; + if ( isset( $data['filesize'] ) ) { + /* + * Restore the original filesize if it was backed up. + * + * See https://core.trac.wordpress.org/ticket/59684. + */ + $meta['filesize'] = $data['filesize']; + } } foreach ( $default_sizes as $default_size ) { @@ -997,8 +1006,9 @@ function wp_save_image( $post_id ) { } } + $saved_image = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ); // Save the full-size file, also needed to create sub-sizes. - if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { + if ( ! $saved_image ) { $return->error = esc_js( __( 'Unable to save the image.' ) ); return $return; } @@ -1018,9 +1028,10 @@ function wp_save_image( $post_id ) { if ( $tag ) { $backup_sizes[ $tag ] = array( - 'width' => $meta['width'], - 'height' => $meta['height'], - 'file' => $basename, + 'width' => $meta['width'], + 'height' => $meta['height'], + 'filesize' => $meta['filesize'], + 'file' => $basename, ); } @@ -1028,9 +1039,10 @@ function wp_save_image( $post_id ) { $meta['file'] = _wp_relative_upload_path( $new_path ); - $size = $img->get_size(); - $meta['width'] = $size['width']; - $meta['height'] = $size['height']; + $size = $img->get_size(); + $meta['width'] = $size['width']; + $meta['height'] = $size['height']; + $meta['filesize'] = $saved_image['filesize']; if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) { $sizes = get_intermediate_image_sizes(); diff --git a/wp-includes/version.php b/wp-includes/version.php index 28a65b5852..49df52e28e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.7-beta2-59201'; +$wp_version = '6.7-beta2-59202'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.