Make WordPress Core

Opened 21 months ago

Last modified 20 months ago

#56349 assigned enhancement

Update WordPress core functions to support multiple MIME types

Reported by: joegrainger's profile joegrainger Owned by: joegrainger's profile joegrainger
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch needs-unit-tests
Focuses: performance Cc:


As part of an effort to improve performance within WordPress, WebP image generation has been introduced into core for new uploads. In order for WebP images to be used outside of user-editable content, WordPress core image functions will be updated to allow developers to specify what MIME type to return for an attachment.

The proposal is to update the wp_get_attachment_image_src function by replacing the $icon parameter with a $args parameter. This new parameter will allow developers to requests a specific attachment mime type source.

To accommodate this change a new wp_get_attachment_preview_src function will be created. This function is intended to replace all instances in WordPress core where wp_get_attachment_image_src is called and the $icon parameter is set to true.

Additionally, all core functions that have an $icon parameter will be updated to accept the new $args parameter and pass this to the wp_get_attachment_image_src function.

For backward compatibility the $args parameter can be passed as a boolean and work the same as the original $icon parameter.

The $args parameter will accept 2 keys, icon and mime_type. The icon argument will work the same as the original $icon parameter and will return the files MIME type icon when set to true. The mime_type argument is used to define the preferred image MIME to return. If the MIME type requested is not available, the original image MIME type is returned.

Lastly, the image_downsize and image_get_intermediate_size functions will be updated with a new $mime_type parameter. This will be used to return the correct file for the specified MIME type.

Patch incoming.

Change History (5)

This ticket was mentioned in PR #3074 on WordPress/wordpress-develop by jjgrainger.

21 months ago

  • Keywords has-patch added

#2 @flixos90
21 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to 6.1

This ticket was mentioned in Slack in #core-media by adamsilverstein. View the logs.

20 months ago

#4 @adamsilverstein
20 months ago

  • Milestone changed from 6.1 to Future Release

This is no longer needed for 6.1 because the mime output approach was changed and multi-mime was removed. This will be valuable if we re-introduce multi-mime support so marking as "Future Release"

adamsilverstein commented on PR #3074:

20 months ago

@jjgrainger - Since we reverted multi-mime support this is not currently needed, though it will come in handy if we reintroduce the feature so thanks for your work here! Closing for now.

Note: See TracTickets for help on using tickets.