Skip to content

Only attempt to get dominant colour for image mime types. - #2264

Merged
westonruter merged 6 commits into
WordPress:trunkfrom
peterwilsoncc:fix/1957-image-placeholder-mime-types
Jan 13, 2026
Merged

westonruter merged 6 commits into
WordPress:trunkfrom
peterwilsoncc:fix/1957-image-placeholder-mime-types

Conversation

@peterwilsoncc

Copy link
Copy Markdown
Contributor

Summary

Modifies the dominant colour detection function to use an allow list of mime types based on image types supported in WordPress. This prevents the feature from running on other media types such as video, zips, etc.

Fixes #1957

Relevant technical choices

Runs the colour detection on the supported mime types

$supported_mime_types = array(
	'image/jpeg',
	'image/png',
	'image/gif',
	'image/webp',
	'image/avif',
);

Introduces the filter dominant_color_supported_mime_types to allow third party developers to extend the feature.

Use of AI Tools

N/A

@codecov

codecov Bot commented Nov 17, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.21%. Comparing base (49f2d7a) to head (c07f4dd).
⚠️ Report is 12 commits behind head on trunk.

Additional details and impacted files
@@            Coverage Diff             @@
##            trunk    #2264      +/-   ##
==========================================
+ Coverage   69.17%   69.21%   +0.04%     
==========================================
  Files          90       90              
  Lines        7696     7703       +7     
==========================================
+ Hits         5324     5332       +8     
+ Misses       2372     2371       -1     
Flag Coverage Δ
multisite 69.21% <100.00%> (+0.04%) ⬆️
single 35.41% <90.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@westonruter westonruter added [Plugin] Image Placeholders Formerly "Dominant Color Images" [slug: dominant-color-images] [Type] Bug An existing feature is broken labels Dec 12, 2025
Comment thread plugins/dominant-color-images/helper.php Outdated
Comment thread plugins/dominant-color-images/helper.php Outdated
Comment thread plugins/dominant-color-images/helper.php Outdated
Co-authored-by: Weston Ruter <westonruter@gmail.com>

@adamsilverstein adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me.

@westonruter westonruter added this to the webp-uploads n.e.x.t milestone Jan 12, 2026
@westonruter

Copy link
Copy Markdown
Member

@peterwilsoncc Is this still a draft on purpose?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 restricts dominant color detection to supported image MIME types only, preventing the feature from attempting to process non-image attachments like videos or ZIP files. The change replaces a PDF-specific check with an allowlist approach.

Changes:

  • Replaced the blocklist approach (checking for application/pdf) with an allowlist of supported image MIME types
  • Added a filter hook to allow third-party developers to extend supported MIME types
  • Updated error handling to return a more generic unsupported_attachment_type error

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/dominant-color-images/helper.php
Comment thread plugins/dominant-color-images/helper.php
@peterwilsoncc
peterwilsoncc force-pushed the fix/1957-image-placeholder-mime-types branch from 1d7d048 to c07f4dd Compare January 12, 2026 23:07
@peterwilsoncc

Copy link
Copy Markdown
Contributor Author

@peterwilsoncc Is this still a draft on purpose?

From memory I wanted to add a test but forgot to do so after 6.9 dropped. I've added it in 0e70a0c

@peterwilsoncc
peterwilsoncc marked this pull request as ready for review January 12, 2026 23:11
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: westonruter <westonruter@git.wordpress.org>
Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: kartikmehta8 <kartikmehta@git.wordpress.org>
Co-authored-by: sarthak-19 <sarthak8858@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@westonruter
westonruter requested a review from Copilot January 12, 2026 23:52
@westonruter
westonruter merged commit c9720dc into WordPress:trunk Jan 13, 2026
41 of 42 checks passed
@peterwilsoncc
peterwilsoncc deleted the fix/1957-image-placeholder-mime-types branch January 13, 2026 21:07
@peterwilsoncc
peterwilsoncc removed the request for review from Copilot March 24, 2026 23:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Plugin] Image Placeholders Formerly "Dominant Color Images" [slug: dominant-color-images] [Type] Bug An existing feature is broken

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Site crashes when uploading a video

4 participants