From a5b782019155e99326c7fddf1b031750b0c50c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Perona?= Date: Fri, 19 Apr 2024 12:54:58 -0400 Subject: [PATCH] Fixes #872 Prevent fatal error if returned extension value is false (#873) --- classes/Optimization/File.php | 5 ++--- classes/Optimization/Process/AbstractProcess.php | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/classes/Optimization/File.php b/classes/Optimization/File.php index 6173b204..7c2fb181 100644 --- a/classes/Optimization/File.php +++ b/classes/Optimization/File.php @@ -745,10 +745,9 @@ public function get_mime_type() { /** * Get the file extension. * - * @since 1.9 - * @author Grégory Viguier + * @since 1.9 * - * @return string|null + * @return string|false */ public function get_extension() { return $this->get_file_type()->ext; diff --git a/classes/Optimization/Process/AbstractProcess.php b/classes/Optimization/Process/AbstractProcess.php index 15b4358b..bbe47b48 100644 --- a/classes/Optimization/Process/AbstractProcess.php +++ b/classes/Optimization/Process/AbstractProcess.php @@ -581,7 +581,12 @@ public function optimize_size( $size, $optimization_level = null ) { // This file type is not supported. $extension = $file->get_extension(); - if ( '' === $extension ) { + if ( ! $extension ) { + $response = new WP_Error( + 'extension_not_mime', + __( 'This file has an extension that does not match a mime type.', 'imagify' ) + ); + } elseif ( '' === $extension ) { $response = new WP_Error( 'no_extension', __( 'With no extension, this file cannot be optimized.', 'imagify' )