-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Editor: Filter file input accept attribute based on upload_mimes #73562
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
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Dynamically computes the file input accept attribute based on WordPress's allowedMimeTypes (from the upload_mimes filter) to prevent users from selecting unsupported file types. This fixes an issue where users could select HEIC files for upload even when the server doesn't support them (lacks Imagick with HEIC support), leading to confusing upload failures. Changes: - MediaPlaceholder: Retrieves allowedMimeTypes from editor settings and computes specific MIME type list for the accept attribute - MediaReplaceFlow: Applies same logic for media replacement flow - Image Block: Removes hardcoded accept="image/*" to allow dynamic computation - Falls back to wildcard (e.g., "image/*") when allowedMimeTypes is unavailable Fixes #73558
228be09 to
35375cf
Compare
|
Size Change: +261 B (+0.01%) Total Size: 2.54 MB
ℹ️ View Unchanged
|
|
Nice one, thanks for putting this PR up! Computing the I've rebased and pushed a couple of updates:
I'm sure there are other places we could update, too, but I think this is in a pretty place to try out. Keen to hear what other folks think, too! |
|
Flaky tests detected in 29ad1e2. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19689778692
|
aaronrobertshaw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ramonjd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good change - I tested with image/gallery/media + text blocks.
<input type="file" ... element looks good.
I left some questions/suggestions that could be done here or in a follow up.
Before
Kapture.2025-11-26.at.13.11.42.mp4
After
Kapture.2025-11-26.at.13.15.29.mp4
packages/block-editor/src/components/media-placeholder/utils.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/media-replace-flow/index.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/media-placeholder/utils.js
Outdated
Show resolved
Hide resolved
packages/block-editor/src/components/media-placeholder/index.js
Outdated
Show resolved
Hide resolved
…eMemo for computed accept attribute to enhance performance and prevent unnecessary recalculations.
andrewserong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good to me, too. I'll merge this in.
Thanks for the collaboration, everyone! 🙇

What?
Dynamically computes the file input
acceptattribute based on WordPress'sallowedMimeTypes(from theupload_mimesfilter) to prevent users from selecting unsupported file types.Why?
Fixes #73558
Users could select HEIC files for upload even when the server doesn't support them (lacks Imagick with HEIC support), leading to confusing upload failures. The file picker would show all image types as selectable, but HEIC uploads would fail.
How?
Changes:
allowedMimeTypesfrom editor settings and computes specific MIME type list for the accept attributeaccept="image/*"to allow dynamic computation based on server capabilities"image/*") whenallowedMimeTypesis unavailableImplementation Details:
get_allowed_mime_types()which applies theupload_mimesfiltergetSettings().allowedMimeTypesin the block editorallowedTypespropaccept="image/jpeg,image/png,image/gif,image/webp,image/avif"instead ofaccept="image/*"Testing Instructions
Setup
Test
Verify in DevTools
<input type="file">elementaccept="image/*"accept="image/jpeg,image/png,image/gif,image/webp,image/avif,..."(without image/heic)Screencast
Before this PR:
grey.out.mov
After this PR:
greyed.out.fix.mov
Note
As mentioned in the original issue, this only affects the file picker dialog. Drag-and-drop will still allow selecting HEIC files, but they will fail to upload with an appropriate error message (existing WordPress behavior).