diff --git a/src/wp-admin/includes/admin-filters.php b/src/wp-admin/includes/admin-filters.php
index e80c111dde..f5f9600332 100644
a
|
b
|
add_filter( 'media_upload_library', 'media_upload_library' ); |
37 | 37 | |
38 | 38 | add_filter( 'media_upload_tabs', 'update_gallery_tab' ); |
39 | 39 | |
| 40 | add_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
| 41 | |
40 | 42 | // Admin color schemes. |
41 | 43 | add_action( 'admin_init', 'register_admin_color_schemes', 1 ); |
42 | 44 | add_action( 'admin_head', 'wp_color_scheme_settings' ); |
diff --git a/src/wp-admin/includes/media.php b/src/wp-admin/includes/media.php
index 510fff563d..32455d1a5e 100644
a
|
b
|
function wp_media_attach_action( $parent_id, $action = 'attach' ) { |
3843 | 3843 | exit; |
3844 | 3844 | } |
3845 | 3845 | } |
| 3846 | |
| 3847 | /** |
| 3848 | * Returns the default image output mapping. |
| 3849 | * |
| 3850 | * @since 6.1.0 |
| 3851 | */ |
| 3852 | function wp_default_image_output_mapping() { |
| 3853 | return array( 'image/jpeg' => 'image/webp' ); |
| 3854 | } |
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
index caa3092d36..48472bb11f 100644
a
|
b
|
abstract class WP_Image_Editor { |
446 | 446 | $name = wp_basename( $this->file, ".$ext" ); |
447 | 447 | $new_ext = strtolower( $extension ? $extension : $ext ); |
448 | 448 | |
| 449 | // When the file extension being generated doesn't match the original image file extension, |
| 450 | // add the original extension to the suffix to ensure a unique file name. Prevents |
| 451 | // generated file name conflicts when a source image type can have multiple extensions, |
| 452 | // eg. .jpg, .jpeg and .jpe are all valid JPEG extensions. |
| 453 | if ( ! empty( $extension ) && $extension !== $ext ) { |
| 454 | $suffix .= "-{$ext}"; |
| 455 | } |
| 456 | |
449 | 457 | if ( ! is_null( $dest_path ) ) { |
450 | 458 | if ( ! wp_is_stream( $dest_path ) ) { |
451 | 459 | $_dest_path = realpath( $dest_path ); |
diff --git a/tests/phpunit/tests/ajax/MediaEdit.php b/tests/phpunit/tests/ajax/MediaEdit.php
index 686dae08c5..60e4cd2105 100644
a
|
b
|
class Tests_Ajax_MediaEdit extends WP_Ajax_UnitTestCase { |
67 | 67 | */ |
68 | 68 | public function testImageEditOverwriteConstant() { |
69 | 69 | define( 'IMAGE_EDIT_OVERWRITE', true ); |
| 70 | $files_that_shouldnt_exist = array(); |
70 | 71 | |
71 | 72 | require_once ABSPATH . 'wp-admin/includes/image-edit.php'; |
72 | 73 | |
diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php
index 487dad0664..73e4ae8f8e 100644
a
|
b
|
class Tests_Image_Editor extends WP_Image_UnitTestCase { |
18 | 18 | require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; |
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(); |
… |
… |
class Tests_Image_Editor extends WP_Image_UnitTestCase { |
226 | 227 | $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ), trailingslashit( realpath( dirname( $editor->generate_filename( null, get_temp_dir() ) ) ) ) ); |
227 | 228 | |
228 | 229 | // Test with a suffix only. |
229 | | $this->assertSame( 'canola-100x50.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); |
| 230 | $this->assertSame( 'canola-100x50-jpg.png', wp_basename( $editor->generate_filename( null, null, 'png' ) ) ); |
230 | 231 | |
231 | 232 | // Combo! |
232 | | $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); |
| 233 | $this->assertSame( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new-jpg.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); |
233 | 234 | |
234 | 235 | // Test with a stream destination. |
235 | 236 | $this->assertSame( 'file://testing/path/canola-100x50.jpg', $editor->generate_filename( null, 'file://testing/path' ) ); |
diff --git a/tests/phpunit/tests/image/editorGd.php b/tests/phpunit/tests/image/editorGd.php
index 5d967bdcdb..2e3828ffe8 100644
a
|
b
|
class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { |
17 | 17 | require_once ABSPATH . WPINC . '/class-wp-image-editor.php'; |
18 | 18 | require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php'; |
19 | 19 | |
| 20 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
| 21 | |
20 | 22 | // This needs to come after the mock image editor class is loaded. |
21 | 23 | parent::set_up(); |
22 | 24 | } |
diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php
index 02e0590a2e..66e1014a03 100644
a
|
b
|
class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { |
18 | 18 | require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php'; |
19 | 19 | require_once DIR_TESTROOT . '/includes/class-wp-test-stream.php'; |
20 | 20 | |
| 21 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
| 22 | |
21 | 23 | // This needs to come after the mock image editor class is loaded. |
22 | 24 | parent::set_up(); |
23 | 25 | } |
diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php
index 86d559145e..2cc73fdfa9 100644
a
|
b
|
class Tests_Image_Functions extends WP_UnitTestCase { |
25 | 25 | foreach ( glob( $folder ) as $file ) { |
26 | 26 | unlink( $file ); |
27 | 27 | } |
| 28 | |
| 29 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
28 | 30 | } |
29 | 31 | |
30 | 32 | /** |
diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
index 830359427a..df8d99ad91 100644
a
|
b
|
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
15 | 15 | parent::tear_down(); |
16 | 16 | } |
17 | 17 | |
| 18 | /** |
| 19 | * Set up the test fixture. |
| 20 | */ |
| 21 | public function set_up() { |
| 22 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
| 23 | |
| 24 | parent::set_up(); |
| 25 | } |
| 26 | |
18 | 27 | public function _make_attachment( $file, $parent_post_id = 0 ) { |
19 | 28 | $contents = file_get_contents( $file ); |
20 | 29 | $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); |
diff --git a/tests/phpunit/tests/image/resize.php b/tests/phpunit/tests/image/resize.php
index 5b302ce295..5043f4e4e6 100644
a
|
b
|
abstract class WP_Tests_Image_Resize_UnitTestCase extends WP_Image_UnitTestCase |
14 | 14 | parent::set_up(); |
15 | 15 | |
16 | 16 | add_filter( 'wp_image_editors', array( $this, 'wp_image_editors' ) ); |
| 17 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
17 | 18 | } |
18 | 19 | |
19 | 20 | public function wp_image_editors() { |
diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php
index ba4bedf51e..e55a757767 100644
a
|
b
|
CAP; |
33 | 33 | self::$_sizes = wp_get_additional_image_sizes(); |
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 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
37 | 38 | self::$large_id = $factory->attachment->create_upload_object( $filename ); |
38 | 39 | |
39 | 40 | $post_statuses = array( 'publish', 'future', 'draft', 'auto-draft', 'trash' ); |
… |
… |
EOF; |
3617 | 3618 | // Clean up the above filter. |
3618 | 3619 | remove_filter( 'wp_omit_loading_attr_threshold', '__return_null', 100 ); |
3619 | 3620 | } |
| 3621 | |
| 3622 | /** |
| 3623 | * Test the wp_default_image_output_mapping function. |
| 3624 | * |
| 3625 | * @ticket 55443 |
| 3626 | */ |
| 3627 | public function test_wp_default_image_output_mapping() { |
| 3628 | $mapping = wp_default_image_output_mapping(); |
| 3629 | $this->assertSame( array( 'image/jpeg' => 'image/webp' ), $mapping ); |
| 3630 | } |
3620 | 3631 | } |
3621 | 3632 | |
3622 | 3633 | /** |
diff --git a/tests/phpunit/tests/post/attachments.php b/tests/phpunit/tests/post/attachments.php
index 2922c185d2..5aa507248a 100644
a
|
b
|
|
6 | 6 | * @group upload |
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 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
| 14 | |
| 15 | parent::set_up(); |
| 16 | } |
9 | 17 | |
10 | 18 | public function tear_down() { |
11 | 19 | // Remove all uploads. |
diff --git a/tests/phpunit/tests/rest-api/rest-attachments-controller.php b/tests/phpunit/tests/rest-api/rest-attachments-controller.php
index 106906ee2b..588a84d0ea 100644
a
|
b
|
class WP_Test_REST_Attachments_Controller extends WP_Test_REST_Post_Type_Control |
93 | 93 | |
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 | remove_filter( 'image_editor_output_format', 'wp_default_image_output_mapping' ); |
96 | 97 | } |
97 | 98 | |
98 | 99 | public function wpSetUpBeforeRequest( $result ) { |