From 69461213d1e362a82f372e5ad4b950de5e1d6c2b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 17 Jun 2022 10:15:59 -0600 Subject: [PATCH 1/7] Enable filtering mime output by image size --- src/wp-admin/includes/image.php | 47 ++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 2ad8b43180c2c..74a81414aeb4b 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -505,13 +505,21 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id, $mim return array(); } + $original_mime_type = wp_get_image_mime( $file ); + if ( ! $mime_type ) { - $mime_type = wp_get_image_mime( $file ); + $mime_type = $original_mime_type; } + // Check if any of the new sizes already exist. if ( isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) { foreach ( $image_meta['sizes'] as $size_name => $size_meta ) { + // Check if the output mime is enabled for this image size. + if ( ! _wp_mime_type_available_for_image_size( $attachment_id, $size_name, $original_mime_type, $mime_type ) ) { + continue; + } + /* * Only checks "size name" so we don't override existing images even if the dimensions * don't match the currently defined size with the same name. @@ -605,6 +613,21 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id, $mim return $image_meta; } +/** + * Check whether mime type output is available for a given size and mime type. + * + * @since 6.1.0 + * + * @param int $attachment_id Attachment ID. + * @param string $size_name Size name to check. + * @return bool Whether the size is available for the given mime type. + */ +function _wp_mime_type_available_for_image_size( $attachment_id, $size_name, $source_mime, $destination_mime ) { + $image_mime_transforms = wp_upload_image_mime_transforms( $attachment_id, $size_name ); + + return isset( $image_mime_transforms[ $source_mime ] [ $destination_mime ] ); +} + /** * Low-level function to create full-size images in additional mime types. * @@ -1336,28 +1359,34 @@ function _copy_image_file( $attachment_id ) { * For example an `image/jpeg` should be converted into an `image/jpeg` and `image/webp`. The first type * is considered the primary output type for this image. * + * Called for each uploaded image to determine the list of mime types that should be converted into. Then, + * called again for each target image size as they are generated to see if the image should be converted into the mime type + * for that size. + * * @since 6.1.0 * - * @param $attachment_id int The attachment ID. + * @param int $attachment_id The attachment ID. + * @param string $image_size The image size name. False when called on the image and target size is unavailable. * @return array An array of valid mime types, where the key is the source file mime type and the list of mime types to * generate. */ -function wp_upload_image_mime_transforms( $attachment_id ) { +function wp_upload_image_mime_transforms( $attachment_id, $image_size ) { $image_mime_transforms = array( 'image/jpeg' => array( 'image/jpeg', 'image/webp' ), 'image/webp' => array( 'image/webp', 'image/jpeg' ), ); /** - * Filter to the output mime types for a given input mime type. + * Filter to the output mime types for a given input mime type and image size. * * @since 6.1.0 * - * @param array $image_mime_transforms A map with the valid mime transforms where the key is the source file mime type - * and the value is one or more mime file types to generate. - * @param int $attachment_id The ID of the attachment where the hook was dispatched. + * @param array $image_mime_transforms A map with the valid mime transforms where the key is the source file mime type + * and the value is one or more mime file types to generate. + * @param int $attachment_id The ID of the attachment where the hook was dispatched. + * @param string $image_size The image size name. Optional. */ - return (array) apply_filters( 'wp_upload_image_mime_transforms', $image_mime_transforms, $attachment_id ); + return (array) apply_filters( 'wp_upload_image_mime_transforms', $image_mime_transforms, $attachment_id, $image_size ); } /** @@ -1371,7 +1400,7 @@ function wp_upload_image_mime_transforms( $attachment_id ) { * @return array An array with two entries, the primary mime type and the list of additional mime types. */ function _wp_get_primary_and_additional_mime_types( $file, $attachment_id ) { - $image_mime_transforms = wp_upload_image_mime_transforms( $attachment_id ); + $image_mime_transforms = wp_upload_image_mime_transforms( $attachment_id, false ); $original_mime_type = wp_get_image_mime( $file ); $output_mime_types = isset( $image_mime_transforms[ $original_mime_type ] ) ? $image_mime_transforms[ $original_mime_type ] : array( $original_mime_type ); From 4feb97e8db56238c44f741ed0eeacaa12145cd7e Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Jun 2022 14:50:38 -0600 Subject: [PATCH 2/7] Add the $output_mimes parameter to add_image_size & test --- src/wp-admin/includes/image.php | 2 +- src/wp-includes/media.php | 48 ++++++++++++++++++++++++--------- tests/phpunit/tests/media.php | 15 +++++++++++ 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 74a81414aeb4b..40620664222fe 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -625,7 +625,7 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id, $mim function _wp_mime_type_available_for_image_size( $attachment_id, $size_name, $source_mime, $destination_mime ) { $image_mime_transforms = wp_upload_image_mime_transforms( $attachment_id, $size_name ); - return isset( $image_mime_transforms[ $source_mime ] [ $destination_mime ] ); + return isset( $image_mime_transforms[ $source_mime ] [ $destination_mime ] ) && image_size_supports_mime( $size_name, $destination_mime ); } /** diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 74bae684fcdaa..e2e75dd365bbb 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -275,29 +275,51 @@ function image_downsize( $id, $size = 'medium' ) { * Register a new image size. * * @since 2.9.0 + * @since 6.1.0 Add the $output_mimes parameter. * * @global array $_wp_additional_image_sizes Associative array of additional image sizes. * - * @param string $name Image size identifier. - * @param int $width Optional. Image width in pixels. Default 0. - * @param int $height Optional. Image height in pixels. Default 0. - * @param bool|array $crop Optional. Image cropping behavior. If false, the image will be scaled (default), - * If true, image will be cropped to the specified dimensions using center positions. - * If an array, the image will be cropped using the array to specify the crop location. - * Array values must be in the format: array( x_crop_position, y_crop_position ) where: - * - x_crop_position accepts: 'left', 'center', or 'right'. - * - y_crop_position accepts: 'top', 'center', or 'bottom'. + * @param string $name Image size identifier. + * @param int $width Optional. Image width in pixels. Default 0. + * @param int $height Optional. Image height in pixels. Default 0. + * @param bool|array $crop Optional. Image cropping behavior. If false, the image will be scaled (default), + * If true, image will be cropped to the specified dimensions using center positions. + * If an array, the image will be cropped using the array to specify the crop location. + * Array values must be in the format: array( x_crop_position, y_crop_position ) where: + * - x_crop_position accepts: 'left', 'center', or 'right'. + * - y_crop_position accepts: 'top', 'center', or 'bottom'. + * @param array $output_mimes A list of supported output mime types for this image size. If empty, no secondary mime + * type images will created for this size. Default is empty. Note this serves to limit the + * mime types that are generated per size, to specify the mime types that are supported, + * for a given input type, use the `wp_upload_image_mime_transforms` filter. */ -function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { +function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_mimes = array() ) { global $_wp_additional_image_sizes; $_wp_additional_image_sizes[ $name ] = array( - 'width' => absint( $width ), - 'height' => absint( $height ), - 'crop' => $crop, + 'width' => absint( $width ), + 'height' => absint( $height ), + 'crop' => $crop, + 'output_mimes' => $output_mimes ); } +/** + * Check if an image size supports output in a specific mime type. + * + * @since 6.1.0 + * + * @uses wp_get_additional_image_sizes() + * + * @param string $name Image size identifier. + * @param string $mime_type The mime type to check. + * @return bool Whether the size supports the mime type for output. + */ +function image_size_supports_mime( $name, $mime_type ) { + $sizes = wp_get_additional_image_sizes(); + return isset( $sizes[ $name ][ 'output_mimes' ] ) && in_array( $mime_type, $sizes[ $name ][ 'output_mimes' ] ); +} + /** * Check if an image size exists. * diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 56c8ba53b3dee..59df658e7b52d 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1177,6 +1177,21 @@ public function test_has_image_size() { remove_image_size( 'test-size' ); } + /** + * @ticket 55443 + */ + public function test_image_size_supports_mime() { + add_image_size( 'test-size', 200, 600, true ); + $this->assertSame( false, image_size_supports_mime( 'test-size', 'image/webp' ) ); + remove_image_size( 'test-size' ); + + add_image_size( 'test-size', 200, 600, true, array( 'image/webp' ) ); + $this->assertSame( true, image_size_supports_mime( 'test-size', 'image/webp' ) ); + + // Clean up. + remove_image_size( 'test-size' ); + } + /** * @ticket 30346 */ From 673cac32d734933b2e4673d2f7e672819f60e59a Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 22 Jun 2022 14:51:22 -0600 Subject: [PATCH 3/7] Add image/webp output type for all core & core theme image sizes --- src/wp-content/themes/twentyeleven/functions.php | 4 ++-- src/wp-content/themes/twentyfourteen/functions.php | 2 +- src/wp-content/themes/twentyseventeen/functions.php | 4 ++-- src/wp-content/themes/twentytwenty/functions.php | 2 +- src/wp-includes/media.php | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/wp-content/themes/twentyeleven/functions.php b/src/wp-content/themes/twentyeleven/functions.php index 12593aaddfeb5..3bfb0d8c45f6f 100644 --- a/src/wp-content/themes/twentyeleven/functions.php +++ b/src/wp-content/themes/twentyeleven/functions.php @@ -227,9 +227,9 @@ function twentyeleven_setup() { * Add Twenty Eleven's custom image sizes. * Used for large feature (header) images. */ - add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true ); + add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true, array( 'image/webp' ) ); // Used for featured posts if a large-feature doesn't exist. - add_image_size( 'small-feature', 500, 300 ); + add_image_size( 'small-feature', 500, 300, false, array( 'image/webp' ) ); // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. register_default_headers( diff --git a/src/wp-content/themes/twentyfourteen/functions.php b/src/wp-content/themes/twentyfourteen/functions.php index 0695bcce6dccb..5e578ae52df08 100644 --- a/src/wp-content/themes/twentyfourteen/functions.php +++ b/src/wp-content/themes/twentyfourteen/functions.php @@ -122,7 +122,7 @@ function twentyfourteen_setup() { // Enable support for Post Thumbnails, and declare two sizes. add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 672, 372, true ); - add_image_size( 'twentyfourteen-full-width', 1038, 576, true ); + add_image_size( 'twentyfourteen-full-width', 1038, 576, true, array( 'image/webp' ) ); // This theme uses wp_nav_menu() in two locations. register_nav_menus( diff --git a/src/wp-content/themes/twentyseventeen/functions.php b/src/wp-content/themes/twentyseventeen/functions.php index 3d933989c2b61..1612f1d81e010 100644 --- a/src/wp-content/themes/twentyseventeen/functions.php +++ b/src/wp-content/themes/twentyseventeen/functions.php @@ -56,9 +56,9 @@ function twentyseventeen_setup() { */ add_theme_support( 'post-thumbnails' ); - add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true ); + add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true, array( 'image/webp' ) ); - add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true ); + add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true, array( 'image/webp' ) ); // Set the default content width. $GLOBALS['content_width'] = 525; diff --git a/src/wp-content/themes/twentytwenty/functions.php b/src/wp-content/themes/twentytwenty/functions.php index c8944e03c1e14..7005dd8f005c4 100644 --- a/src/wp-content/themes/twentytwenty/functions.php +++ b/src/wp-content/themes/twentytwenty/functions.php @@ -63,7 +63,7 @@ function twentytwenty_theme_support() { set_post_thumbnail_size( 1200, 9999 ); // Add custom image size used in Cover Template. - add_image_size( 'twentytwenty-fullscreen', 1980, 9999 ); + add_image_size( 'twentytwenty-fullscreen', 1980, 9999, false, array( 'image/webp' ) ); // Custom logo. $logo_width = 120; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index e2e75dd365bbb..5ae8e544c0f27 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -367,7 +367,7 @@ function remove_image_size( $name ) { * An array can specify positioning of the crop area. Default false. */ function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { - add_image_size( 'post-thumbnail', $width, $height, $crop ); + add_image_size( 'post-thumbnail', $width, $height, $crop, array( 'image/webp' ) ); } /** @@ -5314,9 +5314,9 @@ function wp_media_personal_data_exporter( $email_address, $page = 1 ) { */ function _wp_add_additional_image_sizes() { // 2x medium_large size. - add_image_size( '1536x1536', 1536, 1536 ); + add_image_size( '1536x1536', 1536, 1536, false, array( 'image/webp' ) ); // 2x large size. - add_image_size( '2048x2048', 2048, 2048 ); + add_image_size( '2048x2048', 2048, 2048, false, array( 'image/webp' ) ); } /** From 4f9b6059ee60cc0164529eec72088f986528ad37 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Jun 2022 12:58:28 -0600 Subject: [PATCH 4/7] Use boolean vs arrays for output_mimes --- .../themes/twentyeleven/functions.php | 4 ++-- .../themes/twentyfourteen/functions.php | 2 +- .../themes/twentyseventeen/functions.php | 4 ++-- .../themes/twentytwenty/functions.php | 2 +- src/wp-includes/media.php | 24 ++++++++++++------- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/wp-content/themes/twentyeleven/functions.php b/src/wp-content/themes/twentyeleven/functions.php index 3bfb0d8c45f6f..ee95afd96b5f9 100644 --- a/src/wp-content/themes/twentyeleven/functions.php +++ b/src/wp-content/themes/twentyeleven/functions.php @@ -227,9 +227,9 @@ function twentyeleven_setup() { * Add Twenty Eleven's custom image sizes. * Used for large feature (header) images. */ - add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true, array( 'image/webp' ) ); + add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true, true ); // Used for featured posts if a large-feature doesn't exist. - add_image_size( 'small-feature', 500, 300, false, array( 'image/webp' ) ); + add_image_size( 'small-feature', 500, 300, false, true ); // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. register_default_headers( diff --git a/src/wp-content/themes/twentyfourteen/functions.php b/src/wp-content/themes/twentyfourteen/functions.php index 5e578ae52df08..0896f84410066 100644 --- a/src/wp-content/themes/twentyfourteen/functions.php +++ b/src/wp-content/themes/twentyfourteen/functions.php @@ -122,7 +122,7 @@ function twentyfourteen_setup() { // Enable support for Post Thumbnails, and declare two sizes. add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 672, 372, true ); - add_image_size( 'twentyfourteen-full-width', 1038, 576, true, array( 'image/webp' ) ); + add_image_size( 'twentyfourteen-full-width', 1038, 576, true, true ); // This theme uses wp_nav_menu() in two locations. register_nav_menus( diff --git a/src/wp-content/themes/twentyseventeen/functions.php b/src/wp-content/themes/twentyseventeen/functions.php index 1612f1d81e010..d8b95b8568e47 100644 --- a/src/wp-content/themes/twentyseventeen/functions.php +++ b/src/wp-content/themes/twentyseventeen/functions.php @@ -56,9 +56,9 @@ function twentyseventeen_setup() { */ add_theme_support( 'post-thumbnails' ); - add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true, array( 'image/webp' ) ); + add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true, true ); - add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true, array( 'image/webp' ) ); + add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true, true ); // Set the default content width. $GLOBALS['content_width'] = 525; diff --git a/src/wp-content/themes/twentytwenty/functions.php b/src/wp-content/themes/twentytwenty/functions.php index 7005dd8f005c4..21a561fdaf820 100644 --- a/src/wp-content/themes/twentytwenty/functions.php +++ b/src/wp-content/themes/twentytwenty/functions.php @@ -63,7 +63,7 @@ function twentytwenty_theme_support() { set_post_thumbnail_size( 1200, 9999 ); // Add custom image size used in Cover Template. - add_image_size( 'twentytwenty-fullscreen', 1980, 9999, false, array( 'image/webp' ) ); + add_image_size( 'twentytwenty-fullscreen', 1980, 9999, false, true ); // Custom logo. $logo_width = 120; diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 5ae8e544c0f27..7ab8e2cbe61d9 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -288,14 +288,18 @@ function image_downsize( $id, $size = 'medium' ) { * Array values must be in the format: array( x_crop_position, y_crop_position ) where: * - x_crop_position accepts: 'left', 'center', or 'right'. * - y_crop_position accepts: 'top', 'center', or 'bottom'. - * @param array $output_mimes A list of supported output mime types for this image size. If empty, no secondary mime - * type images will created for this size. Default is empty. Note this serves to limit the - * mime types that are generated per size, to specify the mime types that are supported, - * for a given input type, use the `wp_upload_image_mime_transforms` filter. + * @param bool $output_mimes Whether to output secondary mimes for this image size. Default is null which will + * throw a doing_it_wrong warning to warn developers they should set this value. + * Default will be true in 6.2. */ -function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_mimes = array() ) { +function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_mimes = null ) { global $_wp_additional_image_sizes; + // For 6.1.x, warn developers about setting a value for $output_mimes. + if ( null === $output_mimes ) { + _doing_it_wrong( __FUNCTION__, __( 'Passing the $output_mimes parameter to add_image_size is recommended.' ), '6.1.0' ); + } + $_wp_additional_image_sizes[ $name ] = array( 'width' => absint( $width ), 'height' => absint( $height ), @@ -317,7 +321,9 @@ function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_ */ function image_size_supports_mime( $name, $mime_type ) { $sizes = wp_get_additional_image_sizes(); - return isset( $sizes[ $name ][ 'output_mimes' ] ) && in_array( $mime_type, $sizes[ $name ][ 'output_mimes' ] ); + error_log( 'image_size_supports_mime --- ' . json_encode( $sizes, JSON_PRETTY_PRINT)); + + return isset( $sizes[ $name ][ 'output_mimes' ] ) && $sizes[ $name ][ 'output_mimes' ]; } /** @@ -367,7 +373,7 @@ function remove_image_size( $name ) { * An array can specify positioning of the crop area. Default false. */ function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) { - add_image_size( 'post-thumbnail', $width, $height, $crop, array( 'image/webp' ) ); + add_image_size( 'post-thumbnail', $width, $height, $crop, true ); } /** @@ -5314,9 +5320,9 @@ function wp_media_personal_data_exporter( $email_address, $page = 1 ) { */ function _wp_add_additional_image_sizes() { // 2x medium_large size. - add_image_size( '1536x1536', 1536, 1536, false, array( 'image/webp' ) ); + add_image_size( '1536x1536', 1536, 1536, false, true ); // 2x large size. - add_image_size( '2048x2048', 2048, 2048, false, array( 'image/webp' ) ); + add_image_size( '2048x2048', 2048, 2048, false, true ); } /** From c6baf723ec026c14e66c3f269e7f388946ef15bc Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Jun 2022 13:09:35 -0600 Subject: [PATCH 5/7] Ensure default image sizes output mimes --- src/wp-includes/media.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 7ab8e2cbe61d9..2edfeb56e26c6 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -918,11 +918,15 @@ function wp_get_registered_image_subsizes() { $all_sizes = array(); foreach ( get_intermediate_image_sizes() as $size_name ) { - $size_data = array( - 'width' => 0, - 'height' => 0, - 'crop' => false, - ); + $default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); + foreach ( get_intermediate_image_sizes() as $size_name ) { + $size_data = array( + 'width' => 0, + 'height' => 0, + 'crop' => false, + 'output_mimes' => in_array( $size_name, $default_sizes, true ), + ); + } if ( isset( $additional_sizes[ $size_name ]['width'] ) ) { // For sizes added by plugins and themes. From 5b99bd87fe33ca9cf7c6881da38383a7d95a7e72 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Jun 2022 14:28:38 -0600 Subject: [PATCH 6/7] Add test for `image_size_supports_mime` and output_mime parameter --- tests/phpunit/tests/media.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 59df658e7b52d..58397eeee8aaf 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -1181,11 +1181,11 @@ public function test_has_image_size() { * @ticket 55443 */ public function test_image_size_supports_mime() { - add_image_size( 'test-size', 200, 600, true ); + add_image_size( 'test-size', 200, 600, true, false ); $this->assertSame( false, image_size_supports_mime( 'test-size', 'image/webp' ) ); remove_image_size( 'test-size' ); - add_image_size( 'test-size', 200, 600, true, array( 'image/webp' ) ); + add_image_size( 'test-size', 200, 600, true, true ); $this->assertSame( true, image_size_supports_mime( 'test-size', 'image/webp' ) ); // Clean up. From 46e5b140e60edfc2764792ee3fbd0697085aa78b Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Fri, 24 Jun 2022 14:28:49 -0600 Subject: [PATCH 7/7] cleanup --- src/wp-admin/includes/image.php | 1 - src/wp-includes/media.php | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 40620664222fe..5cce0f2fbcac4 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -511,7 +511,6 @@ function _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id, $mim $mime_type = $original_mime_type; } - // Check if any of the new sizes already exist. if ( isset( $image_meta['sizes'] ) && is_array( $image_meta['sizes'] ) ) { foreach ( $image_meta['sizes'] as $size_name => $size_meta ) { diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index 2edfeb56e26c6..19c27585ec443 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -304,7 +304,7 @@ function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_ 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => $crop, - 'output_mimes' => $output_mimes + 'output_mimes' => $output_mimes, ); } @@ -321,9 +321,7 @@ function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_ */ function image_size_supports_mime( $name, $mime_type ) { $sizes = wp_get_additional_image_sizes(); - error_log( 'image_size_supports_mime --- ' . json_encode( $sizes, JSON_PRETTY_PRINT)); - - return isset( $sizes[ $name ][ 'output_mimes' ] ) && $sizes[ $name ][ 'output_mimes' ]; + return isset( $sizes[ $name ]['output_mimes'] ) && $sizes[ $name ]['output_mimes']; } /** @@ -918,7 +916,7 @@ function wp_get_registered_image_subsizes() { $all_sizes = array(); foreach ( get_intermediate_image_sizes() as $size_name ) { - $default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); + $default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' ); foreach ( get_intermediate_image_sizes() as $size_name ) { $size_data = array( 'width' => 0,