Gracefully skip media sideload for disallowed MIME types (e.g., SVG)#1221
Gracefully skip media sideload for disallowed MIME types (e.g., SVG)#1221Copilot wants to merge 3 commits into
Conversation
…SVG) Add an elseif check in try_save_featured_image() that detects when a downloaded file's MIME type is not in WordPress's allowed upload types. Instead of proceeding with media_handle_sideload() which would fail and log an error, it now gracefully skips the upload with a debug-level log message, cleans up the temporary file, and returns false. This prevents the "Sorry, you are not allowed to upload this file type" error spam in log reports when Feedzy uses its default feedzy.svg placeholder as a featured image during imports. Agent-Logs-Url: https://github.com/Codeinwp/feedzy-rss-feeds/sessions/0f3a59f0-d3d7-48d2-bf51-c093e46abd44 Co-authored-by: kushh23 <110405452+kushh23@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent repeated error-level logging when Feedzy falls back to an image URL whose MIME type is blocked by WordPress (notably SVG), by detecting disallowed MIME types before calling media_handle_sideload() and skipping the upload gracefully.
Changes:
- Added a new
elseifpath intry_save_featured_image()to detect a known-but-disallowed MIME type and skip the sideload. - Downgraded the “disallowed type” condition from error-level failures to debug logging, and cleaned up the downloaded temp file.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } 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 ), |
|
@copilot apply changes based on the comments in this thread |
…ions Lowercase the type and strip parameters (e.g., "; charset=UTF-8") so that content-type values from HTTP headers match get_allowed_mime_types() correctly and valid images are not incorrectly skipped. Agent-Logs-Url: https://github.com/Codeinwp/feedzy-rss-feeds/sessions/c5a4d11c-804a-4e60-8284-9695b1527dc8 Co-authored-by: kushh23 <110405452+kushh23@users.noreply.github.com>
Done in a776cbe. Added MIME type normalization (lowercase + strip parameters after |
🌍 i18n String Review Report📊 Summary
➕ Added Strings (1) - Click to expand
|
|
Plugin build for a776cbe is ready 🛎️!
Note You can preview the changes in the Playground |
feedzy_define_default_imagereturnsfeedzy.svgURL →feedzy_retrieve_imageuses it as fallback → import setsitem_img_pathto it →try_save_featured_imagetries to sideload SVG → WordPress blocks SVG → error log spamtry_save_featured_imageto check if the detected MIME type is allowed before attemptingmedia_handle_sideload, and gracefully skip with a debug log if not;) before comparison to avoid false rejections of valid imagesSummary
Added a check in
try_save_featured_image()(includes/admin/feedzy-rss-feeds-import.php) that detects when a downloaded file's MIME type (e.g.,image/svg+xml) is not in WordPress's allowed upload types list (get_allowed_mime_types()).Before: The code would always proceed to
media_handle_sideload(), which fails for disallowed types like SVG, generating error-level log entries that spam customer log reports.After: When a disallowed MIME type is detected, the code:
; charset=UTF-8)falsegracefully