Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
Merged
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
28 changes: 24 additions & 4 deletions modules/images/webp-uploads/image-edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_t

foreach ( $old_metadata['sizes'] as $size_name => $size_details ) {
// If the target is 'nothumb', skip generating the 'thumbnail' size.
if ( 'nothumb' === $target && 'thumbnail' === $size_name ) {
if ( webp_uploads_image_edit_thumbnails_separately() && 'nothumb' === $target && 'thumbnail' === $size_name ) {
continue;
}

Expand All @@ -150,7 +150,7 @@ static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_t
foreach ( $mime_transforms as $targeted_mime ) {
if ( $targeted_mime === $mime_type ) {
// If the target is `thumbnail` make sure it is the only selected size.
if ( 'thumbnail' === $target ) {
if ( webp_uploads_image_edit_thumbnails_separately() && 'thumbnail' === $target ) {
if ( isset( $metadata['sizes']['thumbnail'] ) ) {
$subsized_images[ $targeted_mime ] = array( 'thumbnail' => $metadata['sizes']['thumbnail'] );
}
Expand Down Expand Up @@ -178,7 +178,7 @@ static function ( $metadata, $post_meta_id ) use ( $post_id, $file_path, $mime_t
$extension = $extension[0];

// If the target is `thumbnail` make sure only that size is generated.
if ( 'thumbnail' === $target ) {
if ( webp_uploads_image_edit_thumbnails_separately() && 'thumbnail' === $target ) {
if ( ! isset( $subsized_images[ $mime_type ]['thumbnail']['file'] ) ) {
continue;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ function webp_uploads_backup_sources( $attachment_id, $data ) {
$target = isset( $_REQUEST['target'] ) ? sanitize_key( $_REQUEST['target'] ) : 'all';

// When an edit to an image is only applied to a thumbnail there's nothing we need to back up.
if ( 'thumbnail' === $target ) {
if ( webp_uploads_image_edit_thumbnails_separately() && 'thumbnail' === $target ) {
return $data;
}

Expand Down Expand Up @@ -420,3 +420,23 @@ function webp_uploads_restore_image( $attachment_id, $data ) {

return $data;
}

/**
* Compatibility function to check whether editing image thumbnails separately is enabled.
*
* The filter {@see 'image_edit_thumbnails_separately'} was introduced in WordPress 6.3 with default value of `false`,
* for a behavior that previously was always enabled.
*
* @since n.e.x.t
* @see https://core.trac.wordpress.org/ticket/57685
*
* @return bool True if editing image thumbnails is enabled, false otherwise.
*/
function webp_uploads_image_edit_thumbnails_separately() {
if ( version_compare( get_bloginfo( 'version' ), '6.3', '<' ) ) {
return true;
}

/** This filter is documented in wp-admin/includes/image-edit.php */
return (bool) apply_filters( 'image_edit_thumbnails_separately', false );
}
6 changes: 5 additions & 1 deletion modules/images/webp-uploads/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Contributors: wordpressdotorg
Requires at least: 6.1
Tested up to: 6.3
Requires PHP: 5.6
Stable tag: 1.0.1
Stable tag: 1.0.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Tags: performance, images, webp
Expand Down Expand Up @@ -58,6 +58,10 @@ By default, the WebP Uploads plugin will only generate WebP versions of the imag

== Changelog ==

= 1.0.2 =

* Fix WebP handling when editing images based on WordPress 6.3 change. ([796](https://github.com/WordPress/performance/pull/796))

= 1.0.1 =

* Bump tested up to version to 6.3. ([772](https://github.com/WordPress/performance/pull/772))
Expand Down
2 changes: 1 addition & 1 deletion plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
},
"images/webp-uploads": {
"slug": "webp-uploads",
"version": "1.0.1"
"version": "1.0.2"
}
}
8 changes: 8 additions & 0 deletions tests/modules/images/fetchpriority/fetchpriority-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ public static function tear_down_after_class() {
parent::tear_down_after_class();
}

public function set_up() {
parent::set_up();

if ( ! perflab_can_load_module( 'images/fetchpriority' ) ) {
$this->markTestSkipped( 'Fetchpriority module tests irrelevant since available in WordPress core' );
}
}

public function test_fetchpriority_img_tag_add_attr_based_on_context_and_loading_lazy() {
$img = get_image_tag( self::$attachment_id, '', '', '', 'large' );

Expand Down
12 changes: 12 additions & 0 deletions tests/modules/images/webp-uploads/image-edit-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ public function it_should_prevent_to_back_up_the_sources_when_the_sources_attrib
* @test
*/
public function it_should_prevent_to_backup_the_full_size_image_if_only_the_thumbnail_is_edited() {
if ( ! webp_uploads_image_edit_thumbnails_separately() ) {
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

// Create JPEG and WebP.
$this->opt_in_to_jpeg_and_webp();

Expand Down Expand Up @@ -195,6 +199,10 @@ public function it_should_prevent_to_backup_the_full_size_image_if_only_the_thum
* @test
*/
public function it_should_backup_the_image_when_all_images_except_the_thumbnail_are_updated() {
if ( ! webp_uploads_image_edit_thumbnails_separately() ) {
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

$attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' );
$metadata = wp_get_attachment_metadata( $attachment_id );

Expand Down Expand Up @@ -236,6 +244,10 @@ public function it_should_backup_the_image_when_all_images_except_the_thumbnail_
* @test
*/
public function it_should_use_the_attached_image_when_updating_subsequent_images_not_the_original_version() {
if ( ! webp_uploads_image_edit_thumbnails_separately() ) {
$this->markTestSkipped( 'Editing image thumbnails separately is disabled' );
}

// The leafs image is 1080 pixels wide with this filter we ensure a -scaled version is created for this test.
add_filter(
'big_image_size_threshold',
Expand Down