diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index bdca0d2c08528..4b9aa76b94000 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -211,10 +211,27 @@ function get_default_block_editor_settings() { ); } + $allowed_mime_types = get_allowed_mime_types(); + + // Check if WebP images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { + unset( $allowed_mime_types['image/webp'] ); + } + + // Check if AVIF images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { + unset( $allowed_mime_types['image/avif'] ); + } + + // Check if HEIC images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) { + unset( $allowed_mime_types['image/heic'] ); + } + $editor_settings = array( 'alignWide' => get_theme_support( 'align-wide' ), 'allowedBlockTypes' => true, - 'allowedMimeTypes' => get_allowed_mime_types(), + 'allowedMimeTypes' => $allowed_mime_types, 'defaultEditorStyles' => $default_editor_styles, 'blockCategories' => get_default_block_categories(), 'isRTL' => is_rtl(), diff --git a/tests/phpunit/tests/blocks/editor.php b/tests/phpunit/tests/blocks/editor.php index 0682839605da9..a04d3638d745a 100644 --- a/tests/phpunit/tests/blocks/editor.php +++ b/tests/phpunit/tests/blocks/editor.php @@ -199,6 +199,7 @@ public function test_get_allowed_block_types_deprecated_filter_post_editor() { /** * @ticket 52920 + * @ticket 61167 */ public function test_get_default_block_editor_settings() { $settings = get_default_block_editor_settings(); @@ -300,6 +301,26 @@ public function test_get_default_block_editor_settings() { ); $this->assertIsInt( $settings['maxUploadFileSize'] ); $this->assertTrue( $settings['__unstableGalleryWithImageBlocks'] ); + + // Confirm that `allowedMimeTypes` matches the supported mime types. + $allowed_mime_types = get_allowed_mime_types(); + + // Check if WebP images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { + unset( $allowed_mime_types['image/webp'] ); + } + + // Check if AVIF images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) { + unset( $allowed_mime_types['image/avif'] ); + } + + // Check if HEIC images can be edited. + if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) { + unset( $allowed_mime_types['image/heic'] ); + } + + $this->assertSameSets( $allowed_mime_types, $settings['allowedMimeTypes'] ); } /**