Changeset 54086
- Timestamp:
- 09/06/2022 09:13:17 PM (2 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/admin-filters.php
r53304 r54086 37 37 38 38 add_filter( 'media_upload_tabs', 'update_gallery_tab' ); 39 40 add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); 39 41 40 42 // Admin color schemes. -
trunk/src/wp-admin/includes/image-edit.php
r53546 r54086 918 918 919 919 // Save the full-size file, also needed to create sub-sizes. 920 if ( ! wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ) ) { 920 $saved = wp_save_image_file( $new_path, $img, $post->post_mime_type, $post_id ); 921 if ( ! $saved ) { 921 922 $return->error = esc_js( __( 'Unable to save the image.' ) ); 922 923 return $return; 923 924 } 925 $new_path = $saved['path']; 924 926 925 927 if ( 'nothumb' === $target || 'all' === $target || 'full' === $target || $scaled ) { -
trunk/src/wp-admin/includes/media.php
r54071 r54086 3844 3844 } 3845 3845 } 3846 3847 /** 3848 * Filters the default image output mapping. 3849 * 3850 * With this filter callback, WebP image files will be generated for certain JPEG source files. 3851 * 3852 * @since 6.1.0 3853 * 3854 * @param array $output_mapping Map of mime type to output format. 3855 * @retun array The adjusted default output mapping. 3856 */ 3857 function wp_default_image_output_mapping( $output_mapping ) { 3858 $output_mapping['image/jpeg'] = 'image/webp'; 3859 return $output_mapping; 3860 } -
trunk/src/wp-includes/class-wp-image-editor.php
r54085 r54086 425 425 } 426 426 427 /** 428 * Builds an output filename based on current file, and adding proper suffix 429 * 430 * @since 3.5.0 431 * 432 * @param string $suffix 433 * @param string $dest_path 434 * @param string $extension 435 * @return string filename 427 /** 428 * Builds an output filename based on current file, and adding proper suffix. 429 * 430 * @since 3.5.0 431 * @since 6.1.0 Skips adding a suffix when set to an empty string. When the 432 * file extension being generated doesn't match the image file extension, 433 * add the extension to the suffix 434 * 435 * @param string $suffix Optional. Suffix to add to the filename. The default null 436 * will result in a 'widthxheight' suffix. Passing 437 * an empty string will result in no suffix. 438 * @param string $dest_path Optional. The path to save the file to. The default null 439 * will use the image file path. 440 * @param string $extension Optional. The file extension to use. The default null 441 * will use the image file extension. 442 * @return string filename The generated file name. 436 443 */ 437 444 public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) { 438 445 // $suffix will be appended to the destination filename, just before the extension. 439 if ( !$suffix ) {446 if ( null === $suffix ) { 440 447 $suffix = $this->get_suffix(); 441 448 } … … 458 465 } 459 466 460 return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}"; 467 if ( empty( $suffix ) ) { 468 $suffix = ''; 469 } else { 470 $suffix = "-{$suffix}"; 471 } 472 473 // When the file extension being generated doesn't match the image file extension, 474 // add the extension to the suffix to ensure a unique file name. Prevents 475 // name conflicts when a single image type can have multiple extensions, 476 // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions. 477 if ( ! empty( $extension ) && $extension !== $ext ) { 478 $suffix .= "-{$ext}"; 479 } 480 481 return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}"; 461 482 } 462 483 -
trunk/tests/phpunit/tests/image/editor.php
r54085 r54086 19 19 20 20 require_once DIR_TESTDATA . '/../includes/mock-image-editor.php'; 21 add_filter( 'image_editor_output_format', '__return_empty_array' ); 21 22 22 23 // This needs to come after the mock image editor class is loaded. 23 24 parent::set_up(); 25 } 26 27 /** 28 * Tear down the class. 29 */ 30 public function tear_down() { 31 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 32 parent::tear_down(); 24 33 } 25 34 … … 227 236 228 237 // Test with a suffix only. 229 $this->assertSame( 'canola-100x50 .png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) );238 $this->assertSame( 'canola-100x50-jpg.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); 230 239 231 240 // Combo! 232 $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new .png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) );241 $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new-jpg.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); 233 242 234 243 // Test with a stream destination. -
trunk/tests/phpunit/tests/image/editorGd.php
r52837 r54086 18 18 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; 19 19 20 add_filter( 'image_editor_output_format', '__return_empty_array' ); 21 20 22 // This needs to come after the mock image editor class is loaded. 21 23 parent::set_up(); … … 30 32 31 33 $this->remove_added_uploads(); 34 35 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 32 36 33 37 parent::tear_down(); -
trunk/tests/phpunit/tests/image/editorImagick.php
r52837 r54086 19 19 require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php'; 20 20 21 add_filter( 'image_editor_output_format', '__return_empty_array' ); 22 21 23 // This needs to come after the mock image editor class is loaded. 22 24 parent::set_up(); … … 31 33 32 34 $this->remove_added_uploads(); 35 36 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 33 37 34 38 parent::tear_down(); -
trunk/tests/phpunit/tests/image/functions.php
r54085 r54086 26 26 unlink( $file ); 27 27 } 28 29 add_filter( 'image_editor_output_format', '__return_empty_array' ); 30 } 31 32 /** 33 * Tear down the class. 34 */ 35 public function tear_down() { 36 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 37 parent::tear_down(); 28 38 } 29 39 -
trunk/tests/phpunit/tests/image/intermediateSize.php
r52389 r54086 6 6 */ 7 7 class Tests_Image_Intermediate_Size extends WP_UnitTestCase { 8 /** 9 * Set up the test fixture. 10 */ 11 public function set_up() { 12 add_filter( 'image_editor_output_format', '__return_empty_array' ); 13 14 parent::set_up(); 15 } 16 8 17 public function tear_down() { 9 18 $this->remove_added_uploads(); … … 13 22 remove_image_size( 'false-width' ); 14 23 remove_image_size( 'off-by-one' ); 24 25 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 26 15 27 parent::tear_down(); 16 28 } -
trunk/tests/phpunit/tests/image/resize.php
r53463 r54086 15 15 16 16 add_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) ); 17 add_filter( 'image_editor_output_format', '__return_empty_array' ); 18 } 19 20 /** 21 * Tear down the class. 22 */ 23 public function tear_down() { 24 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 25 parent::tear_down(); 17 26 } 18 27 -
trunk/tests/phpunit/tests/media.php
r54085 r54086 34 34 $GLOBALS['_wp_additional_image_sizes'] = array(); 35 35 36 $filename = DIR_TESTDATA . '/images/' . self::$large_filename; 36 $filename = DIR_TESTDATA . '/images/' . self::$large_filename; 37 add_filter( 'image_editor_output_format', '__return_empty_array' ); 37 38 self::$large_id = $factory->attachment->create_upload_object( $filename ); 38 39 … … 69 70 public static function wpTearDownAfterClass() { 70 71 $GLOBALS['_wp_additional_image_sizes'] = self::$_sizes; 72 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 71 73 } 72 74 … … 3618 3620 remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 ); 3619 3621 } 3622 3623 /** 3624 * Test the wp_default_image_output_mapping function. 3625 * 3626 * @ticket 55443 3627 */ 3628 public function test_wp_default_image_output_mapping() { 3629 $mapping = wp_default_image_output_mapping( array() ); 3630 $this->assertSame( array( 'image/jpeg' => 'image/webp' ), $mapping ); 3631 } 3632 3633 /** 3634 * Test that wp_default_image_output_mapping doesn't overwrite existing mappings. 3635 * 3636 * @ticket 55443 3637 */ 3638 public function test_wp_default_image_output_mapping_existing() { 3639 $mapping = array( 'mime/png' => 'mime/webp' ); 3640 $mapping = wp_default_image_output_mapping( $mapping ); 3641 $this->assertSame( 3642 array( 3643 'mime/png' => 'mime/webp', 3644 'image/jpeg' => 'image/webp', 3645 ), 3646 $mapping 3647 ); 3648 } 3649 3650 /** 3651 * Test that the image editor default output for JPEGs is WebP. 3652 * 3653 * @ticket 55443 3654 */ 3655 public function test_wp_image_editor_default_output_maps_to_webp() { 3656 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 3657 3658 $editor = wp_get_image_editor( DIR_TESTDATA . '/images/canola.jpg' ); 3659 $this->assertNotWPError( $editor ); 3660 3661 $resized = $editor->resize( 100, 100, false ); 3662 $this->assertNotWPError( $resized ); 3663 3664 $saved = $editor->save(); 3665 $this->assertNotWPError( $saved ); 3666 3667 if ( $editor->supports_mime_type( 'image/webp' ) ) { 3668 $this->assertSame( 'image/webp', $saved['mime-type'] ); 3669 $this->assertSame( 'canola-100x75-jpg.webp', $saved['file'] ); 3670 } else { 3671 $this->assertSame( 'image/jpeg', $saved['mime-type'] ); 3672 $this->assertSame( 'canola-100x75.jpg', $saved['file'] ); 3673 } 3674 } 3620 3675 } 3621 3676 -
trunk/tests/phpunit/tests/post/attachments.php
r52389 r54086 7 7 */ 8 8 class Tests_Post_Attachments extends WP_UnitTestCase { 9 /** 10 * Set up the test fixture. 11 */ 12 public function set_up() { 13 add_filter( 'image_editor_output_format', '__return_empty_array' ); 14 15 parent::set_up(); 16 } 9 17 10 18 public function tear_down() { 11 19 // Remove all uploads. 12 20 $this->remove_added_uploads(); 21 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 13 22 parent::tear_down(); 14 23 } -
trunk/tests/phpunit/tests/rest-api/rest-attachments-controller.php
r54085 r54086 94 94 add_filter( 'rest_pre_dispatch', array( $this, 'wpSetUpBeforeRequest' ), 10, 3 ); 95 95 add_filter( 'posts_clauses', array( $this, 'save_posts_clauses' ), 10, 2 ); 96 add_filter( 'image_editor_output_format', '__return_empty_array' ); 96 97 } 97 98 … … 121 122 WP_Image_Editor_Mock::$size_return = null; 122 123 } 124 125 remove_filter( 'image_editor_output_format', '__return_empty_array' ); 123 126 124 127 parent::tear_down();
Note: See TracChangeset
for help on using the changeset viewer.