[wp-trac] [WordPress Trac] #37479: Ambiguous use of first parameter in wp_calculate_image_sizes

WordPress Trac noreply at wordpress.org
Wed Jul 27 00:23:58 UTC 2016


#37479: Ambiguous use of first parameter in wp_calculate_image_sizes
-------------------------+-----------------------------
 Reporter:  smerriman    |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Media        |    Version:  trunk
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The `wp_calculate_image_sizes` function in WordPress takes `$size` as a
 parameter, documented as:

   Image size. Accepts any valid image size, or an array of width and
 height values in pixels (in that order). Default 'thumbnail'.

 The code in this function tests if the parameter is a string, and
 calculates the width if so; otherwise simply using the first value of the
 array.

 However, every single call to this function passes an array, not the size
 name. For example, `wp_get_attachment_image` takes the size name, and
 converts it to an array before calling `wp_calculate_image_sizes`. No call
 is ever made with a size name string.

 I would like to request the parameter is enforced to be an array. The
 reason for doing so is in the `wp_calculate_image_sizes` filter. To be
 strictly correct, any uses of this filter need to handle a string, thus
 need to duplicate all of the code for extracting a width. A theme like
 twentysixteen doesn't do this - it assumes the parameter is an array and
 uses `$size[0]` as the width.

 Alternately, the calculated width could be passed as an additional
 parameter to the filter, so that it does not need recalculating.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/37479>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list