Make WordPress Core

Ticket #55443: reintroduce-webp-default-output.diff

File reintroduce-webp-default-output.diff, 9.3 KB (added by adamsilverstein, 2 years ago)
  • src/wp-admin/includes/admin-filters.php

    diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php
    index e80c111dde..f5f9600332 100644
    a b add_filter( 'media_upload_library', 'media_upload_library' ); 
    3737
    3838add_filter( 'media_upload_tabs', 'update_gallery_tab' );
    3939
     40add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
     41
    4042// Admin color schemes.
    4143add_action( 'admin_init', 'register_admin_color_schemes', 1 );
    4244add_action( 'admin_head', 'wp_color_scheme_settings' );
  • src/wp-admin/includes/media.php

    diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php
    index 510fff563d..32455d1a5e 100644
    a b function wp_media_attach_action( $parent_id, $action = 'attach' ) { 
    38433843                exit;
    38443844        }
    38453845}
     3846
     3847/**
     3848 * Returns the default image output mapping.
     3849 *
     3850 * @since 6.1.0
     3851 */
     3852function wp_default_image_output_mapping() {
     3853        return array( 'image/jpeg' => 'image/webp' );
     3854}
  • src/wp-includes/class-wp-image-editor.php

    diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
    index caa3092d36..48472bb11f 100644
    a b abstract class WP_Image_Editor { 
    446446                $name    = wp_basename( $this->file, ".$ext" );
    447447                $new_ext = strtolower( $extension ? $extension : $ext );
    448448
     449                // When the file extension being generated doesn't match the original image file extension,
     450                // add the original extension to the suffix to ensure a unique file name. Prevents
     451                // generated file name conflicts when a source image type can have multiple extensions,
     452                // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions.
     453                if ( ! empty( $extension ) && $extension !== $ext ) {
     454                        $suffix .= "-{$ext}";
     455                }
     456
    449457                if ( ! is_null( $dest_path ) ) {
    450458                        if ( ! wp_is_stream( $dest_path ) ) {
    451459                                $_dest_path = realpath( $dest_path );
  • tests/phpunit/tests/ajax/MediaEdit.php

    diff --git a/tests/phpunit/tests/ajax/MediaEdit.php b/tests/phpunit/tests/ajax/MediaEdit.php
    index 686dae08c5..60e4cd2105 100644
    a b class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { 
    6767         */
    6868        public function testImageEditOverwriteConstant() {
    6969                define( 'IMAGE_EDIT_OVERWRITE', true );
     70                $files_that_shouldnt_exist = array();
    7071
    7172                require_once ABSPATH . 'wp-admin/includes/image-edit.php';
    7273
  • tests/phpunit/tests/image/editor.php

    diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php
    index 487dad0664..73e4ae8f8e 100644
    a b class Tests_Image_Editor extends WP_Image_UnitTestCase { 
    1818                require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
    1919
    2020                require_once DIR_TESTDATA . '/../includes/mock-image-editor.php';
     21                add_filter( 'image_editor_output_format', '__return_empty_array' );
    2122
    2223                // This needs to come after the mock image editor class is loaded.
    2324                parent::set_up();
    class Tests_Image_Editor extends WP_Image_UnitTestCase { 
    226227                $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) );
    227228
    228229                // Test with a suffix only.
    229                 $this->assertSame( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );
     230                $this->assertSame( 'canola-100x50-jpg.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );
    230231
    231232                // Combo!
    232                 $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
     233                $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new-jpg.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );
    233234
    234235                // Test with a stream destination.
    235236                $this->assertSame( 'file://testing/path/canola-100x50.jpg', $editor->generate_filename( null, 'file://testing/path' ) );
  • tests/phpunit/tests/image/editorGd.php

    diff --git a/tests/phpunit/tests/image/editorGd.php b/tests/phpunit/tests/image/editorGd.php
    index 5d967bdcdb..2e3828ffe8 100644
    a b class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    1717                require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
    1818                require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
    1919
     20                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
     21
    2022                // This needs to come after the mock image editor class is loaded.
    2123                parent::set_up();
    2224        }
  • tests/phpunit/tests/image/editorImagick.php

    diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php
    index 02e0590a2e..66e1014a03 100644
    a b class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    1818                require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
    1919                require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php';
    2020
     21                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
     22
    2123                // This needs to come after the mock image editor class is loaded.
    2224                parent::set_up();
    2325        }
  • tests/phpunit/tests/image/functions.php

    diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php
    index 86d559145e..2cc73fdfa9 100644
    a b class Tests_Image_Functions extends WP_UnitTestCase { 
    2525                foreach ( glob( $folder ) as $file ) {
    2626                        unlink( $file );
    2727                }
     28
     29                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
    2830        }
    2931
    3032        /**
  • tests/phpunit/tests/image/intermediateSize.php

    diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
    index 830359427a..df8d99ad91 100644
    a b class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    1515                parent::tear_down();
    1616        }
    1717
     18        /**
     19         * Set up the test fixture.
     20         */
     21        public function set_up() {
     22                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
     23
     24                parent::set_up();
     25        }
     26
    1827        public function _make_attachment( $file, $parent_post_id = 0 ) {
    1928                $contents = file_get_contents( $file );
    2029                $upload   = wp_upload_bits( wp_basename( $file ), null, $contents );
  • tests/phpunit/tests/image/resize.php

    diff --git a/tests/phpunit/tests/image/resize.php b/tests/phpunit/tests/image/resize.php
    index 5b302ce295..5043f4e4e6 100644
    a b abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase 
    1414                parent::set_up();
    1515
    1616                add_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) );
     17                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
    1718        }
    1819
    1920        public function wp_image_editors() {
  • tests/phpunit/tests/media.php

    diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
    index ba4bedf51e..e55a757767 100644
    a b CAP; 
    3333                self::$_sizes                          = wp_get_additional_image_sizes();
    3434                $GLOBALS['_wp_additional_image_sizes'] = array();
    3535
    36                 $filename       = DIR_TESTDATA . '/images/' . self::$large_filename;
     36                $filename = DIR_TESTDATA . '/images/' . self::$large_filename;
     37                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
    3738                self::$large_id = $factory->attachment->create_upload_object( $filename );
    3839
    3940                $post_statuses = array( 'publish', 'future', 'draft', 'auto-draft', 'trash' );
    EOF; 
    36173618                // Clean up the above filter.
    36183619                remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 );
    36193620        }
     3621
     3622        /**
     3623         * Test the wp_default_image_output_mapping function.
     3624         *
     3625         * @ticket 55443
     3626         */
     3627        public function test_wp_default_image_output_mapping() {
     3628                $mapping = wp_default_image_output_mapping();
     3629                $this->assertSame( array( 'image/jpeg' => 'image/webp' ), $mapping );
     3630        }
    36203631}
    36213632
    36223633/**
  • tests/phpunit/tests/post/attachments.php

    diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php
    index 2922c185d2..5aa507248a 100644
    a b  
    66 * @group upload
    77 */
    88class Tests_Post_Attachments extends WP_UnitTestCase {
     9        /**
     10         * Set up the test fixture.
     11         */
     12        public function set_up() {
     13                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
     14
     15                parent::set_up();
     16        }
    917
    1018        public function tear_down() {
    1119                // Remove all uploads.
  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

    diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
    index 106906ee2b..588a84d0ea 100644
    a b class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 
    9393
    9494                add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 );
    9595                add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 );
     96                remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' );
    9697        }
    9798
    9899        public function wpSetUpBeforeRequest( $result ) {