Repository navigation
Media: Avoid showing the filename twice for upload size errors. - #15265
abhishekfdd wants to merge 1 commit into
Conversation
The media upload status error template already shows the filename next to each message, but `wp.Uploader.errorMap.FILE_SIZE_ERROR` also inserted the filename into its message, so size errors in the media grid and modal named the file twice. Add a `file_size_exceeded` string to `pluploadL10n` that does not include the filename and use it for `FILE_SIZE_ERROR`. The shared template is unchanged, so other upload errors keep their filename and messages remain escaped. See #64931.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
In the media grid and media modal, upload size errors show the filename twice: once in the
upload-error-filenamespan of thetmpl-uploader-status-errortemplate, and again inside the message, becausewp.Uploader.errorMap.FILE_SIZE_ERRORinsertsfile.nameintopluploadL10n.file_exceeds_size_limit.This PR is an alternative approach to #11332. Thanks to Presskopp for the original report and patch.
Changes
file_size_exceededstring topluploadL10ninscript-loader.php: "This file exceeds the maximum upload size for this site."Uploader.errorMap.FILE_SIZE_ERRORinwp-plupload.jsnow returns that string instead of interpolating the filename.The shared
tmpl-uploader-status-errortemplate inmedia-template.phpis unchanged. It still shows the filename in its own span for every error, and the message stays escaped with{{ data.message }}. #11332 removes the filename span and switches to{{{ data.message }}}, which drops the filename from all other upload errors (for example, disallowed file types) and stops escaping all error messages, including server- and plugin-supplied ones.handlers.js(uploadSizeError(), used by the "Add New Media File" screen) is unchanged as well. It renders only the message, with no separate filename, sofile_exceeds_size_limitand its%sremain correct there.Notes
FILE_SIZE_ERRORstays a function rather than becoming a plain string, so external code callingwp.Uploader.errorMap.FILE_SIZE_ERROR( file )keeps working. Core's own caller already handles both forms.wp.Uploader.errorsmessages without the filename will no longer see the filename in the size error message. The file is still available on the error model (error.get( 'file' )).max_file_sizeis filtered abovewp_max_upload_size()(for example viaplupload_default_settings), theupload-mediapipeline's own size check rejects the file with a message that also contains the filename. That edge case is noted on the ticket as a follow-up.Testing
Tested on a local
wordpress-developenvironment with a temporary mu-plugin that filtersupload_size_limitdown to 100 KB, and a second one that makeswp_handle_upload_prefilterreturn the errorBlocked <b>by plugin</b>for a specific file. Both were removed afterwards and are not part of this PR.Results in Media > Library (grid), compared across trunk, #11332, and this PR. Chromium uses the client-side (REST) upload pipeline, and WebKit uses the classic
async-upload.phppath..exe,.svg)E2E:
tests/e2e/specs/media-library-client-side-upload.test.js.upload-error-filenamechecks at lines 447, 643 and 893 ("shows an error for a disallowed file type", "surfaces a pipeline error with its message and file name", "reports the HEIC error when neither the browser nor the server can convert it"). Each fails with "element(s) not found".Also ran
npm run build:dev,npm run grunt -- jshint:corejs(no issues), andphpcsonscript-loader.php(no issues).Trac ticket: https://core.trac.wordpress.org/ticket/64931
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Implementing the change, running the local and e2e test comparisons, and preparing this PR. I reviewed the code and test results and take responsibility for the change.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.