diff --git a/wp-includes/compat.php b/wp-includes/compat.php index 59e5700439..aec742d77a 100644 --- a/wp-includes/compat.php +++ b/wp-includes/compat.php @@ -371,7 +371,7 @@ if ( ! function_exists( 'is_iterable' ) ) { } } -// WebP constants may not be defined, even in cases where the format is supported. +// WebP constants are only defined in PHP 7.1+. if ( ! defined( 'IMAGETYPE_WEBP' ) ) { define( 'IMAGETYPE_WEBP', 18 ); } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3bb257ab8b..d8e90d82c7 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3079,9 +3079,11 @@ function wp_get_image_mime( $file ) { return false; } - // Add WebP fallback detection when image library doesn't support WebP. - // Note: detection values come from LibWebP, see - // https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30 + /* + * Add WebP fallback detection when image library doesn't support WebP. + * Note: detection values come from LibWebP, see + * https://github.com/webmproject/libwebp/blob/master/imageio/image_dec.c#L30 + */ $magic = bin2hex( $magic ); if ( // RIFF. diff --git a/wp-includes/media.php b/wp-includes/media.php index 82d1b32627..100fe5dfab 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -5024,7 +5024,7 @@ function wp_getimagesize( $filename, array &$image_info = null ) { * * @since 5.8.0 * - * @param [type] $filename Path to a WebP file. + * @param string $filename Path to a WebP file. * @return array $webp_info { * An array of WebP image information. * @@ -5038,9 +5038,11 @@ function wp_get_webp_info( $filename ) { $width = false; $height = false; $type = false; + if ( ! 'image/webp' === wp_get_image_mime( $filename ) ) { return compact( 'width', 'height', 'type' ); } + try { $handle = fopen( $filename, 'rb' ); if ( $handle ) { @@ -5083,6 +5085,7 @@ function wp_get_webp_info( $filename ) { } } catch ( Exception $e ) { } + return compact( 'width', 'height', 'type' ); } @@ -5097,6 +5100,7 @@ function wp_get_webp_info( $filename ) { function _wp_webp_is_lossy( $filename ) { $webp_info = wp_get_webp_info( $filename ); $type = $webp_info['type']; + return $type && 'lossy' === $type; } @@ -5113,17 +5117,19 @@ function _wp_webp_is_lossy( $filename ) { function _wp_get_image_size( $filename, &$imageinfo = array() ) { // Try getimagesize() first. $info = getimagesize( $filename, $imageinfo ); + if ( false !== $info ) { return $info; } - // For PHP versions that don't support WebP images, extract the image - // size info from the file headers. + + // For PHP versions that don't support WebP images, + // extract the image size info from the file headers. if ( 'image/webp' === wp_get_image_mime( $filename ) ) { $webp_info = wp_get_webp_info( $filename ); $width = $webp_info['width']; $height = $webp_info['height']; - // Mimic the native return format. + // Mimic the native return format. if ( $width && $height ) { return array( $width, diff --git a/wp-includes/version.php b/wp-includes/version.php index d10ca5ed0d..3a9d807c54 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.8-alpha-50813'; +$wp_version = '5.8-alpha-50814'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.