mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-22 09:07:59 +01:00
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
This commit is contained in:
parent
a74b414813
commit
5cbec1348b
@ -826,9 +826,10 @@ function wp_restore_image( $post_id ) {
|
|||||||
}
|
}
|
||||||
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
|
} elseif ( isset( $meta['width'], $meta['height'] ) ) {
|
||||||
$backup_sizes[ "full-$suffix" ] = array(
|
$backup_sizes[ "full-$suffix" ] = array(
|
||||||
'width' => $meta['width'],
|
'width' => $meta['width'],
|
||||||
'height' => $meta['height'],
|
'height' => $meta['height'],
|
||||||
'file' => $parts['basename'],
|
'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['file'] = _wp_relative_upload_path( $restored_file );
|
||||||
$meta['width'] = $data['width'];
|
$meta['width'] = $data['width'];
|
||||||
$meta['height'] = $data['height'];
|
$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 ) {
|
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.
|
// 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->error = esc_js( __( 'Unable to save the image.' ) );
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
@ -1018,9 +1028,10 @@ function wp_save_image( $post_id ) {
|
|||||||
|
|
||||||
if ( $tag ) {
|
if ( $tag ) {
|
||||||
$backup_sizes[ $tag ] = array(
|
$backup_sizes[ $tag ] = array(
|
||||||
'width' => $meta['width'],
|
'width' => $meta['width'],
|
||||||
'height' => $meta['height'],
|
'height' => $meta['height'],
|
||||||
'file' => $basename,
|
'filesize' => $meta['filesize'],
|
||||||
|
'file' => $basename,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1028,9 +1039,10 @@ function wp_save_image( $post_id ) {
|
|||||||
|
|
||||||
$meta['file'] = _wp_relative_upload_path( $new_path );
|
$meta['file'] = _wp_relative_upload_path( $new_path );
|
||||||
|
|
||||||
$size = $img->get_size();
|
$size = $img->get_size();
|
||||||
$meta['width'] = $size['width'];
|
$meta['width'] = $size['width'];
|
||||||
$meta['height'] = $size['height'];
|
$meta['height'] = $size['height'];
|
||||||
|
$meta['filesize'] = $saved_image['filesize'];
|
||||||
|
|
||||||
if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
|
if ( $success && ( 'nothumb' === $target || 'all' === $target ) ) {
|
||||||
$sizes = get_intermediate_image_sizes();
|
$sizes = get_intermediate_image_sizes();
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user