diff --git a/wp-includes/media.php b/wp-includes/media.php index 335e415798..56624bdc6b 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -5625,6 +5625,25 @@ function wp_get_webp_info( $filename ) { function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { global $wp_query; + /** + * Filters whether to short-circuit loading optimization attributes. + * + * Returning an array from the filter will effectively short-circuit the loading of optimization attributes, + * returning that value instead. + * + * @since 6.4.0 + * + * @param array|false $loading_attrs False by default, or array of loading optimization attributes to short-circuit. + * @param string $tag_name The tag name. + * @param array $attr Array of the attributes for the tag. + * @param string $context Context for the element for which the loading optimization attribute is requested. + */ + $loading_attrs = apply_filters( 'pre_wp_get_loading_optimization_attributes', false, $tag_name, $attr, $context ); + + if ( is_array( $loading_attrs ) ) { + return $loading_attrs; + } + $loading_attrs = array(); /* @@ -5632,17 +5651,20 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { * The skip is also applicable for `fetchpriority`. */ if ( 'template' === $context ) { - return $loading_attrs; + /** This filter is documented in wp-includes/media.php */ + return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); } // For now this function only supports images and iframes. if ( 'img' !== $tag_name && 'iframe' !== $tag_name ) { - return $loading_attrs; + /** This filter is documented in wp-includes/media.php */ + return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); } // For any resources, width and height must be provided, to avoid layout shifts. if ( ! isset( $attr['width'], $attr['height'] ) ) { - return $loading_attrs; + /** This filter is documented in wp-includes/media.php */ + return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); } /* @@ -5654,7 +5676,8 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { */ // TODO: Handle shortcode images together with the content (see https://core.trac.wordpress.org/ticket/58853). if ( 'the_content' !== $context && 'do_shortcode' !== $context && doing_filter( 'the_content' ) ) { - return $loading_attrs; + /** This filter is documented in wp-includes/media.php */ + return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); } /* @@ -5789,7 +5812,17 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) { } } - return $loading_attrs; + /** + * Filters the loading optimization attributes. + * + * @since 6.4.0 + * + * @param array $loading_attrs The loading optimization attributes. + * @param string $tag_name The tag name. + * @param array $attr Array of the attributes for the tag. + * @param string $context Context for the element for which the loading optimization attribute is requested. + */ + return apply_filters( 'wp_get_loading_optimization_attributes', $loading_attrs, $tag_name, $attr, $context ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 0287fdfa95..efd9638c54 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56650'; +$wp_version = '6.4-alpha-56651'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.