Skip to content
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

Helpful error on upload of image type not supported by server #68644

Open
wants to merge 4 commits into
base: trunk
Choose a base branch
from

Conversation

adamsilverstein
Copy link
Member

@adamsilverstein adamsilverstein commented Jan 13, 2025

What?

Reject upload of image types not supported by server - match the behavior when trying to upload the same file types in the media library.

This will fix this issue reported in Trac: https://core.trac.wordpress.org/ticket/61167

Why?

Currently users can upload AVIF, WebP or HEIC images even if their web server doesn't support - meaning WordPress will be unable to process the uploaded image into the sub-sized images used for display on the front end. This matches what we do in the media library - we help users by suggesting they convert their images before uploading them

While the upload might look like it is working currently, since the sub-sized images are not created, the front experience is sub-par and the user might never realize this.

How?

  • detect webp, avif and heic support server side - similar to the media library
  • pass those values from settings thru to the media upload component
  • reject uploads the server cannot handle with the same error message used in the media library

Testing Instructions

  1. use a server that doesn't support AVIF images
  2. try uploading an AVIF image
  3. before the patch, check the web page on the front end - note no srcset is created, bedcause sub-sized images were not created
  4. apply the patch and try uploading an avif again
  5. note the error message

Screenshots or screencast

Media library error:
media library error

Post editor error:
post editor error

Missing srcset
srcset missing

Copy link

github-actions bot commented Jan 13, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: adamsilverstein <adamsilverstein@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@adamsilverstein adamsilverstein added the [Type] Bug An existing feature does not function as intended label Jan 13, 2025
@Mamaduka Mamaduka added the [Feature] Media Anything that impacts the experience of managing media label Jan 13, 2025
@Mamaduka Mamaduka self-requested a review January 13, 2025 20:09
Comment on lines +92 to +107
$settings['typesNotSupportedByServer'] = array();

// Check if WebP images can be edited.
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
$settings['typesNotSupportedByServer']['image/webp'] = true;
}

// Check if AVIF images can be edited.
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
$settings['typesNotSupportedByServer']['image/avif'] = true;
}

// Check if HEIC images can be edited.
if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/heic' ) ) ) {
$settings['typesNotSupportedByServer']['image/heic'] = true;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The release-specific code needs to go into the compat/wordpress-6.8 (next major version) folder. This will probably be a part of the get_default_block_editor_settings function during backport.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok thanks for clarifying. I will move

@Mamaduka
Copy link
Member

Do you think we should return this error on the REST API level? The uploadMedia is just one of its consumers; I'm guessing others would also benefit from his helpful error.

Plus, it removes the need to introduce another config argument for media upload utils.

@Mamaduka
Copy link
Member

Related:

@adamsilverstein
Copy link
Member Author

Do you think we should return this error on the REST API level? The uploadMedia is just one of its consumers; I'm guessing others would also benefit from his helpful error.

Plus, it removes the need to introduce another config argument for media upload utils.

Good idea, I can try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Media Anything that impacts the experience of managing media [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants