Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #872 Prevent fatal error if returned extension value is false #873

Merged
merged 2 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions classes/Optimization/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion classes/Optimization/Process/AbstractProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' )
Expand Down
Loading