@@ -82,9 +82,9 @@ 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
- $ id = $ block ->attributes ['id ' ] ?? 0 ;
85
+ $ id = isset ( $ block ->attributes ['id ' ] ) ? ( int ) $ block -> attributes [ ' id ' ] : 0 ;
86
86
$ alignment = $ block ->attributes ['align ' ] ?? '' ;
87
- $ width = $ block ->attributes ['width ' ] ?? '' ;
87
+ $ width = isset ( $ block ->attributes ['width ' ] ) ? ( int ) $ block -> attributes [ ' width ' ] : 0 ;
88
88
$ max_alignment = $ block ->context ['max_alignment ' ] ?? '' ;
89
89
90
90
/*
@@ -95,7 +95,7 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
95
95
$ size = array ( 420 , 420 );
96
96
}
97
97
98
- $ better_sizes = auto_sizes_calculate_better_sizes ( ( int ) $ id , $ size , ( string ) $ alignment , ( string ) $ width , ( string ) $ max_alignment );
98
+ $ better_sizes = auto_sizes_calculate_better_sizes ( $ id , $ size , $ alignment , $ width , $ max_alignment );
99
99
100
100
// If better sizes can't be calculated, use the default sizes.
101
101
return false !== $ better_sizes ? $ better_sizes : $ sizes ;
@@ -135,33 +135,32 @@ function auto_sizes_filter_image_tag( $content, array $parsed_block, WP_Block $b
135
135
* @param int $id The image attachment post ID.
136
136
* @param string|array{int, int} $size Image size name or array of width and height.
137
137
* @param string $align The image alignment.
138
- * @param string $resize_width Resize image width.
138
+ * @param int $resize_width Resize image width.
139
139
* @param string $max_alignment The maximum usable layout alignment.
140
140
* @return string|false An improved sizes attribute or false if a better size cannot be calculated.
141
141
*/
142
- function auto_sizes_calculate_better_sizes ( int $ id , $ size , string $ align , string $ resize_width , string $ max_alignment ) {
142
+ function auto_sizes_calculate_better_sizes ( int $ id , $ size , string $ align , int $ resize_width , string $ max_alignment ) {
143
143
// Without an image ID or a resize width, we cannot calculate a better size.
144
- if ( ! ( bool ) $ id && ! ( bool ) $ resize_width ) {
144
+ if ( 0 === $ id && 0 === $ resize_width ) {
145
145
return false ;
146
146
}
147
147
148
148
$ image_data = wp_get_attachment_image_src ( $ id , $ size );
149
149
150
- $ resize_width = (int ) $ resize_width ;
151
- $ image_width = false !== $ image_data ? $ image_data [1 ] : 0 ;
150
+ $ image_width = false !== $ image_data ? $ image_data [1 ] : 0 ;
152
151
153
152
// If we don't have an image width or a resize width, we cannot calculate a better size.
154
- if ( ! ( ( bool ) $ image_width || ( bool ) $ resize_width ) ) {
153
+ if ( 0 === $ image_width && 0 === $ resize_width ) {
155
154
return false ;
156
155
}
157
156
158
157
/*
159
158
* If we don't have an image width, use the resize width.
160
159
* If we have both an image width and a resize width, use the smaller of the two.
161
160
*/
162
- if ( ! ( bool ) $ image_width ) {
161
+ if ( 0 === $ image_width ) {
163
162
$ image_width = $ resize_width ;
164
- } elseif ( ( bool ) $ resize_width ) {
163
+ } elseif ( 0 !== $ resize_width ) {
165
164
$ image_width = min ( $ image_width , $ resize_width );
166
165
}
167
166
0 commit comments