Make WordPress Core

Opened 6 years ago

Last modified 4 years ago

#43023 new enhancement

Make Core Image Handling More Extensible

Reported by: blobfolio's profile blobfolio Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.1
Component: Media Keywords:
Focuses: Cc:


As we are beginning to see many new and promising formats such as WebP (#35725), APNG, and HEIF/HEVC (#42775), it is probably time to revisit all of the image-related code in the Core, providing filters and hooks so that plugins and themes can choose to support them.

Based on the work in #35725, it is clear there are a number of areas with insufficient extensibility, making it impossible for such work to be done by third-party code.


getimagesize(): Due to various bugs and inconsistencies within PHP, direct calls to this function should be replaced with a wrapper function capable of providing filtered responses. #35725 includes this in its patch.


Many functions include hard-coded datasets or conditions. By wrapping those in filters, third-party code can alter behavior accordingly.

  • wp_stream_image()
  • wp_save_image_file()
  • wp_generate_attachment_metadata() - The extensions-by-type need to be filterable.
  • load_image_to_edit() - The $mime_type switch needs a filterable default.
  • getid3.lib.php ImageTypesLookup() - Types need to be filterable.
  • class-phpmailer.php _mime_types() - Types need to be filterable.
  • image classes supports_mime_type()
  • class-wp-theme get_screenshot() - Filterable types.
  • gd_edit_image_support() - Filterable responses for both conditions.
  • translate_smiley() - Needs filterable types.
  • wp_get_image_mime()
  • wp_attachment_is() - Filterable extensions.
  • wp_mime_type_icon() - Filterable test for image files.


There are additional areas that require more complicated solutions.

  • file_is_displayable_image() - Relies on constants which may not be defined, even in cases where an image type is actually supported. Haha.
  • wp-admin/includes/schema.php - $misc_exts needs to be filterable.
  • class-wp-image-editor-gd load() - Needs a filter around the resource creation. imagecreatefromstring() does not work consistently depending on the GD version installed.
  • class-wp-image-editor-gd _save() - Needs a filter to handle alternative MIME types.
  • class-wp-image-editor-gd stream() - Needs some means of specifying alternative headers and callbacks.
  • class-wp-image-editor-imagick thumbnail_image() - Needs some means of specifying options for different image types.
  • class-wp-image-editor-imagick stream() - Needs a shortcut filter to allow for completely different handling. (This is a quirk of the PHP extension not always properly communicating with the system binary, leading to segfaults, etc.)
  • class-wp-customize-media-control to_json() - Needs some method of altering the $type matching.


Additional requirements, such as defining missing PHP constants, might not be possible by the time plugin or theme code is executed. However by the time official PHP support lands, we can probably consider adding such values to the compat.php file (without necessarily providing a full blessing for the filetype within the Core).

Change History (2)

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

5 years ago

Note: See TracTickets for help on using tickets.