[wp-trac] [WordPress Trac] #58212: Improve clunky logic to inject `loading` attribute in the `get_the_post_thumbnail()` function

WordPress Trac noreply at wordpress.org
Wed May 17 18:29:56 UTC 2023


#58212: Improve clunky logic to inject `loading` attribute in the
`get_the_post_thumbnail()` function
--------------------------------------+--------------------------
 Reporter:  flixos90                  |       Owner:  flixos90
     Type:  enhancement               |      Status:  closed
 Priority:  high                      |   Milestone:  6.3
Component:  Post Thumbnails           |     Version:
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch has-unit-tests  |     Focuses:  performance
--------------------------------------+--------------------------
Changes (by flixos90):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"55821" 55821]:
 {{{
 #!CommitTicketReference repository="" revision="55821"
 Media: Introduce `wp_get_attachment_image_context` filter.

 Since WordPress 5.9, a "context" value of "wp_get_attachment_image" has
 been used in the `wp_get_attachment_image()` function to provide context
 to underlying functions where that is relevant, e.g.
 `wp_get_loading_attr_default()`. Since that value used to be not
 customizable, it required a workaround in `get_the_post_thumbnail()` to
 avoid calling those functions in `wp_get_attachment_image()`, which
 resulted in unnecessary complexity and was prone to errors.

 This changeset introduces a `wp_get_attachment_image_context` filter and
 leverages it with private filter callback functions that are leveraged by
 default when `get_the_post_thumbnail()` is called. This avoids the need
 for the previous workaround and furthermore provides flexibility for other
 callers of `wp_get_attachment_image()` to provide their own contexts.

 Props flixos90, costdev, thekt12, westonruter, spacedmonkey.
 Fixes #58212.
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/58212#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list