Repository navigation
Media: Prevent PHP warnings in wp_get_missing_image_subsizes() when image dimensions are missing - #14861
Media: Prevent PHP warnings in wp_get_missing_image_subsizes() when image dimensions are missing#14861abhishekfdd wants to merge 1 commit into
wp_get_missing_image_subsizes() when image dimensions are missing#14861Conversation
… image dimensions are missing. When the attachment metadata does not contain a `width` or `height` value, for example for SVG files added by plugins, broken uploads, or migrated content, `wp_get_missing_image_subsizes()` would trigger "Undefined array key" warnings. Missing dimensions now fall back to `0`. The return value is unchanged: no sub-sizes are considered possible without both dimensions, so an empty array is still returned and passed through the `wp_get_missing_image_subsizes` filter. Includes unit tests. See #57813.
|
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. |
The template has a required "Use of AI Tools" section, so I filled it in. Please check that the "Used for" line matches how you see it.
wp_get_missing_image_subsizes()reads$image_meta['width']and$image_meta['height']without checking that they exist. For attachments whose metadata lacks dimensions (SVGs added by plugins, broken uploads, migrated content), this triggers "Undefined array key" warnings.This PR uses
isset()checks so that missing dimensions fall back to0. The return value is unchanged; only the warning is removed. With a zero dimension,image_resize_dimensions()rules out every sub-size, so the function still returns an empty array, and the result still passes through thewp_get_missing_image_subsizesfilter exactly as before.Testing
New test class
Tests_Media_wpGetMissingImageSubsizes:Undefined array key "width"/Undefined array key "height"warning; with this fix all 4 pass.wp_get_missing_image_subsizesfilter is still called, receiving an empty array and the attachment ID, when width/height are missing.thumbnail).Commands:
All pass.
phpcsis clean on both changed files.Trac ticket: https://core.trac.wordpress.org/ticket/57813
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Local environment setup, running tests, implementing the fix, adding the filter test, and coding-standards cleanup; the changes were reviewed by me.
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.