From b6cd9f19503982fdcae98eb8b2a79d9da94a3674 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 23 Oct 2024 10:56:18 -0600 Subject: [PATCH] Editor: limit uploads to supported mime types --- src/wp-includes/block-editor.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index bdca0d2c08528..6cc8bb89006d1 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -211,10 +211,19 @@ function get_default_block_editor_settings() { ); } + $allowed_mime_types = get_allowed_mime_types(); + + // Iterate through mime types and check if they are supported by the image editor. + foreach ( $allowed_mime_types as $mime_type_extensions => $mime_type ) { + if ( ! wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) { + unset( $allowed_mime_types[ $mime_type_extensions ] ); + } + } + $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(),