Skip to content

Gracefully skip media sideload for disallowed MIME types (e.g., SVG)#1221

Open
Copilot wants to merge 3 commits into
developmentfrom
copilot/prevent-media-library-upload-errors
Open

Gracefully skip media sideload for disallowed MIME types (e.g., SVG)#1221
Copilot wants to merge 3 commits into
developmentfrom
copilot/prevent-media-library-upload-errors

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

  • Analyze the code flow: feedzy_define_default_image returns feedzy.svg URL → feedzy_retrieve_image uses it as fallback → import sets item_img_path to it → try_save_featured_image tries to sideload SVG → WordPress blocks SVG → error log spam
  • Fix try_save_featured_image to check if the detected MIME type is allowed before attempting media_handle_sideload, and gracefully skip with a debug log if not
  • Normalize MIME type (lowercase + strip parameters after ;) before comparison to avoid false rejections of valid images
  • Run validation (Code Review ✅, CodeQL ✅)

Summary

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:

  1. Normalizes the MIME type (lowercase, strip parameters like ; charset=UTF-8)
  2. Logs a debug-level message (not error) explaining the skip
  3. Cleans up the temporary downloaded file
  4. Returns false gracefully

…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>
Copilot AI changed the title [WIP] Fix Media Library upload errors for default placeholder image Gracefully skip media sideload for disallowed MIME types (e.g., SVG) May 11, 2026
Copilot AI requested a review from kushh23 May 11, 2026 18:33
@kushh23 kushh23 requested a review from Copilot May 18, 2026 21:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 elseif path in try_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.

Comment on lines +3064 to +3069
} 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 ),
@kushh23
Copy link
Copy Markdown

kushh23 commented May 18, 2026

@copilot apply changes based on the comments in this thread

@kushh23 kushh23 changed the base branch from master to development May 18, 2026 21:49
…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>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 18, 2026

@copilot apply changes based on the comments in this thread

Done in a776cbe. Added MIME type normalization (lowercase + strip parameters after ;) before the in_array() check, so content-type values like image/jpeg; charset=UTF-8 or Image/JPEG correctly match the allowed list and aren't incorrectly skipped.

@kushh23 kushh23 marked this pull request as ready for review May 19, 2026 10:07
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented May 19, 2026

🌍 i18n String Review Report

📊 Summary

Category Count
➕ Added 1
➖ Removed 0
🔄 Changed 0
Total 1
➕ Added Strings (1) - Click to expand
String Location Words Suggested Match
Skipping image upload — file type "%1$s" is not... includes/admin/feedzy-rss... 13 No close match
Total 13

@pirate-bot
Copy link
Copy Markdown
Contributor

Plugin build for a776cbe is ready 🛎️!

Note

You can preview the changes in the Playground

@kushh23 kushh23 added the pr-checklist-skip Allow this Pull Request to skip checklist. label May 19, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent Media Library upload errors for default placeholder image (feedzy.svg)

5 participants