diff --git a/plugins/webp-uploads/picture-element.php b/plugins/webp-uploads/picture-element.php index 349edb3b46..008ecd9d11 100644 --- a/plugins/webp-uploads/picture-element.php +++ b/plugins/webp-uploads/picture-element.php @@ -148,6 +148,16 @@ function webp_uploads_wrap_image_in_picture( string $image, string $context, int esc_attr( $image_srcset ), is_string( $sizes ) ? sprintf( ' sizes="%s"', esc_attr( $sizes ) ) : '' ); + } else { + // Fallback when wp_calculate_image_srcset returns false - generate simple source without srcset. + $image_url = webp_uploads_get_mime_type_image( $attachment_id, $src, $image_mime_type ); + if ( is_string( $image_url ) ) { + $picture_sources .= sprintf( + '', + esc_attr( $image_mime_type ), + esc_attr( $image_url ) + ); + } } } } else { diff --git a/plugins/webp-uploads/tests/test-picture-element.php b/plugins/webp-uploads/tests/test-picture-element.php index 87ca0282c1..766fd0c981 100644 --- a/plugins/webp-uploads/tests/test-picture-element.php +++ b/plugins/webp-uploads/tests/test-picture-element.php @@ -436,10 +436,15 @@ public function test_disable_responsive_image_with_picture_element( Closure $set $this->assertStringEndsWith( '.jpg', $picture_processor->get_attribute( 'src' ), 'Make sure the fallback IMG should return JPEG src.' ); $picture_processor = new WP_HTML_Tag_Processor( $picture_markup ); + $source_count = 0; while ( $picture_processor->next_tag( array( 'tag_name' => 'source' ) ) ) { + ++$source_count; $this->assertSame( self::$mime_type, $picture_processor->get_attribute( 'type' ), 'Make sure the Picture source should not return JPEG as source.' ); $this->assertStringContainsString( '.webp', $picture_processor->get_attribute( 'srcset' ), 'Make sure the Picture source srcset should return WEBP images.' ); } + + // Ensure at least one source element was created (addresses GitHub issue with wp_calculate_image_srcset disabled). + $this->assertGreaterThan( 0, $source_count, 'At least one source element should be created even when responsive images are disabled.' ); } /**