diff --git a/includes/admin/feedzy-rss-feeds-import.php b/includes/admin/feedzy-rss-feeds-import.php index 701eaf3f..daf69a32 100644 --- a/includes/admin/feedzy-rss-feeds-import.php +++ b/includes/admin/feedzy-rss-feeds-import.php @@ -3036,6 +3036,11 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title $type = $this->get_file_type_by_url( $img_source_url ); } + // Normalize the MIME type: lowercase and strip any parameters (e.g., "; charset=UTF-8"). + if ( ! empty( $type ) ) { + $type = strtolower( trim( explode( ';', $type )[0] ) ); + } + // the file is downloaded with a .tmp extension // if the URL mentions the extension of the file, the upload succeeds // but if the URL is like https://source.unsplash.com/random, then the upload fails @@ -3061,6 +3066,23 @@ private function try_save_featured_image( $img_source_url, $post_id, $post_title return false; } + } elseif ( ! empty( $type ) ) { + // The file type is not allowed by WordPress (e.g., SVG). + // Skip the upload gracefully to avoid error log spam. + Feedzy_Rss_Feeds_Log::debug( + // translators: %1$s is the MIME type, %2$s is the image source URL. + sprintf( __( 'Skipping image upload — file type "%1$s" is not allowed by WordPress: %2$s', 'feedzy-rss-feeds' ), $type, $img_source_url ), + array( + 'post_id' => $post_id, + 'img_source_url' => $img_source_url, + 'mime_type' => $type, + ) + ); + + // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink + unlink( $local_file ); + + return false; } $file_array['tmp_name'] = $local_file;