Make WordPress Core


Ignore:
Timestamp:
10/07/2022 07:15:59 PM (2 years ago)
Author:
adamsilverstein
Message:

Media: ensure the wp_editor_set_quality filter consistently passes the correct output mime type.

Ensure that the mime type passed to the wp_editor_set_quality filter is correct when the output format is altered with the image_editor_output_format filter and the image is saved multiple times, for example when generating sub sizes. Previously, the original image mime type was passed instead of the output type after the initial save.

Props flixos90, peterwilsoncc.
Fixes #56442.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/editor.php

    r54226 r54417  
    106106        // Ensure wp_editor_set_quality filter applies if it exists before editor instantiation.
    107107        $this->assertSame( 100, $editor->get_quality() );
    108 
    109         // Clean up.
    110         remove_filter( 'wp_editor_set_quality', $func_100_percent );
    111108    }
    112109
     
    120117        $editor->set_mime_type( 'image/png' ); // Ensure mime-specific filters act properly.
    121118
     119        // Quality setting for the source image. For PNG the fallback default of 82 is used.
     120        $this->assertSame( 82, $editor->get_quality(), 'Default quality setting is 82.' );
     121
    122122        // Set conversions for uploaded images.
    123123        add_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) );
     
    126126        $this->assertSame( 82, $editor->get_quality(), 'Default quality setting is 82.' );
    127127
    128         // Quality should change to the output format's value.
    129         // A PNG image will be converted to WEBP whose quialty should be 86.
    130         $editor->save();
    131         $this->assertSame( 86, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 86.' );
    132 
    133         // Removing PNG to WEBP conversion on save. Quality setting should reset to the default.
     128        // When saving, quality should change to the output format's value.
     129        // A PNG image will be converted to WebP whose quality should be 86.
     130        $editor->save();
     131        $this->assertSame( 86, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 86.' );
     132
     133        // Saving again should not change the quality.
     134        $editor->save();
     135        $this->assertSame( 86, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 86.' );
     136
     137        // Removing PNG to WebP conversion on save. Quality setting should reset to the default.
    134138        remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) );
    135139        $editor->save();
     
    150154
    151155        // Quality should change to the output format's value as filtered above.
    152         // A JPEG image will be converted to WEBP whose quialty should be 42.
    153         $editor->save();
    154         $this->assertSame( 42, $editor->get_quality(), 'Image conversion from JPEG to WEBP. Filtered WEBP quality shoild be 42.' );
     156        // A JPEG image will be converted to WebP whose quialty should be 42.
     157        $editor->save();
     158        $this->assertSame( 42, $editor->get_quality(), 'Image conversion from JPEG to WEBP. Filtered WEBP quality should be 42.' );
    155159
    156160        // After removing the conversion the quality setting should reset to the filtered value for the original image type, JPEG.
     
    162166            'After removing image conversion the quality setting should reset to the filtered value for JPEG, 56.'
    163167        );
    164 
    165         remove_filter( 'wp_editor_set_quality', array( $this, 'image_editor_change_quality' ) );
    166168    }
    167169
Note: See TracChangeset for help on using the changeset viewer.