Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#51362 closed defect (bug) (fixed)

Allow gallery_shortcode() and get_image_tag() to accept an array of image dimensions

Reported by: johnbillion's profile johnbillion Owned by: johnbillion's profile johnbillion
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Media Keywords: has-patch
Focuses: Cc:


Of all the image-related functions in WordPress that include a $size parameter, almost all of them accept either a registered image size or an array of the image width and height in pixels.

There are three exceptions to this, which do not accept an array:

  • gallery_shortcode() ($attr['size'] parameter) because the value gets passed to sanitize_html_class()
  • get_image_tag() because the value gets directly used as an HTML attribute
  • get_image_send_to_editor() because the value gets passed to get_image_tag()

The gallery_shortcode() and image_tag() functions should be fixed so that they use {$width}x{$height} where the image size is used as an HTML attribute. This is what wp_get_attachment_image() already does when its $size parameter is an array.

The documentation for these functions and their filters are currently incorrect because they state that they do accept either an image name or array of dimensions, therefore this is a backwards-compatible fix.

Related / split from #47364.

Attachments (1)

51362.diff (976 bytes) - added by johnbillion 4 years ago.

Download all attachments as: .zip

Change History (3)

4 years ago

#1 @johnbillion
4 years ago

  • Keywords has-patch added; needs-patch removed

51362.diff fixes these two instances.

#2 @johnbillion
4 years ago

  • Owner set to johnbillion
  • Resolution set to fixed
  • Status changed from new to closed

In 49128:

Media: Allow the gallery_shortcode() and get_image_tag() functions to correctly accept an array of image dimensions.

These functions did previously accept an array of image dimensions but their class attributes were not properly constructed.

Fixes #51362

Note: See TracTickets for help on using tickets.