[wp-trac] [WordPress Trac] #63923: style-engine: Add string check to prevent fatal errors from malformed block attributes
WordPress Trac
noreply at wordpress.org
Wed Sep 3 19:24:06 UTC 2025
#63923: style-engine: Add string check to prevent fatal errors from malformed block
attributes
--------------------------+-----------------------------
Reporter: mreishus | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Editor | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
=== Problem ===
This fixes an fatal error I saw from a client site with a malformed site-
logo block:
{{{
<!-- wp:site-logo
{"width":61,"style":{"spacing":{"padding":{"top":"var:preset|spacing|40","position":{"type":"fixed","top":"0px"},"z-index":"500px","bottom":"var:preset|spacing|40","left":"var:preset|spacing|50","right":"var:preset|spacing|50"}}}}
/-->
}}}
The fatal error when malformed block attributes are passed:
{{{
Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of
type string, array given
}}}
Here's a stack trace (when running GB):
{{{
Fatal error: Uncaught TypeError: trim(): Argument #1 ($string) must be of
type string, array given in /home/wpcom/public_html/wp-content/plugins
/gutenberg-core/v20.6.0/build/style-engine/class-wp-style-engine-css-
declarations-gutenberg.php:54
Stack trace:
#0 wp-content/plugins/gutenberg-core/v20.6.0/build/style-engine/class-wp-
style-engine-css-declarations-gutenberg.php(54): trim(Array)
#1 wp-content/plugins/gutenberg-core/v20.6.0/build/style-engine/class-wp-
style-engine-css-declarations-gutenberg.php(86):
WP_Style_Engine_CSS_Declarations_Gutenberg->add_declaration('padding-
positio...', Array)
#2 wp-content/plugins/gutenberg-core/v20.6.0/build/style-engine/class-wp-
style-engine-css-declarations-gutenberg.php(34):
WP_Style_Engine_CSS_Declarations_Gutenberg->add_declarations(Array)
#3 wp-content/plugins/gutenberg-core/v20.6.0/build/style-engine/class-wp-
style-engine-gutenberg.php(655):
WP_Style_Engine_CSS_Declarations_Gutenberg->__construct(Array)
#4 wp-content/plugins/gutenberg-core/v20.6.0/build/style-engine/style-
engine-gutenberg.php(57): WP_Style_Engine_Gutenberg::compile_css(Array,
NULL)
#5 wp-content/plugins/gutenberg-core/v20.6.0/lib/block-
supports/spacing.php(67): gutenberg_style_engine_get_styles(Array)
#6 wp-includes/class-wp-block-supports.php(119):
gutenberg_apply_spacing_support(Object(WP_Block_Type), Array)
#7 wp-includes/class-wp-block-supports.php(176):
WP_Block_Supports->apply_block_supports()
#8 wp-content/plugins/gutenberg-core/v20.6.0/build/block-library/blocks
/site-logo.php(60): get_block_wrapper_attributes(Array)
#9 wp-includes/class-wp-block.php(587):
gutenberg_render_block_core_site_logo(Array, '', Object(WP_Block))
#10 wp-includes/class-wp-block.php(566): WP_Block->render()
#11 wp-includes/class-wp-block.php(566): WP_Block->render()
}}}
=== Solution ===
Add type checking before trim():
{{{#!php
// Bails early if the value is not a string.
if ( ! is_string( $value ) ) {
return $this;
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/63923>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list