Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/wp-admin/includes/image.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ function _wp_image_meta_replace_original( $saved_data, $original_file, $image_me
// Store the original image file name in image_meta.
$image_meta['original_image'] = wp_basename( $original_file );

// Update the post mime type when the new image was saved in a different format.
if ( isset( $saved_data['mime-type'] ) && get_post_mime_type( $attachment_id ) !== $saved_data['mime-type'] ) {
wp_update_post(
array(
'ID' => $attachment_id,
'post_mime_type' => $saved_data['mime-type'],
)
);
}

return $image_meta;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2867,9 +2867,11 @@ public function sideload_item( WP_REST_Request $request ) {
* The server writes sub-sizes in the attachment's output format without
* checking it against the network's allowed upload file types, so a
* sideload in that format is exempt from them too. Resolved before the
* output format filter below is added.
* output format filter below is added. When the filter leaves the format
* unchanged, as for a main file the server already converted, that is the
* attachment's own format.
*/
$output_format = wp_attachment_is_image( $post ) ? $this->get_image_output_format( $post ) : null;
$output_format = wp_attachment_is_image( $post ) ? ( $this->get_image_output_format( $post ) ?? get_post_mime_type( $post ) ) : null;
$output_extensions = null !== $output_format ? array_search( $output_format, wp_get_mime_types(), true ) : false;
$filter_filetypes = null;

Expand Down
4 changes: 4 additions & 0 deletions tests/phpunit/tests/media.php
Original file line number Diff line number Diff line change
Expand Up @@ -7657,6 +7657,7 @@ public function test_wp_img_tag_add_auto_sizes( string $input, string $expected
*
* @ticket 62305
* @ticket 62359
* @ticket 53665
*
* @dataProvider data_image_converted_to_other_format_has_correct_filename
*
Expand Down Expand Up @@ -7692,13 +7693,15 @@ public function test_heic_image_upload_is_converted_to_jpeg( bool $apply_big_ima
$this->assertSame( "test-image{$scaled_suffix}.jpg", basename( $image_meta['file'] ), "The file name is expected to be test-image{$scaled_suffix}.jpg" );
$this->assertSame( 'test-image.heic', $image_meta['original_image'], 'The original image name is expected to be stored in the meta data.' );
$this->assertSame( 'image/jpeg', wp_get_image_mime( $image_meta['file'] ), 'The image mime type is expected to be image/jpeg.' );
$this->assertSame( 'image/jpeg', get_post_mime_type( $attachment_id ), 'The attachment mime type is expected to be image/jpeg.' );
}

/**
* Ensure a JPEG is converted to WebP when applied via a filter.
*
* @ticket 62305
* @ticket 62359
* @ticket 53665
*
* @dataProvider data_image_converted_to_other_format_has_correct_filename
*
Expand Down Expand Up @@ -7737,6 +7740,7 @@ public function test_jpeg_image_converts_to_webp_when_filtered( bool $apply_big_
$this->assertSame( "33772{$scaled_suffix}.webp", basename( $image_meta['file'] ), "The file name is expected to be 33772{$scaled_suffix}.webp." );
$this->assertSame( '33772.jpg', $image_meta['original_image'], 'The original image name is expected to be stored in the meta data.' );
$this->assertSame( 'image/webp', wp_get_image_mime( $image_meta['file'] ), 'The image mime type is expected to be image/webp.' );
$this->assertSame( 'image/webp', get_post_mime_type( $attachment_id ), 'The attachment mime type is expected to be image/webp.' );
}

/**
Expand Down
Loading