Ticket #56288: 56288.diff
File 56288.diff, 15.2 KB (added by , 2 years ago) |
---|
-
src/wp-admin/includes/image.php
diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php index 98689672b3..7de3eb0b2c 100644
function _wp_filter_image_sizes_additional_mime_type_support( $sizes, $attachmen 660 660 'post-thumbnail' => true, 661 661 ); 662 662 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['output_mimes'] ) && $size['output_mimes']; 669 } 670 ); 671 672 foreach ( array_keys( $additional_image_sizes ) as $size_name ) { 673 $enabled_sizes[ $size_name ] = true; 674 } 675 663 676 /** 664 677 * Filter the sizes that support secondary mime type output. Developers can use this 665 678 * 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' ) ) : 227 227 * Add Twenty Eleven's custom image sizes. 228 228 * Used for large feature (header) images. 229 229 */ 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 ); 231 231 // 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 ); 233 233 234 234 // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 235 235 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' ) ) : 122 122 // Enable support for Post Thumbnails, and declare two sizes. 123 123 add_theme_support( 'post-thumbnails' ); 124 124 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 ); 126 126 127 127 // This theme uses wp_nav_menu() in two locations. 128 128 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() { 56 56 */ 57 57 add_theme_support( 'post-thumbnails' ); 58 58 59 add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );59 add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true, true ); 60 60 61 add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );61 add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true, true ); 62 62 63 63 // Set the default content width. 64 64 $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() { 63 63 set_post_thumbnail_size( 1200, 9999 ); 64 64 65 65 // 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 ); 67 67 68 68 // Custom logo. 69 69 $logo_width = 120; -
src/wp-includes/media.php
diff --git src/wp-includes/media.php src/wp-includes/media.php index 51c49f83d2..6c1febad81 100644
function image_downsize( $id, $size = 'medium' ) { 275 275 * Register a new image size. 276 276 * 277 277 * @since 2.9.0 278 * @since 6.1.0 Add the $output_mimes parameter. 278 279 * 279 280 * @global array $_wp_additional_image_sizes Associative array of additional image sizes. 280 281 * 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 $output_mimes Whether to output secondary mimes for this image size. Default is false. 290 292 */ 291 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {293 function add_image_size( $name, $width = 0, $height = 0, $crop = false, $output_mimes = false ) { 292 294 global $_wp_additional_image_sizes; 293 295 294 296 $_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 'output_mimes' => $output_mimes, 298 301 ); 299 302 } 300 303 … … function remove_image_size( $name ) { 343 346 * @param int $height Image height in pixels. 344 347 * @param bool|array $crop Optional. Whether to crop images to specified width and height or resize. 345 348 * An array can specify positioning of the crop area. Default false. 349 * @param bool $output_mimes Whether to output secondary mimes for the post thumbnail. Default is true. 346 350 */ 347 function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {348 add_image_size( 'post-thumbnail', $width, $height, $crop );351 function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false, $output_mimes = true ) { 352 add_image_size( 'post-thumbnail', $width, $height, $crop, true ); 349 353 } 350 354 351 355 /** … … function wp_get_registered_image_subsizes() { 925 929 $size_data['crop'] = (bool) $size_data['crop']; 926 930 } 927 931 932 if ( isset( $additional_sizes[ $size_name ]['output_mimes'] ) ) { 933 $size_data['output_mimes'] = $additional_sizes[ $size_name ]['output_mimes']; 934 } 935 928 936 $all_sizes[ $size_name ] = $size_data; 929 937 } 930 938 … … function wp_media_personal_data_exporter( $email_address, $page = 1 ) { 5317 5325 */ 5318 5326 function _wp_add_additional_image_sizes() { 5319 5327 // 2x medium_large size. 5320 add_image_size( '1536x1536', 1536, 1536 );5328 add_image_size( '1536x1536', 1536, 1536, false, true ); 5321 5329 // 2x large size. 5322 add_image_size( '2048x2048', 2048, 2048 );5330 add_image_size( '2048x2048', 2048, 2048, false, true ); 5323 5331 } 5324 5332 5325 5333 /** -
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 { 857 857 858 858 $this->assertNotEmpty( $attachment_id ); 859 859 860 add_image_size( 'test-size', 100, 100 );860 add_image_size( 'test-size', 100, 100, false, false ); 861 861 add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 ); 862 862 863 863 $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..6e875be81e 100644
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 93 93 * @requires function imagejpeg 94 94 */ 95 95 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, true ); 97 97 98 98 $file = DIR_TESTDATA . '/images/waffles.jpg'; 99 99 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 115 115 */ 116 116 public function test_get_intermediate_sizes_by_array_exact() { 117 117 // 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, true ); 119 add_image_size( 'false-height', 330, 400, true, true ); 120 add_image_size( 'false-width', 600, 220, true, true ); 121 121 122 122 $file = DIR_TESTDATA . '/images/waffles.jpg'; 123 123 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 138 138 public function test_get_intermediate_sizes_by_array_nearest() { 139 139 // If an exact size is not found, it should be returned. 140 140 // 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, true ); 142 add_image_size( 'false-height', 330, 100, true, true ); 143 add_image_size( 'false-width', 150, 220, true, true ); 144 144 145 145 $file = DIR_TESTDATA . '/images/waffles.jpg'; 146 146 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 161 161 public function test_get_intermediate_sizes_by_array_nearest_false() { 162 162 // If an exact size is not found, it should be returned. 163 163 // 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, true ); 165 add_image_size( 'false-width', 150, 220, true, true ); 166 166 167 167 $file = DIR_TESTDATA . '/images/waffles.jpg'; 168 168 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 185 185 $width = 300; 186 186 187 187 // 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, true ); 189 add_image_size( 'false-height', $width, 100, true, true ); 190 190 191 191 $file = DIR_TESTDATA . '/images/waffles.jpg'; 192 192 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 214 214 $height = 202; 215 215 216 216 // 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, true ); 218 add_image_size( 'false-height', 300, $height, true, true ); 219 219 220 220 $file = DIR_TESTDATA . '/images/waffles.jpg'; 221 221 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 242 242 // Original is 600x400. 300x201 is close enough to match. 243 243 $width = 300; 244 244 $height = 201; 245 add_image_size( 'off-by-one', $width, $height, true );245 add_image_size( 'off-by-one', $width, $height, true, true ); 246 246 247 247 $file = DIR_TESTDATA . '/images/waffles.jpg'; 248 248 $id = $this->_make_attachment( $file, 0 ); … … class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 264 264 */ 265 265 public function test_get_intermediate_size_with_small_size_array() { 266 266 // 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, true ); 268 268 269 269 $file = DIR_TESTDATA . '/images/waffles.jpg'; 270 270 $id = $this->_make_attachment( $file, 0 ); -
tests/phpunit/tests/media.php
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php index 592b19e328..e3b0ce5d57 100644
VIDEO; 1143 1143 remove_image_size( 'test-size' ); 1144 1144 1145 1145 $this->assertArrayNotHasKey( 'test-size', $_wp_additional_image_sizes ); 1146 add_image_size( 'test-size', 200, 600 );1146 add_image_size( 'test-size', 200, 600, false, true ); 1147 1147 1148 1148 $sizes = wp_get_additional_image_sizes(); 1149 1149 … … VIDEO; 1159 1159 * @ticket 26768 1160 1160 */ 1161 1161 public function test_remove_image_size() { 1162 add_image_size( 'test-size', 200, 600 );1162 add_image_size( 'test-size', 200, 600, false, true ); 1163 1163 $this->assertTrue( has_image_size( 'test-size' ) ); 1164 1164 remove_image_size( 'test-size' ); 1165 1165 $this->assertFalse( has_image_size( 'test-size' ) ); … … VIDEO; 1169 1169 * @ticket 26951 1170 1170 */ 1171 1171 public function test_has_image_size() { 1172 add_image_size( 'test-size', 200, 600 );1172 add_image_size( 'test-size', 200, 600, false, true ); 1173 1173 $this->assertTrue( has_image_size( 'test-size' ) ); 1174 1174 1175 1175 // 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 ec52dbcd0d..7dd2ccec2d 100644
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 710 710 $this->test_file 711 711 ); 712 712 713 add_image_size( 'rest-api-test', 119, 119, true );713 add_image_size( 'rest-api-test', 119, 119, true, true ); 714 714 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $this->test_file ) ); 715 715 716 716 $request = new WP_REST_Request( 'GET', '/wp/v2/media/' . $attachment_id ); … … class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control 741 741 $this->test_file 742 742 ); 743 743 744 add_image_size( 'rest-api-test', 119, 119, true );744 add_image_size( 'rest-api-test', 119, 119, true, true ); 745 745 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $this->test_file ) ); 746 746 747 747 add_filter( 'wp_get_attachment_image_src', '__return_false' );