Skip to content

Fatal error in Enhanced Responsive Images when using old Columns block with a percentage float width #2724

Description

@westonruter

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 369

Call stack:

  1. rtrim()
    wp-content/plugins/auto-sizes/includes/improve-calculate-sizes.php:369
  2. auto_sizes_filter_render_block_context()
    wp-includes/class-wp-hook.php:353
  3. WP_Hook::apply_filters()
    wp-includes/plugin.php:206
  4. apply_filters()
    wp-includes/class-wp-block.php:617
  5. WP_Block::render()
    wp-includes/blocks.php:2514
  6. render_block()
    wp-includes/blocks.php:2597
  7. do_blocks()
    wp-includes/class-wp-hook.php:353
  8. WP_Hook::apply_filters()
    wp-includes/plugin.php:206
  9. apply_filters()
    wp-includes/blocks/post-content.php:50
  10. render_block_core_post_content()
    wp-includes/class-wp-block.php:665
  11. WP_Block::render()
    wp-includes/class-wp-block.php:629
  12. WP_Block::render()
    wp-includes/class-wp-block.php:629
  13. WP_Block::render()
    wp-includes/blocks.php:2514
  14. render_block()
    wp-includes/blocks.php:2597
  15. do_blocks()
    wp-includes/block-template.php:291
  16. get_the_block_template_html()
    wp-includes/template-canvas.php:12
  17. include('/code/wp-includes/template-canvas.php')
    wp-includes/template-loader.php:132
  18. require_once('/code/wp-includes/template-loader.php')
    wp-blog-header.php:19
  19. require('/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions