wp_maybe_add_fetchpriority_high_attr( array $loading_attrs, string $tag_name, array $attr ): array
- Since
- 6.3.0
- Source
wp-includes/media.php:6247
fetchpriority='high' to loading attributes.Compatibility
- WordPress
- since 6.3.0
- PHP
- 7.4–8.6-dev
- 6.7.10
- 6.8.11
- 6.9.10
- 7.0.7
- 7.1.3
Present in every tracked release (6.7.10 to 7.1.3), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$loading_attrsarray- Array of the loading optimization attributes for the element.
$tag_namestring- The tag name.
$attrarray- Array of the attributes for the element.
Return value
array- Updated loading optimization attributes for the element.
Performance profile
How much work a call to wp_maybe_add_fetchpriority_high_attr() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–31
- Plugin surface
- 1 hook
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 43.
Third-party callbacks on 'wp_min_priority_img_pixels' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 4 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_maybe_add_fetchpriority_high_attr() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–13 | none |
$tag_name === "img" | 13–16 | wp_high_priority_element_flag() |
$tag_name === "img" && !isset($attr) && wp_high_priority_element_flag() && !$wp_min_priority_img_pixels | 23–26 | wp_high_priority_element_flag(), apply_filters() |
$tag_name === "img" && !isset($attr) && wp_high_priority_element_flag() && $wp_min_priority_img_pixels | 28–31 | wp_high_priority_element_flag(), apply_filters(), wp_high_priority_element_flag() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 43 instructions, 6–31 executed per call, 7 branches. The work does not change between versions.
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_maybe_add_fetchpriority_high_attr() runs, in this order:
- apply_filters( wp_min_priority_img_pixels )filterline 6284 (+37 into the body)
Filters the minimum square-pixels threshold for an image to be eligible as the high-priority image.
Uses · 2
- wp_high_priority_element_flag()Accesses a flag that indicates if an element is a possible candidate for `fetchpriority='high'`.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 1
- wp_get_loading_optimization_attributes()Gets loading optimization attributes.
Source code
function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr ) { // For now, adding `fetchpriority="high"` is only supported for images. if ( 'img' !== $tag_name ) { return $loading_attrs; } if ( isset( $attr['fetchpriority'] ) ) { /* * While any `fetchpriority` value could be set in `$loading_attrs`, * for consistency we only do it for `fetchpriority="high"` since that * is the only possible value that WordPress core would apply on its * own. */ if ( 'high' === $attr['fetchpriority'] ) { $loading_attrs['fetchpriority'] = 'high'; wp_high_priority_element_flag( false ); } return $loading_attrs; } // Lazy-loading and `fetchpriority="high"` are mutually exclusive. if ( isset( $loading_attrs['loading'] ) && 'lazy' === $loading_attrs['loading'] ) { return $loading_attrs; } if ( ! wp_high_priority_element_flag() ) { return $loading_attrs; } /** * Filters the minimum square-pixels threshold for an image to be eligible as the high-priority image. * * @since 6.3.0 * * @param int $threshold Minimum square-pixels threshold. Default 50000. */ $wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 ); if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) { $loading_attrs['fetchpriority'] = 'high'; wp_high_priority_element_flag( false ); } return $loading_attrs;}Changelog
Introduced in 6.3.0. 3 changes between 6.7.10 and 7.1.3.
Signature, return type and hooks compared across 5 parsed releases.
$loading_attrs retyped from array to untyped.verified against source$attr retyped from array to untyped.verified against sourcearray to array<string,.verified against sourceAbout this page
- Parsed data
- Generated from the wordpress-develop 6.8.11 tag, from
src/wp-includes/media.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.