mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
Media: Avoid an infinite loop between wp_getimagesize() and wp_get_image_mime().
As a result of the recent changes, both functions were calling each other if the `exif` PHP extension is not available. The issue is now resolved by calling the `getimagesize()` PHP function directly, instead of the `wp_getimagesize()` wrapper. Follow-up to [50146], [50810], [50814], [50815], [50818-50821]. See #35725. git-svn-id: https://develop.svn.wordpress.org/trunk@50822 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
630399eb20
commit
ea4707d927
@ -3044,6 +3044,7 @@ function wp_check_filetype_and_ext( $file, $filename, $mimes = null ) {
|
||||
* This depends on exif_imagetype() or getimagesize() to determine real mime types.
|
||||
*
|
||||
* @since 4.7.1
|
||||
* @since 5.8.0 Added support for WebP images.
|
||||
*
|
||||
* @param string $file Full path to the file.
|
||||
* @return string|false The actual mime type or false if the type cannot be determined.
|
||||
@ -3059,8 +3060,18 @@ function wp_get_image_mime( $file ) {
|
||||
$imagetype = exif_imagetype( $file );
|
||||
$mime = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
|
||||
} elseif ( function_exists( 'getimagesize' ) ) {
|
||||
$imagesize = wp_getimagesize( $file );
|
||||
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
|
||||
// Don't silence errors when in debug mode, unless running unit tests.
|
||||
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
|
||||
&& ! defined( 'WP_RUN_CORE_TESTS' )
|
||||
) {
|
||||
// Not using wp_getimagesize() here to avoid an infinite loop.
|
||||
$imagesize = getimagesize( $file );
|
||||
} else {
|
||||
// phpcs:ignore WordPress.PHP.NoSilencedErrors
|
||||
$imagesize = @getimagesize( $file );
|
||||
}
|
||||
|
||||
$mime = ( isset( $imagesize['mime'] ) ) ? $imagesize['mime'] : false;
|
||||
} else {
|
||||
$mime = false;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user