From 2c7ce700201489d1412fc90933bd6cb13418b20f Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 8 May 2024 12:49:21 -0600 Subject: [PATCH 1/3] allowedMimeTypes: filter types that are not supported by the server. --- src/wp-includes/block-editor.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index e04b012e7dd08..b9288e8af710b 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -211,10 +211,30 @@ function get_default_block_editor_settings() { ); } + $allowed_mime_types = get_allowed_mime_types(); + // Filter image types that are not supported by the server. + $types_to_test_for_support = array( 'image/webp', 'image/avif' ); + foreach ( $types_to_test_for_support as $type ) { + error_log( 'checking type:' . $type ); + error_log( wp_image_editor_supports( array( 'mime_type' => $type ) ) ? 'supported' : 'not supported' ); + + if ( ! wp_image_editor_supports( array( 'mime_type' => $type ) ) ) { + error_log( 'removing by type:' . $type ); + + $key = array_search( $type, $allowed_mime_types, true ); + error_log( 'found key:' . $key ); + + if ( $key !== false ) { + error_log( 'removing by key:' . $key ); + unset( $allowed_mime_types[ $key ] ); + } + } + } + $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(), From 93c4813115fbd9e49d726075a54fbb8887bf9814 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 8 May 2024 12:50:47 -0600 Subject: [PATCH 2/3] Cleanup --- src/wp-includes/block-editor.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index b9288e8af710b..1dd6140c743b0 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -211,21 +211,13 @@ function get_default_block_editor_settings() { ); } - $allowed_mime_types = get_allowed_mime_types(); // Filter image types that are not supported by the server. + $allowed_mime_types = get_allowed_mime_types(); $types_to_test_for_support = array( 'image/webp', 'image/avif' ); foreach ( $types_to_test_for_support as $type ) { - error_log( 'checking type:' . $type ); - error_log( wp_image_editor_supports( array( 'mime_type' => $type ) ) ? 'supported' : 'not supported' ); - if ( ! wp_image_editor_supports( array( 'mime_type' => $type ) ) ) { - error_log( 'removing by type:' . $type ); - $key = array_search( $type, $allowed_mime_types, true ); - error_log( 'found key:' . $key ); - if ( $key !== false ) { - error_log( 'removing by key:' . $key ); unset( $allowed_mime_types[ $key ] ); } } From 760f13f0c26c491aa520e3bce41645e25e0acf0a Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Wed, 8 May 2024 12:56:20 -0600 Subject: [PATCH 3/3] Use Yoda consitionals, I must --- src/wp-includes/block-editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/block-editor.php b/src/wp-includes/block-editor.php index 1dd6140c743b0..6565eb263f1b7 100644 --- a/src/wp-includes/block-editor.php +++ b/src/wp-includes/block-editor.php @@ -217,7 +217,7 @@ function get_default_block_editor_settings() { foreach ( $types_to_test_for_support as $type ) { if ( ! wp_image_editor_supports( array( 'mime_type' => $type ) ) ) { $key = array_search( $type, $allowed_mime_types, true ); - if ( $key !== false ) { + if ( false !== $key ) { unset( $allowed_mime_types[ $key ] ); } }