[wp-trac] [WordPress Trac] #58894: Enhance `wp_get_loading_optimization_attributes()` to support arbitrary context values
WordPress Trac
noreply at wordpress.org
Mon Jul 24 18:47:26 UTC 2023
#58894: Enhance `wp_get_loading_optimization_attributes()` to support arbitrary
context values
-------------------------+--------------------
Reporter: flixos90 | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: 6.4
Component: Media | Version:
Severity: normal | Keywords:
Focuses: performance |
-------------------------+--------------------
The `wp_get_loading_optimization_attributes()` function, which was
introduced in 6.3 (see #58235) but inherited most of its logic from the
now deprecated `wp_get_loading_attr_default()` function introduced in 5.5,
relies on a `$context` parameter based on which it may alter its behavior
and the attributes returned. At the moment, it only supports context
values used within WordPress core.
While this made sense for a first implementation, it is technically not
required and could easily be expanded in several areas to support custom
context values. Having to use WordPress core contexts is limiting today
when relying on the function in plugins or themes, as at the moment any
custom context used would result in incorrect handling of the attributes.
This leads to the awkward situation where we currently have to recommend
always using one of the core context values, even when the function is
actually used in a different context (see e.g. the
[https://make.wordpress.org/core/2023/07/13/image-performance-
enhancements-in-wordpress-6-3/ dev note post] which recommends using the
`wp_get_attachment_image` context even though that function is never
called in the example).
We should abstract certain clauses in the function away from specific
contexts so that the function can also be ''correctly'' used with custom
contexts.
This ticket's implementation should be considered blocked by #58891 as
making the changes before that would be unnecessarily complicated and
error-prone.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/58894>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list