@@ -82,13 +82,20 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
82
82
*/
83
83
$ filter = static function ( $ sizes , $ size ) use ( $ block ) {
84
84
85
- $ block_name = $ block ->name ;
86
85
$ id = $ block ->attributes ['id ' ] ?? 0 ;
87
86
$ alignment = $ block ->attributes ['align ' ] ?? '' ;
88
87
$ width = $ block ->attributes ['width ' ] ?? '' ;
89
88
$ max_alignment = $ block ->context ['max_alignment ' ];
90
89
91
- $ better_sizes = auto_sizes_calculate_better_sizes ( (string ) $ block_name , (int ) $ id , (string ) $ size , (string ) $ alignment , (string ) $ width , (string ) $ max_alignment );
90
+ /*
91
+ * Update width for cover block.
92
+ * See https://github.com/WordPress/gutenberg/blob/938720602082dc50a1746bd2e33faa3d3a6096d4/packages/block-library/src/cover/style.scss#L82-L87.
93
+ */
94
+ if ( 'core/cover ' === $ block ->name && in_array ( $ alignment , array ( 'left ' , 'right ' ), true ) ) {
95
+ $ size = array ( 420 , 420 );
96
+ }
97
+
98
+ $ better_sizes = auto_sizes_calculate_better_sizes ( (int ) $ id , $ size , (string ) $ alignment , (string ) $ width , (string ) $ max_alignment );
92
99
93
100
// If better sizes can't be calculated, use the default sizes.
94
101
return false !== $ better_sizes ? $ better_sizes : $ sizes ;
@@ -125,15 +132,14 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
125
132
*
126
133
* @since n.e.x.t
127
134
*
128
- * @param string $block_name The block name.
129
- * @param int $id The image id.
130
- * @param string $size The image size data.
131
- * @param string $align The image alignment.
132
- * @param string $resize_width Resize image width.
133
- * @param string $max_alignment The maximum usable layout alignment.
135
+ * @param int $id The image id.
136
+ * @param string|int[] $size The image size data.
137
+ * @param string $align The image alignment.
138
+ * @param string $resize_width Resize image width.
139
+ * @param string $max_alignment The maximum usable layout alignment.
134
140
* @return string|false An improved sizes attribute or false if a better size cannot be calculated.
135
141
*/
136
- function auto_sizes_calculate_better_sizes ( string $ block_name , int $ id , string $ size , string $ align , string $ resize_width , string $ max_alignment ) {
142
+ function auto_sizes_calculate_better_sizes ( int $ id , $ size , string $ align , string $ resize_width , string $ max_alignment ) {
137
143
// Without an image ID or a resize width, we cannot calculate a better size.
138
144
if ( ! (bool ) $ id && ! (bool ) $ resize_width ) {
139
145
return false ;
@@ -189,13 +195,6 @@ function auto_sizes_calculate_better_sizes( string $block_name, int $id, string
189
195
190
196
case 'left ' :
191
197
case 'right ' :
192
- /*
193
- * Update width for cover block.
194
- * See https://github.com/WordPress/gutenberg/blob/938720602082dc50a1746bd2e33faa3d3a6096d4/packages/block-library/src/cover/style.scss#L82-L87.
195
- */
196
- if ( 'core/cover ' === $ block_name ) {
197
- $ image_width = $ image_width * 0.5 ;
198
- }
199
198
$ layout_width = sprintf ( '%1$spx ' , $ image_width );
200
199
break ;
201
200
0 commit comments