#34379 closed defect (bug) (fixed)
Responsive Images: Streamline wp_get_attachment_image_sizes()
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 4.4 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Media | Keywords: | has-patch commit |
Focuses: | performance | Cc: |
Description
While working on performance optimizations for wp_get_attachment_image_sizes()
I came to the conclusion that we could drastically simplify the internals of this function without losing any useful functionality. Originally, the third parameter of this function would allow a developer to pass in an array of source sizes information which would be used to build the sizes
attribute. However, the logic wasn't transparent and in all cases where this functionality would be useful, it would be far easier for a developer to simply build the sizes
value themselves.
Instead, I'm proposing that the third parameter be used to pass in the width of the image, which has performance benefits by not making us recalculate a width that is already known. I'd also like to move the placement of the filter to the returned value and change the filter name to 'wp_get_attachment_image_sizes' to be consistent with other filter names in this family of functions.
I've updated the applicable tests and inline docs.
Aside: @jaspermdegroot was integral in the crafting of this patch and should be included in any props.
Attachments (3)
Change History (18)
This ticket was mentioned in Slack in #feature-respimg by joemcgill. View the logs.
10 years ago
This ticket was mentioned in Slack in #core by joemcgill. View the logs.
10 years ago
#9
@
10 years ago
- Resolution fixed deleted
- Status changed from closed to reopened
I really don't like the idea of changing the wp_get_attachment_image_sizes function signature. If we need to go from accepting an array to accepting an integer, we should either:
1) Create a new function and deprecated wp_get_attachment_image_sizes
2) Ensure that passing an array doesn't change the behavior of wp_get_attachment_image_sizes through automated tests.
Backwards incompatible changes like this make it harder for users to upgrade and break sites and plugins when they do upgrade.
#10
@
10 years ago
@jorbin to be clear, wp_get_attachment_image_sizes()
is a new function introduced in 34855 to create a sizes
attribute for responsive images. As such, I'm not sure I see the harm in changing the signature of this function.
34379.2.patch Cleans up some inline docs and makes sure a
srcset
attribute doesn't get set without a corresponding sizes attribute inwp_get_attachment_image()
.