Problem
When using the Gutenberg media uploader, uploading a file can result in a NotFoundHttpException (or other errors depending on error handling/logging configuration). This happens because MediaUploader.php uses the ternary shorthand operator (?:) on $file_settings['max_resolution']:
PHP
$image_settings['max_dimensions'] = $file_settings['max_resolution'] ?: $image_settings['max_dimensions'];
If the max_resolution key is not present in the $file_settings array, PHP raises an Undefined array key warning/notice. In environments where notices are strictly handled or logged/suppressed via custom error handlers, this breaks the media upload flow.
Proposed Solution
Replace the ternary shorthand operator (?:) with the null-coalescing operator (??), which safely checks for the existence and null-status of the key without triggering an undefined index notice:
PHP
$image_settings['max_dimensions'] = $file_settings['max_resolution'] ?? $image_settings['max_dimensions'];
Steps to Reproduce
Attempt a media upload through the Gutenberg editor where $file_settings does not explicitly define a max_resolution key.
Observe the PHP notice / subsequent exception preventing a successful upload response.
Would you like any adjustments made to the title or description before you post it?
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | gutenberg-max_resolution-fix.patch | 1.46 KB | pemson18 |
| #4 | gutenberg-max_resolution-fix.patch | 451 bytes | pemson18 |
Comments
Comment #2
pemson18Comment #3
pemson18Comment #4
pemson18Comment #5
pemson18