Repository navigation
Fatal error in Enhanced Responsive Images when using old Columns block with a percentage float width #2724
Description
Bug Description
I'm noticing the following error on my site:
Uncaught Error: rtrim(): Argument 1 ($string) must be of type string, float given
in /code/wp-content/plugins/auto-sizes/includes/improve-calculate-sizes.php on line 369Call stack:
rtrim()
wp-content/plugins/auto-sizes/includes/improve-calculate-sizes.php:369auto_sizes_filter_render_block_context()
wp-includes/class-wp-hook.php:353WP_Hook::apply_filters()
wp-includes/plugin.php:206apply_filters()
wp-includes/class-wp-block.php:617WP_Block::render()
wp-includes/blocks.php:2514render_block()
wp-includes/blocks.php:2597do_blocks()
wp-includes/class-wp-hook.php:353WP_Hook::apply_filters()
wp-includes/plugin.php:206apply_filters()
wp-includes/blocks/post-content.php:50render_block_core_post_content()
wp-includes/class-wp-block.php:665WP_Block::render()
wp-includes/class-wp-block.php:629WP_Block::render()
wp-includes/class-wp-block.php:629WP_Block::render()
wp-includes/blocks.php:2514render_block()
wp-includes/blocks.php:2597do_blocks()
wp-includes/block-template.php:291get_the_block_template_html()
wp-includes/template-canvas.php:12include('/code/wp-includes/template-canvas.php')
wp-includes/template-loader.php:132require_once('/code/wp-includes/template-loader.php')
wp-blog-header.php:19require('/code/wp-blog-header.php')
index.php:17
In looking at the $block['attrs'] being passed, the array has:
array( 'width' => 33.33 )It seems this is due to using strict types (#2424).
The problematic line is here:
| $current_width = floatval( rtrim( $block['attrs']['width'], '%' ) ) / 100; |
The quick fix is to add a string cast:
- $current_width = floatval( rtrim( $block['attrs']['width'], '%' ) ) / 100;
+ $current_width = floatval( rtrim( (string) $block['attrs']['width'], '%' ) ) / 100;But it's not clear whether this is just fixing the symptom.
It appears this is due to old Columns block code which was last touched in 2020:
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":33.33} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"id":9760,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-error-but-admin-bar-ok.png" alt="AMP Validator Extension shows AMP validation error but AMP plugin in Admin Bar shows valid" class="wp-image-9760"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"width":66.66} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:image {"id":9759,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-dev-mode-700x210.png" alt="AMP Validator Extension showing Dev Mode error" class="wp-image-9759"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->When I put that code into the block editor and toggle visual mode, it comes out modified, with the width attributes being converted from floats to strings:
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"width":"33.33%"} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-error-but-admin-bar-ok.png" alt="AMP Validator Extension shows AMP validation error but AMP plugin in Admin Bar shows valid"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
<!-- wp:column {"width":"66.66%"} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:image {"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-dev-mode-700x210.png" alt="AMP Validator Extension showing Dev Mode error"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->--- before.html 2026-10-15 22:08:47
+++ after.html 2026-10-15 22:10:10
@@ -1,11 +1,11 @@
<!-- wp:columns -->
-<div class="wp-block-columns"><!-- wp:column {"width":33.33} -->
+<div class="wp-block-columns"><!-- wp:column {"width":"33.33%"} -->
<div class="wp-block-column" style="flex-basis:33.33%"><!-- wp:image {"id":9760,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-error-but-admin-bar-ok.png" alt="AMP Validator Extension shows AMP validation error but AMP plugin in Admin Bar shows valid" class="wp-image-9760"/></figure>
<!-- /wp:image --></div>
<!-- /wp:column -->
-<!-- wp:column {"width":66.66} -->
+<!-- wp:column {"width":"66.66%"} -->
<div class="wp-block-column" style="flex-basis:66.66%"><!-- wp:image {"id":9759,"sizeSlug":"large"} -->
<figure class="wp-block-image size-large"><img src="https://weston.ruter.net/wp-content/uploads/2019/09/amp-validator-extension-dev-mode-700x210.png" alt="AMP Validator Extension showing Dev Mode error" class="wp-image-9759"/></figure>
<!-- /wp:image --></div>So apparently there is a block deprecation going on which Enhanced Responsive Images is not aware of.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNot Started/Backlog 📆
Activity