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?

Comments

pemson18 created an issue. See original summary.

pemson18’s picture

StatusFileSize
new418 bytes
pemson18’s picture

StatusFileSize
new417 bytes
pemson18’s picture

StatusFileSize
new451 bytes
pemson18’s picture

StatusFileSize
new1.46 KB