Skip to content

Commit c1fad61

Browse files
Merge branch 'trunk' into 76369-skip-server-support-check-when-not-generating-subsizes
2 parents 12fcd29 + 68c0f19 commit c1fad61

12 files changed

Lines changed: 628 additions & 152 deletions

File tree

src/wp-includes/block-supports/block-visibility.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,16 @@ function wp_render_block_visibility_support( $block_content, $block ) {
139139
$processor = new WP_HTML_Tag_Processor( $block_content );
140140
if ( $processor->next_tag() ) {
141141
$processor->add_class( implode( ' ', $class_names ) );
142+
143+
/*
144+
* Set all IMG tags to be `fetchpriority=auto` so that wp_get_loading_optimization_attributes() won't add
145+
* `fetchpriority=high` or increment the media count to affect whether subsequent IMG tags get `loading=lazy`.
146+
*/
147+
do {
148+
if ( 'IMG' === $processor->get_tag() ) {
149+
$processor->set_attribute( 'fetchpriority', 'auto' );
150+
}
151+
} while ( $processor->next_tag() );
142152
$block_content = $processor->get_updated_html();
143153
}
144154
}

src/wp-includes/class-wp-block-patterns-registry.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,9 @@ private function get_content( $pattern_name, $outside_init_only = false ) {
174174
$patterns = &$this->registered_patterns;
175175
}
176176

177-
$pattern_path = realpath( $patterns[ $pattern_name ]['filePath'] ?? '' );
177+
$file_path = $patterns[ $pattern_name ]['filePath'] ?? '';
178+
$is_stringy = is_string( $file_path ) || ( is_object( $file_path ) && method_exists( $file_path, '__toString' ) );
179+
$pattern_path = $is_stringy ? realpath( (string) $file_path ) : null;
178180
if (
179181
! isset( $patterns[ $pattern_name ]['content'] ) &&
180182
is_string( $pattern_path ) &&

src/wp-includes/class-wp-scripts.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,19 +417,32 @@ public function do_item( $handle, $group = false ) {
417417
$src = $this->base_url . $src;
418418
}
419419

420-
$query_args = array();
420+
$ver_to_add = '';
421421
if ( empty( $obj->ver ) && null !== $obj->ver && is_string( $this->default_version ) ) {
422-
$query_args['ver'] = $this->default_version;
422+
$ver_to_add = $this->default_version;
423423
} elseif ( is_scalar( $obj->ver ) ) {
424-
$query_args['ver'] = (string) $obj->ver;
424+
$ver_to_add = (string) $obj->ver;
425425
}
426-
if ( isset( $this->args[ $handle ] ) ) {
427-
parse_str( $this->args[ $handle ], $parsed_args );
428-
if ( $parsed_args ) {
429-
$query_args = array_merge( $query_args, $parsed_args );
426+
427+
$added_args = (string) ( $this->args[ $handle ] ?? '' );
428+
429+
if ( '' !== $ver_to_add || '' !== $added_args ) {
430+
$fragment = strstr( $src, '#' );
431+
if ( false !== $fragment ) {
432+
$src = substr( $src, 0, -strlen( $fragment ) );
433+
}
434+
435+
if ( '' !== $ver_to_add ) {
436+
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . 'ver=' . rawurlencode( $ver_to_add );
437+
}
438+
if ( '' !== $added_args ) {
439+
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . $added_args;
440+
}
441+
442+
if ( false !== $fragment ) {
443+
$src .= $fragment;
430444
}
431445
}
432-
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
433446

434447
/** This filter is documented in wp-includes/class-wp-scripts.php */
435448
$src = esc_url_raw( apply_filters( 'script_loader_src', $src, $handle ) );

src/wp-includes/class-wp-styles.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,19 +407,32 @@ public function _css_href( $src, $ver, $handle ) {
407407
$src = $this->base_url . $src;
408408
}
409409

410-
$query_args = array();
410+
$ver_to_add = '';
411411
if ( empty( $ver ) && null !== $ver && is_string( $this->default_version ) ) {
412-
$query_args['ver'] = $this->default_version;
412+
$ver_to_add = $this->default_version;
413413
} elseif ( is_scalar( $ver ) ) {
414-
$query_args['ver'] = (string) $ver;
414+
$ver_to_add = (string) $ver;
415415
}
416-
if ( isset( $this->args[ $handle ] ) ) {
417-
parse_str( $this->args[ $handle ], $parsed_args );
418-
if ( $parsed_args ) {
419-
$query_args = array_merge( $query_args, $parsed_args );
416+
417+
$added_args = (string) ( $this->args[ $handle ] ?? '' );
418+
419+
if ( '' !== $ver_to_add || '' !== $added_args ) {
420+
$fragment = strstr( $src, '#' );
421+
if ( false !== $fragment ) {
422+
$src = substr( $src, 0, -strlen( $fragment ) );
423+
}
424+
425+
if ( '' !== $ver_to_add ) {
426+
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . 'ver=' . rawurlencode( $ver_to_add );
427+
}
428+
if ( '' !== $added_args ) {
429+
$src .= ( str_contains( $src, '?' ) ? '&' : '?' ) . $added_args;
430+
}
431+
432+
if ( false !== $fragment ) {
433+
$src .= $fragment;
420434
}
421435
}
422-
$src = add_query_arg( rawurlencode_deep( $query_args ), $src );
423436

424437
/**
425438
* Filters an enqueued style's fully-qualified URL.

src/wp-includes/html-api/class-wp-html-tag-processor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,8 @@ public function change_parsing_namespace( string $new_namespace ): bool {
881881
* @type string|null $tag_closers "visit" or "skip": whether to stop on tag closers, e.g. </div>.
882882
* }
883883
* @return bool Whether a tag was matched.
884+
*
885+
* @phpstan-impure
884886
*/
885887
public function next_tag( $query = null ): bool {
886888
$this->parse_query( $query );

src/wp-includes/media.php

Lines changed: 66 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5967,6 +5967,7 @@ function wp_get_webp_info( $filename ) {
59675967
* both attributes are present with those values.
59685968
*
59695969
* @since 6.3.0
5970+
* @since 7.0.0 Support `fetchpriority=low` and `fetchpriority=auto` so that `loading=lazy` is not added and the media count is not increased.
59705971
*
59715972
* @global WP_Query $wp_query WordPress Query object.
59725973
*
@@ -6067,7 +6068,9 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
60676068
}
60686069

60696070
// Logic to handle a `fetchpriority` attribute that is already provided.
6070-
if ( isset( $attr['fetchpriority'] ) && 'high' === $attr['fetchpriority'] ) {
6071+
$existing_fetchpriority = ( $attr['fetchpriority'] ?? null );
6072+
$is_low_fetchpriority = ( 'low' === $existing_fetchpriority );
6073+
if ( 'high' === $existing_fetchpriority ) {
60716074
/*
60726075
* If the image was already determined to not be in the viewport (e.g.
60736076
* from an already provided `loading` attribute), trigger a warning.
@@ -6090,6 +6093,31 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
60906093
} else {
60916094
$maybe_in_viewport = true;
60926095
}
6096+
} elseif ( $is_low_fetchpriority ) {
6097+
/*
6098+
* An IMG with fetchpriority=low is not initially displayed; it may be hidden in the Navigation Overlay,
6099+
* or it may be occluded in a non-initial carousel slide. Such images must not be lazy-loaded because the browser
6100+
* has no heuristic to know when to start loading them before the user needs to see them.
6101+
*/
6102+
$maybe_in_viewport = false;
6103+
6104+
// Preserve fetchpriority=low.
6105+
$loading_attrs['fetchpriority'] = 'low';
6106+
} elseif ( 'auto' === $existing_fetchpriority ) {
6107+
/*
6108+
* When a block's visibility support identifies that the block is conditionally displayed based on the viewport
6109+
* size, then it adds `fetchpriority=auto` to the block's IMG tags. These images must not be fetched with high
6110+
* priority because they could be erroneously loaded in viewports which do not even display them. Contrarily,
6111+
* they must not get `fetchpriority=low` because they may in fact be displayed in the current viewport. So as
6112+
* a signal to indicate that an IMG may be in the viewport, `fetchpriority=auto` is added. This has the effect
6113+
* here of preventing the media count from being increased, so that images hidden with block visibility do not
6114+
* affect whether a following IMG gets `loading=lazy`. In particular, `loading=lazy` should still be omitted
6115+
* on an IMG following any number of initial IMGs with `fetchpriority=auto` since those initial images may not
6116+
* be displayed.
6117+
*/
6118+
6119+
// Preserve fetchpriority=auto.
6120+
$loading_attrs['fetchpriority'] = 'auto';
60936121
}
60946122

60956123
if ( null === $maybe_in_viewport ) {
@@ -6140,7 +6168,7 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
61406168
* does not include any loop.
61416169
*/
61426170
&& did_action( 'get_header' ) && ! did_action( 'get_footer' )
6143-
) {
6171+
) {
61446172
$maybe_in_viewport = true;
61456173
$maybe_increase_count = true;
61466174
}
@@ -6149,12 +6177,14 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
61496177
/*
61506178
* If the element is in the viewport (`true`), potentially add
61516179
* `fetchpriority` with a value of "high". Otherwise, i.e. if the element
6152-
* is not not in the viewport (`false`) or it is unknown (`null`), add
6153-
* `loading` with a value of "lazy".
6180+
* is not in the viewport (`false`) or it is unknown (`null`), add
6181+
* `loading` with a value of "lazy" if the element is not already being
6182+
* de-prioritized with `fetchpriority=low` due to occlusion in
6183+
* Navigation Overlay, non-initial carousel slides, or a collapsed Details block.
61546184
*/
61556185
if ( $maybe_in_viewport ) {
61566186
$loading_attrs = wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr );
6157-
} else {
6187+
} elseif ( ! $is_low_fetchpriority ) {
61586188
// Only add `loading="lazy"` if the feature is enabled.
61596189
if ( wp_lazy_loading_enabled( $tag_name, $context ) ) {
61606190
$loading_attrs['loading'] = 'lazy';
@@ -6164,16 +6194,20 @@ function wp_get_loading_optimization_attributes( $tag_name, $attr, $context ) {
61646194
/*
61656195
* If flag was set based on contextual logic above, increase the content
61666196
* media count, either unconditionally, or based on whether the image size
6167-
* is larger than the threshold.
6197+
* is larger than the threshold. This does not apply when the IMG has
6198+
* fetchpriority=auto because it may be conditionally displayed by viewport
6199+
* size.
61686200
*/
6169-
if ( $increase_count ) {
6170-
wp_increase_content_media_count();
6171-
} elseif ( $maybe_increase_count ) {
6172-
/** This filter is documented in wp-includes/media.php */
6173-
$wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 );
6174-
6175-
if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) {
6201+
if ( 'auto' !== $existing_fetchpriority ) {
6202+
if ( $increase_count ) {
61766203
wp_increase_content_media_count();
6204+
} elseif ( $maybe_increase_count ) {
6205+
/** This filter is documented in wp-includes/media.php */
6206+
$wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 );
6207+
6208+
if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) {
6209+
wp_increase_content_media_count();
6210+
}
61776211
}
61786212
}
61796213

@@ -6245,27 +6279,31 @@ function wp_increase_content_media_count( $amount = 1 ) {
62456279
* Determines whether to add `fetchpriority='high'` to loading attributes.
62466280
*
62476281
* @since 6.3.0
6282+
* @since 7.0.0 Support is added for IMG tags with `fetchpriority='low'` and `fetchpriority='auto'`.
62486283
* @access private
62496284
*
6250-
* @param array $loading_attrs Array of the loading optimization attributes for the element.
6251-
* @param string $tag_name The tag name.
6252-
* @param array $attr Array of the attributes for the element.
6253-
* @return array Updated loading optimization attributes for the element.
6285+
* @param array<string, string> $loading_attrs Array of the loading optimization attributes for the element.
6286+
* @param string $tag_name The tag name.
6287+
* @param array<string, mixed> $attr Array of the attributes for the element.
6288+
* @return array<string, string> Updated loading optimization attributes for the element.
62546289
*/
62556290
function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr ) {
62566291
// For now, adding `fetchpriority="high"` is only supported for images.
62576292
if ( 'img' !== $tag_name ) {
62586293
return $loading_attrs;
62596294
}
62606295

6261-
if ( isset( $attr['fetchpriority'] ) ) {
6296+
$existing_fetchpriority = $attr['fetchpriority'] ?? null;
6297+
if ( null !== $existing_fetchpriority && 'auto' !== $existing_fetchpriority ) {
62626298
/*
6263-
* While any `fetchpriority` value could be set in `$loading_attrs`,
6264-
* for consistency we only do it for `fetchpriority="high"` since that
6265-
* is the only possible value that WordPress core would apply on its
6266-
* own.
6299+
* When an IMG has been explicitly marked with `fetchpriority=high`, then honor that this is the element that
6300+
* should have the priority. In contrast, the Navigation block may add `fetchpriority=low` to an IMG which
6301+
* appears in the Navigation Overlay; such images should never be considered candidates for
6302+
* `fetchpriority=high`. Lastly, block visibility may add `fetchpriority=auto` to an IMG when the block is
6303+
* conditionally displayed based on viewport size. Such an image is considered an LCP element candidate if it
6304+
* exceeds the threshold for the minimum number of square pixels.
62676305
*/
6268-
if ( 'high' === $attr['fetchpriority'] ) {
6306+
if ( 'high' === $existing_fetchpriority ) {
62696307
$loading_attrs['fetchpriority'] = 'high';
62706308
wp_high_priority_element_flag( false );
62716309
}
@@ -6292,7 +6330,9 @@ function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr
62926330
$wp_min_priority_img_pixels = apply_filters( 'wp_min_priority_img_pixels', 50000 );
62936331

62946332
if ( $wp_min_priority_img_pixels <= $attr['width'] * $attr['height'] ) {
6295-
$loading_attrs['fetchpriority'] = 'high';
6333+
if ( 'auto' !== $existing_fetchpriority ) {
6334+
$loading_attrs['fetchpriority'] = 'high';
6335+
}
62966336
wp_high_priority_element_flag( false );
62976337
}
62986338

@@ -6306,9 +6346,9 @@ function wp_maybe_add_fetchpriority_high_attr( $loading_attrs, $tag_name, $attr
63066346
* @access private
63076347
*
63086348
* @param bool $value Optional. Used to change the static variable. Default null.
6309-
* @return bool Returns true if high-priority element was marked already, otherwise false.
6349+
* @return bool Returns true if the high-priority element was not already marked.
63106350
*/
6311-
function wp_high_priority_element_flag( $value = null ) {
6351+
function wp_high_priority_element_flag( $value = null ): bool {
63126352
static $high_priority_element = true;
63136353

63146354
if ( is_bool( $value ) ) {

src/wp-includes/template-loader.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,9 @@
111111
*
112112
* @param string $template The path of the template to include.
113113
*/
114-
$template = apply_filters( 'template_include', $template );
115-
$template = is_string( $template ) ? realpath( $template ) : null;
114+
$template = apply_filters( 'template_include', $template );
115+
$is_stringy = is_string( $template ) || ( is_object( $template ) && method_exists( $template, '__toString' ) );
116+
$template = $is_stringy ? realpath( (string) $template ) : null;
116117
if (
117118
is_string( $template ) &&
118119
( str_ends_with( $template, '.php' ) || str_ends_with( $template, '.html' ) ) &&

src/wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '7.0-beta3-61849-src';
19+
$wp_version = '7.0-beta4-61919-src';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)