Make WordPress Core

Ticket #56288: 56288.5.diff

File 56288.5.diff, 16.9 KB (added by adamsilverstein, 22 months ago)
  • src/wp-admin/includes/image.php

    diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
    index b0cffc504f..d3d65fead1 100644
    function _wp_filter_image_sizes_additional_mime_type_support( $sizes, $attachmen 
    672672                'medium'         => true,
    673673                'medium_large'   => true,
    674674                'large'          => true,
    675                 'post-thumbnail' => true,
    676675        );
    677676
     677        // Include any sizes that were added with `add_image_size`.
     678        $additional_image_sizes = array_map(
     679                '__return_true',
     680                array_filter(
     681                        wp_get_additional_image_sizes(),
     682                        function( $size ) {
     683                                return isset( $size['additional_mimes'] ) && $size['additional_mimes'];
     684                        }
     685                )
     686        );
     687        $enabled_sizes          = array_merge( $enabled_sizes, $additional_image_sizes );
     688
    678689        /**
    679690         * Filter the sizes that support secondary mime type output. Developers can use this
    680691         * to control the output of additional mime type sub-sized images.
  • src/wp-content/themes/twentyeleven/functions.php

    diff --git src/wp-content/themes/twentyeleven/functions.php src/wp-content/themes/twentyeleven/functions.php
    index 12593aaddf..ee95afd96b 100644
    if ( ! function_exists( 'twentyeleven_setup' ) ) : 
    227227                 * Add Twenty Eleven's custom image sizes.
    228228                 * Used for large feature (header) images.
    229229                 */
    230                 add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
     230                add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true, true );
    231231                // Used for featured posts if a large-feature doesn't exist.
    232                 add_image_size( 'small-feature', 500, 300 );
     232                add_image_size( 'small-feature', 500, 300, false, true );
    233233
    234234                // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
    235235                register_default_headers(
  • src/wp-content/themes/twentyfourteen/functions.php

    diff --git src/wp-content/themes/twentyfourteen/functions.php src/wp-content/themes/twentyfourteen/functions.php
    index 0695bcce6d..0896f84410 100644
    if ( ! function_exists( 'twentyfourteen_setup' ) ) : 
    122122                // Enable support for Post Thumbnails, and declare two sizes.
    123123                add_theme_support( 'post-thumbnails' );
    124124                set_post_thumbnail_size( 672, 372, true );
    125                 add_image_size( 'twentyfourteen-full-width', 1038, 576, true );
     125                add_image_size( 'twentyfourteen-full-width', 1038, 576, true, true );
    126126
    127127                // This theme uses wp_nav_menu() in two locations.
    128128                register_nav_menus(
  • src/wp-content/themes/twentyseventeen/functions.php

    diff --git src/wp-content/themes/twentyseventeen/functions.php src/wp-content/themes/twentyseventeen/functions.php
    index 3d933989c2..d8b95b8568 100644
    function twentyseventeen_setup() { 
    5656         */
    5757        add_theme_support( 'post-thumbnails' );
    5858
    59         add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
     59        add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true, true );
    6060
    61         add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
     61        add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true, true );
    6262
    6363        // Set the default content width.
    6464        $GLOBALS['content_width'] = 525;
  • src/wp-content/themes/twentytwenty/functions.php

    diff --git src/wp-content/themes/twentytwenty/functions.php src/wp-content/themes/twentytwenty/functions.php
    index c8944e03c1..21a561fdaf 100644
    function twentytwenty_theme_support() { 
    6363        set_post_thumbnail_size( 1200, 9999 );
    6464
    6565        // Add custom image size used in Cover Template.
    66         add_image_size( 'twentytwenty-fullscreen', 1980, 9999 );
     66        add_image_size( 'twentytwenty-fullscreen', 1980, 9999, false, true );
    6767
    6868        // Custom logo.
    6969        $logo_width  = 120;
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 456cd7c988..1b0eab52c7 100644
    function image_downsize( $id, $size = 'medium' ) { 
    275275 * Register a new image size.
    276276 *
    277277 * @since 2.9.0
     278 * @since 6.1.0 Add the $additional_mimes parameter.
    278279 *
    279280 * @global array $_wp_additional_image_sizes Associative array of additional image sizes.
    280281 *
    281  * @param string     $name   Image size identifier.
    282  * @param int        $width  Optional. Image width in pixels. Default 0.
    283  * @param int        $height Optional. Image height in pixels. Default 0.
    284  * @param bool|array $crop   Optional. Image cropping behavior. If false, the image will be scaled (default),
    285  *                           If true, image will be cropped to the specified dimensions using center positions.
    286  *                           If an array, the image will be cropped using the array to specify the crop location.
    287  *                           Array values must be in the format: array( x_crop_position, y_crop_position ) where:
    288  *                               - x_crop_position accepts: 'left', 'center', or 'right'.
    289  *                               - y_crop_position accepts: 'top', 'center', or 'bottom'.
     282 * @param string     $name             Image size identifier.
     283 * @param int        $width            Optional. Image width in pixels. Default 0.
     284 * @param int        $height           Optional. Image height in pixels. Default 0.
     285 * @param bool|array $crop             Optional. Image cropping behavior. If false, the image will be scaled (default),
     286 *                                     If true, image will be cropped to the specified dimensions using center positions.
     287 *                                     If an array, the image will be cropped using the array to specify the crop location.
     288 *                                     Array values must be in the format: array( x_crop_position, y_crop_position ) where:
     289 *                                         - x_crop_position accepts: 'left', 'center', or 'right'.
     290 *                                         - y_crop_position accepts: 'top', 'center', or 'bottom'.
     291 * @param bool|null  $additional_mimes Optional. Whether to output secondary mimes for this image size. If not passed,
     292 *                                     WordPres core will determine whether true or false. Sizes should be registered
     293 *                                     with false only if they are not intended for use in a front-end context.
    290294 */
    291 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
     295function add_image_size( $name, $width = 0, $height = 0, $crop = false, $additional_mimes = null ) {
    292296        global $_wp_additional_image_sizes;
    293297
     298        // Trigger a warning if the size was registered without providing an `additional_mimes` parameter.
     299        if ( null === $additional_mimes ) {
     300                _doing_it_wrong(
     301                        __FUNCTION__,
     302                        sprintf(
     303                                /* translators: %s: additional_mimes variable */
     304                                __( 'You should provide a boolean value for the %s parameter.' ),
     305                                '<code>$additional_mimes</code>'
     306                        ),
     307                        '6.1.0'
     308                );
     309                $additional_mimes = false;
     310        }
     311
    294312        $_wp_additional_image_sizes[ $name ] = array(
    295                 'width'  => absint( $width ),
    296                 'height' => absint( $height ),
    297                 'crop'   => $crop,
     313                'width'            => absint( $width ),
     314                'height'           => absint( $height ),
     315                'crop'             => $crop,
     316                'additional_mimes' => $additional_mimes,
    298317        );
    299318}
    300319
    function remove_image_size( $name ) { 
    345364 *                           An array can specify positioning of the crop area. Default false.
    346365 */
    347366function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
    348         add_image_size( 'post-thumbnail', $width, $height, $crop );
     367        add_image_size( 'post-thumbnail', $width, $height, $crop, true );
    349368}
    350369
    351370/**
    function wp_media_personal_data_exporter( $email_address, $page = 1 ) { 
    53165335 */
    53175336function _wp_add_additional_image_sizes() {
    53185337        // 2x medium_large size.
    5319         add_image_size( '1536x1536', 1536, 1536 );
     5338        add_image_size( '1536x1536', 1536, 1536, false, true );
    53205339        // 2x large size.
    5321         add_image_size( '2048x2048', 2048, 2048 );
     5340        add_image_size( '2048x2048', 2048, 2048, false, true );
    53225341}
    53235342
    53245343/**
  • tests/phpunit/tests/image/functions.php

    diff --git tests/phpunit/tests/image/functions.php tests/phpunit/tests/image/functions.php
    index cb5a7971c9..dd0ad5e609 100644
    class Tests_Image_Functions extends WP_UnitTestCase { 
    857857
    858858                $this->assertNotEmpty( $attachment_id );
    859859
    860                 add_image_size( 'test-size', 100, 100 );
     860                add_image_size( 'test-size', 100, 100, false, false );
    861861                add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 );
    862862
    863863                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
  • tests/phpunit/tests/image/intermediateSize.php

    diff --git tests/phpunit/tests/image/intermediateSize.php tests/phpunit/tests/image/intermediateSize.php
    index 830359427a..517bc8c5b2 100644
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    9393         * @requires function imagejpeg
    9494         */
    9595        public function test_get_intermediate_sizes_by_name() {
    96                 add_image_size( 'test-size', 330, 220, true );
     96                add_image_size( 'test-size', 330, 220, true, false );
    9797
    9898                $file = DIR_TESTDATA . '/images/waffles.jpg';
    9999                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    115115         */
    116116        public function test_get_intermediate_sizes_by_array_exact() {
    117117                // Only one dimention match shouldn't return false positive (see: #17626).
    118                 add_image_size( 'test-size', 330, 220, true );
    119                 add_image_size( 'false-height', 330, 400, true );
    120                 add_image_size( 'false-width', 600, 220, true );
     118                add_image_size( 'test-size', 330, 220, true, false );
     119                add_image_size( 'false-height', 330, 400, true, false );
     120                add_image_size( 'false-width', 600, 220, true, false );
    121121
    122122                $file = DIR_TESTDATA . '/images/waffles.jpg';
    123123                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    138138        public function test_get_intermediate_sizes_by_array_nearest() {
    139139                // If an exact size is not found, it should be returned.
    140140                // If not, find nearest size that is larger (see: #17626).
    141                 add_image_size( 'test-size', 450, 300, true );
    142                 add_image_size( 'false-height', 330, 100, true );
    143                 add_image_size( 'false-width', 150, 220, true );
     141                add_image_size( 'test-size', 450, 300, true, false );
     142                add_image_size( 'false-height', 330, 100, true, false );
     143                add_image_size( 'false-width', 150, 220, true, false );
    144144
    145145                $file = DIR_TESTDATA . '/images/waffles.jpg';
    146146                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    161161        public function test_get_intermediate_sizes_by_array_nearest_false() {
    162162                // If an exact size is not found, it should be returned.
    163163                // If not, find nearest size that is larger, otherwise return false (see: #17626).
    164                 add_image_size( 'false-height', 330, 100, true );
    165                 add_image_size( 'false-width', 150, 220, true );
     164                add_image_size( 'false-height', 330, 100, true, false );
     165                add_image_size( 'false-width', 150, 220, true, false );
    166166
    167167                $file = DIR_TESTDATA . '/images/waffles.jpg';
    168168                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    185185                $width = 300;
    186186
    187187                // Only one dimention match shouldn't return false positive (see: #17626).
    188                 add_image_size( 'test-size', $width, 0, false );
    189                 add_image_size( 'false-height', $width, 100, true );
     188                add_image_size( 'test-size', $width, 0, false, false );
     189                add_image_size( 'false-height', $width, 100, true, false );
    190190
    191191                $file = DIR_TESTDATA . '/images/waffles.jpg';
    192192                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    214214                $height = 202;
    215215
    216216                // Only one dimention match shouldn't return false positive (see: #17626).
    217                 add_image_size( 'test-size', 0, $height, false );
    218                 add_image_size( 'false-height', 300, $height, true );
     217                add_image_size( 'test-size', 0, $height, false, false );
     218                add_image_size( 'false-height', 300, $height, true, false );
    219219
    220220                $file = DIR_TESTDATA . '/images/waffles.jpg';
    221221                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    242242                // Original is 600x400. 300x201 is close enough to match.
    243243                $width  = 300;
    244244                $height = 201;
    245                 add_image_size( 'off-by-one', $width, $height, true );
     245                add_image_size( 'off-by-one', $width, $height, true, false );
    246246
    247247                $file = DIR_TESTDATA . '/images/waffles.jpg';
    248248                $id   = $this->_make_attachment( $file, 0 );
    class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 
    264264         */
    265265        public function test_get_intermediate_size_with_small_size_array() {
    266266                // Add a hard cropped size that matches the aspect ratio we're going to test.
    267                 add_image_size( 'test-size', 200, 100, true );
     267                add_image_size( 'test-size', 200, 100, true, false );
    268268
    269269                $file = DIR_TESTDATA . '/images/waffles.jpg';
    270270                $id   = $this->_make_attachment( $file, 0 );
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index daf585d548..ee246b1d2f 100644
    VIDEO; 
    11421142                remove_image_size( 'test-size' );
    11431143
    11441144                $this->assertArrayNotHasKey( 'test-size', $_wp_additional_image_sizes );
    1145                 add_image_size( 'test-size', 200, 600 );
     1145                add_image_size( 'test-size', 200, 600, false, false );
    11461146
    11471147                $sizes = wp_get_additional_image_sizes();
    11481148
    VIDEO; 
    11541154                $this->assertSame( 600, $sizes['test-size']['height'] );
    11551155        }
    11561156
     1157        /**
     1158         * @ticket 56288
     1159         */
     1160        public function test_add_image_size_additional_mimes() {
     1161                add_image_size( 'test-size-with-additional-mimes', 200, 600, false, true );
     1162                add_image_size( 'test-size-without-additional-mimes', 200, 600, false, false );
     1163
     1164                $sizes = wp_get_additional_image_sizes();
     1165
     1166                remove_image_size( 'test-size-with-additional-mimes' );
     1167                remove_image_size( 'test-size-without-additional-mimes' );
     1168
     1169                $this->assertArrayHasKey( 'test-size-with-additional-mimes', $sizes );
     1170                $this->assertArrayHasKey( 'test-size-without-additional-mimes', $sizes );
     1171                $this->assertTrue( $sizes['test-size-with-additional-mimes']['additional_mimes'] );
     1172                $this->assertFalse( $sizes['test-size-without-additional-mimes']['additional_mimes'] );
     1173        }
     1174
     1175        /**
     1176         * @ticket 56288
     1177         */
     1178        public function test__wp_filter_image_sizes_additional_mime_type_support_with_add_image_size() {
     1179                $default_sizes = wp_get_registered_image_subsizes();
     1180
     1181                add_image_size( 'test-size-with-additional-mimes', 200, 600, false, true );
     1182                add_image_size( 'test-size-without-additional-mimes', 200, 600, false, false );
     1183
     1184                $all_sizes      = wp_get_registered_image_subsizes();
     1185                $filtered_sizes = _wp_filter_image_sizes_additional_mime_type_support( $all_sizes, $this->large_id );
     1186
     1187                remove_image_size( 'test-size-with-additional-mimes' );
     1188                remove_image_size( 'test-size-without-additional-mimes' );
     1189
     1190                $expected_size_names   = array_keys( $default_sizes );
     1191                $expected_size_names[] = 'test-size-with-additional-mimes';
     1192
     1193                $this->assertSame( $expected_size_names, array_keys( $filtered_sizes ) );
     1194        }
     1195
    11571196        /**
    11581197         * @ticket 26768
    11591198         */
    11601199        public function test_remove_image_size() {
    1161                 add_image_size( 'test-size', 200, 600 );
     1200                add_image_size( 'test-size', 200, 600, false, false );
    11621201                $this->assertTrue( has_image_size( 'test-size' ) );
    11631202                remove_image_size( 'test-size' );
    11641203                $this->assertFalse( has_image_size( 'test-size' ) );
    VIDEO; 
    11681207         * @ticket 26951
    11691208         */
    11701209        public function test_has_image_size() {
    1171                 add_image_size( 'test-size', 200, 600 );
     1210                add_image_size( 'test-size', 200, 600, false, false );
    11721211                $this->assertTrue( has_image_size( 'test-size' ) );
    11731212
    11741213                // Clean up.
  • tests/phpunit/tests/rest-api/rest-attachments-controller.php

    diff --git tests/phpunit/tests/rest-api/rest-attachments-controller.php tests/phpunit/tests/rest-api/rest-attachments-controller.php
    index c8a6e180a3..28cdde22a4 100644
    class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 
    710710                        $this->test_file
    711711                );
    712712
    713                 add_image_size( 'rest-api-test', 119, 119, true );
     713                add_image_size( 'rest-api-test', 119, 119, true, false );
    714714                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $this->test_file ) );
    715715
    716716                $request            = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id );
    class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 
    741741                        $this->test_file
    742742                );
    743743
    744                 add_image_size( 'rest-api-test', 119, 119, true );
     744                add_image_size( 'rest-api-test', 119, 119, true, false );
    745745                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $this->test_file ) );
    746746
    747747                add_filter( 'wp_get_attachment_image_src', '__return_false' );