[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:50:23 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       |  Resolution:
 Keywords:               |     Focuses:  performance
-------------------------+--------------------------
Description changed by flixos90:

Old description:

> 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.

New description:

 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). An actual example for the problem is
 [https://github.com/tomusborne/generatepress/pull/557/files this theme
 pull request] which, despite looking correct, would lead to incorrect
 behavior as of today.

 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#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list