From a59cea3c92076d990d3492dcfd8a40ff184b15c6 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Tue, 22 Jun 2021 23:11:02 +0000 Subject: [PATCH] Media: Prevent uploading and show an error message when the server doesn't support editing of WebP files and image sub-sizes cannot be created. Props adamsilverstein, desrosj, azaozz Fixes #53475 git-svn-id: https://develop.svn.wordpress.org/trunk@51211 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/functions.php | 7 +++++++ src/wp-includes/script-loader.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index c834a01ef4..8835ecfec4 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -3300,6 +3300,13 @@ function get_allowed_mime_types( $user = null ) { unset( $t['htm|html'], $t['js'] ); } + // Add WebP if the server supports it. + unset( $t['webp'] ); + + if ( wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) { + $t['webp'] = 'image/webp'; + } + /** * Filters list of allowed mime types and file extensions. * diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index 2e1e6668cd..c7a6963f73 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -851,7 +851,7 @@ function wp_default_scripts( $scripts ) { /* translators: %s: File name. */ 'file_exceeds_size_limit' => __( '%s exceeds the maximum upload size for this site.' ), 'zero_byte_file' => __( 'This file is empty. Please try another.' ), - 'invalid_filetype' => __( 'Sorry, this file type is not permitted for security reasons.' ), + 'invalid_filetype' => __( 'Sorry, this file type is not supported.' ), 'not_an_image' => __( 'This file is not an image. Please try another.' ), 'image_memory_exceeded' => __( 'Memory exceeded. Please try another smaller file.' ), 'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ),