Skip to content

Commit 18f9911

Browse files
Disable editor uploading WebP, AVIF or HEIC when the server doesn’t support these types
1 parent be9a01a commit 18f9911

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/wp-includes/block-editor.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,19 @@ function get_default_block_editor_settings() {
213213

214214
$allowed_mime_types = get_allowed_mime_types();
215215

216-
// Iterate through mime types and remove those unsupported by the image editor.
217-
foreach ( $allowed_mime_types as $mime_type_extensions => $mime_type ) {
218-
if ( ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) {
219-
unset( $allowed_mime_types[ $mime_type_extensions ] );
220-
}
216+
// Check if WebP images can be edited.
217+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
218+
unset( $allowed_mime_types['image/webp'] );
219+
}
220+
221+
// Check if AVIF images can be edited.
222+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
223+
unset( $allowed_mime_types['image/avif'] );
224+
}
225+
226+
// Check if HEIC images can be edited.
227+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) {
228+
unset( $allowed_mime_types['image/heic'] );
221229
}
222230

223231
$editor_settings = array(

tests/phpunit/tests/blocks/editor.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function test_get_allowed_block_types_deprecated_filter_post_editor() {
199199

200200
/**
201201
* @ticket 52920
202+
* @ticket 61167
202203
*/
203204
public function test_get_default_block_editor_settings() {
204205
$settings = get_default_block_editor_settings();
@@ -300,6 +301,26 @@ public function test_get_default_block_editor_settings() {
300301
);
301302
$this->assertIsInt( $settings['maxUploadFileSize'] );
302303
$this->assertTrue( $settings['__unstableGalleryWithImageBlocks'] );
304+
305+
// Confirm that `allowedMimeTypes` matches the supported mime types.
306+
$allowed_mime_types = get_allowed_mime_types();
307+
308+
// Check if WebP images can be edited.
309+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
310+
unset( $allowed_mime_types['image/webp'] );
311+
}
312+
313+
// Check if AVIF images can be edited.
314+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
315+
unset( $allowed_mime_types['image/avif'] );
316+
}
317+
318+
// Check if HEIC images can be edited.
319+
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) {
320+
unset( $allowed_mime_types['image/heic'] );
321+
}
322+
323+
$this->assertSameSets( $allowed_mime_types, $settings['allowedMimeTypes'] );
303324
}
304325

305326
/**

0 commit comments

Comments
 (0)