Skip to content

Commit 37b893b

Browse files
committed
Merge branch 'trunk' into fix/palette-pngs-to-avif-webp-conversion
2 parents e39b2c7 + e147007 commit 37b893b

File tree

7 files changed

+222
-38
lines changed

7 files changed

+222
-38
lines changed

.github/workflows/php-test-plugins.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ jobs:
4747
wp: '6.6'
4848
- php: '8.3'
4949
wp: 'trunk'
50+
- php: '8.4'
51+
wp: 'trunk'
5052
- php: '8.2'
5153
phpunit: '9.6'
5254
wp: 'latest'

package-lock.json

Lines changed: 21 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
},
1313
"devDependencies": {
1414
"@octokit/rest": "^22.0.0",
15-
"@playwright/test": "^1.53.2",
15+
"@playwright/test": "^1.54.1",
1616
"@types/node": "^24.0.10",
1717
"@wordpress/e2e-test-utils-playwright": "^1.26.0",
18-
"@wordpress/env": "^10.26.0",
18+
"@wordpress/env": "^10.27.0",
1919
"@wordpress/prettier-config": "^4.25.0",
2020
"@wordpress/scripts": "^30.19.0",
2121
"commander": "14.0.0",

plugins/auto-sizes/hooks.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ function auto_sizes_render_generator(): void {
4040
add_filter( 'the_content', 'auto_sizes_prime_attachment_caches', 9 ); // This must run before 'do_blocks', which runs at priority 9.
4141
add_filter( 'render_block_core/image', 'auto_sizes_filter_image_tag', 10, 3 );
4242
add_filter( 'render_block_core/cover', 'auto_sizes_filter_image_tag', 10, 3 );
43+
add_filter( 'render_block_core/post-featured-image', 'auto_sizes_filter_image_tag', 10, 3 );
4344
add_filter( 'get_block_type_uses_context', 'auto_sizes_filter_uses_context', 10, 2 );
4445
add_filter( 'render_block_context', 'auto_sizes_filter_render_block_context', 10, 3 );

plugins/auto-sizes/includes/improve-calculate-sizes.php

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,20 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
9494
* @param string $size The image size data.
9595
*/
9696
$filter = static function ( $sizes, $size ) use ( $block ) {
97-
9897
$id = isset( $block->attributes['id'] ) ? (int) $block->attributes['id'] : 0;
9998
$alignment = $block->attributes['align'] ?? '';
10099
$width = isset( $block->attributes['width'] ) ? (int) $block->attributes['width'] : 0;
101100
$max_alignment = $block->context['max_alignment'] ?? '';
102101
$container_relative_width = $block->context['container_relative_width'] ?? 1.0;
103102

103+
/*
104+
* For the post featured image block, use the post ID to get the featured image attachment ID.
105+
* See https://github.com/WordPress/wordpress-develop/blob/3f9c6fce666ed2ea0d56c21f6235c37db3d91392/src/wp-includes/blocks/post-featured-image.php#L65
106+
*/
107+
if ( 'core/post-featured-image' === $block->name && isset( $block->context['postId'] ) ) {
108+
$id = auto_sizes_get_featured_image_attachment_id( $block->context['postId'] );
109+
}
110+
104111
/*
105112
* Update width for cover block.
106113
* See https://github.com/WordPress/gutenberg/blob/938720602082dc50a1746bd2e33faa3d3a6096d4/packages/block-library/src/cover/style.scss#L82-L87.
@@ -118,12 +125,23 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
118125
// Hook this filter early, before default filters are run.
119126
add_filter( 'wp_calculate_image_sizes', $filter, 9, 2 );
120127

128+
// Get the image ID from the block attributes or context.
129+
$id = $parsed_block['attrs']['id'] ?? 0;
130+
131+
/*
132+
* For the post featured image block, use the post ID to get the featured image attachment ID.
133+
* See https://github.com/WordPress/wordpress-develop/blob/3f9c6fce666ed2ea0d56c21f6235c37db3d91392/src/wp-includes/blocks/post-featured-image.php#L65
134+
*/
135+
if ( 'core/post-featured-image' === $block->name && isset( $block->context['postId'] ) ) {
136+
$id = auto_sizes_get_featured_image_attachment_id( $block->context['postId'] );
137+
}
138+
121139
$sizes = wp_calculate_image_sizes(
122140
// If we don't have a size slug, assume the full size was used.
123141
$parsed_block['attrs']['sizeSlug'] ?? 'full',
124142
null,
125143
null,
126-
$parsed_block['attrs']['id'] ?? 0
144+
$id
127145
);
128146

129147
remove_filter( 'wp_calculate_image_sizes', $filter, 9 );
@@ -284,11 +302,12 @@ function auto_sizes_get_layout_width( string $alignment ): string {
284302
function auto_sizes_filter_uses_context( array $uses_context, WP_Block_Type $block_type ): array {
285303
// Define block-specific context usage.
286304
$block_specific_context = array(
287-
'core/cover' => array( 'max_alignment', 'container_relative_width' ),
288-
'core/image' => array( 'max_alignment', 'container_relative_width' ),
289-
'core/group' => array( 'max_alignment' ),
290-
'core/columns' => array( 'max_alignment', 'container_relative_width' ),
291-
'core/column' => array( 'max_alignment', 'column_count' ),
305+
'core/cover' => array( 'max_alignment', 'container_relative_width' ),
306+
'core/image' => array( 'max_alignment', 'container_relative_width' ),
307+
'core/post-featured-image' => array( 'max_alignment', 'container_relative_width' ),
308+
'core/group' => array( 'max_alignment' ),
309+
'core/columns' => array( 'max_alignment', 'container_relative_width' ),
310+
'core/column' => array( 'max_alignment', 'column_count' ),
292311
);
293312

294313
if ( isset( $block_specific_context[ $block_type->name ] ) ) {
@@ -316,6 +335,7 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ?
316335
$provider_blocks = array(
317336
'core/columns',
318337
'core/group',
338+
'core/post-featured-image',
319339
);
320340

321341
if ( in_array( $block['blockName'], $provider_blocks, true ) ) {
@@ -360,3 +380,19 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ?
360380
}
361381
return $context;
362382
}
383+
384+
/**
385+
* Retrieves the featured image attachment ID for a given post ID.
386+
*
387+
* @since n.e.x.t
388+
*
389+
* @param int $post_id The post ID.
390+
* @return int The featured image attachment ID or 0 if not found.
391+
*/
392+
function auto_sizes_get_featured_image_attachment_id( int $post_id ): int {
393+
if ( 0 === $post_id ) {
394+
return 0;
395+
}
396+
397+
return (int) get_post_thumbnail_id( $post_id );
398+
}

0 commit comments

Comments
 (0)