Make WordPress Core

Ticket #56288: 56288.2.diff

File 56288.2.diff, 9.1 KB (added by adamsilverstein, 2 years ago)

update from PR

  • src/wp-admin/includes/image.php

    diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
    index 98689672b3..486530c4c9 100644
    function _wp_filter_image_sizes_additional_mime_type_support( $sizes, $attachmen 
    660660                'post-thumbnail' => true,
    661661        );
    662662
     663        // Include any sizes that were added with `add_image_size`.
     664        $additional_image_sizes = wp_get_additional_image_sizes();
     665        $additional_image_sizes = array_filter(
     666                $additional_image_sizes,
     667                function( $size ) {
     668                        return isset( $size['additional_mimes'] ) && $size['additional_mimes'];
     669                }
     670        );
     671
     672        foreach ( array_keys( $additional_image_sizes ) as $size_name ) {
     673                $enabled_sizes[ $size_name ] = true;
     674        }
     675
    663676        /**
    664677         * Filter the sizes that support secondary mime type output. Developers can use this
    665678         * 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 51c49f83d2..b944575b92 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 $output_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       $additional_mimes Optional. Whether to output secondary mimes for this image size. Default is false.
    290292 */
    291 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
     293function add_image_size( $name, $width = 0, $height = 0, $crop = false, $additional_mimes = false ) {
    292294        global $_wp_additional_image_sizes;
    293295
    294296        $_wp_additional_image_sizes[ $name ] = array(
    295                 'width'  => absint( $width ),
    296                 'height' => absint( $height ),
    297                 'crop'   => $crop,
     297                'width'            => absint( $width ),
     298                'height'           => absint( $height ),
     299                'crop'             => $crop,
     300                'additional_mimes' => $additional_mimes,
    298301        );
    299302}
    300303
    function remove_image_size( $name ) { 
    345348 *                           An array can specify positioning of the crop area. Default false.
    346349 */
    347350function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
    348         add_image_size( 'post-thumbnail', $width, $height, $crop );
     351        add_image_size( 'post-thumbnail', $width, $height, $crop, true );
    349352}
    350353
    351354/**
    function wp_media_personal_data_exporter( $email_address, $page = 1 ) { 
    53175320 */
    53185321function _wp_add_additional_image_sizes() {
    53195322        // 2x medium_large size.
    5320         add_image_size( '1536x1536', 1536, 1536 );
     5323        add_image_size( '1536x1536', 1536, 1536, false, true );
    53215324        // 2x large size.
    5322         add_image_size( '2048x2048', 2048, 2048 );
     5325        add_image_size( '2048x2048', 2048, 2048, false, true );
    53235326}
    53245327
    53255328/**
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 592b19e328..f2e6b525b3 100644
    VIDEO; 
    11551155                $this->assertSame( 600, $sizes['test-size']['height'] );
    11561156        }
    11571157
     1158        /**
     1159         * @ticket 56288
     1160         */
     1161        public function test_add_image_size_additional_mimes() {
     1162                add_image_size( 'test-size-with-additional-mimes', 200, 600, false, true );
     1163                add_image_size( 'test-size-without-additional-mimes', 200, 600, false, false );
     1164
     1165                $sizes = wp_get_additional_image_sizes();
     1166
     1167                remove_image_size( 'test-size-with-additional-mimes' );
     1168                remove_image_size( 'test-size-without-additional-mimes' );
     1169
     1170                $this->assertArrayHasKey( 'test-size-with-additional-mimes', $sizes );
     1171                $this->assertArrayHasKey( 'test-size-without-additional-mimes', $sizes );
     1172                $this->assertTrue( $sizes['test-size-with-additional-mimes']['additional_mimes'] );
     1173                $this->assertFalse( $sizes['test-size-without-additional-mimes']['additional_mimes'] );
     1174        }
     1175
     1176        /**
     1177         * @ticket 56288
     1178         */
     1179        public function test__wp_filter_image_sizes_additional_mime_type_support_with_add_image_size() {
     1180                add_image_size( 'test-size-with-additional-mimes', 200, 600, false, true );
     1181                add_image_size( 'test-size-without-additional-mimes', 200, 600, false, false );
     1182
     1183                $all_sizes      = wp_get_additional_image_sizes();
     1184                $filtered_sizes = _wp_filter_image_sizes_additional_mime_type_support( $all_sizes, $this->large_id );
     1185
     1186                remove_image_size( 'test-size-with-additional-mimes' );
     1187                remove_image_size( 'test-size-without-additional-mimes' );
     1188
     1189                $this->assertArrayHasKey( 'test-size-with-additional-mimes', $filtered_sizes );
     1190                $this->assertArrayNotHasKey( 'test-size-without-additional-mimes', $filtered_sizes );
     1191
     1192        }
     1193
    11581194        /**
    11591195         * @ticket 26768
    11601196         */