From 160a45aa00e1d28ba4e46170c1914e75778c4157 Mon Sep 17 00:00:00 2001 From: Ramon Date: Fri, 1 Nov 2024 16:49:28 +1100 Subject: [PATCH] Style engine: wrap array_merge in conditionals to prevent unnecessary merging (#66661) Wrap array_merge in a conditional to prevent unnecessary firing. Co-authored-by: ramonjd Co-authored-by: aaronrobertshaw --- packages/style-engine/class-wp-style-engine.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/style-engine/class-wp-style-engine.php b/packages/style-engine/class-wp-style-engine.php index 02186fecdcea26..3c692719030053 100644 --- a/packages/style-engine/class-wp-style-engine.php +++ b/packages/style-engine/class-wp-style-engine.php @@ -424,8 +424,15 @@ public static function parse_block_styles( $block_styles, $options ) { continue; } - $parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], static::get_classnames( $style_value, $style_definition ) ); - $parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], static::get_css_declarations( $style_value, $style_definition, $options ) ); + $classnames = static::get_classnames( $style_value, $style_definition ); + if ( ! empty( $classnames ) ) { + $parsed_styles['classnames'] = array_merge( $parsed_styles['classnames'], $classnames ); + } + + $css_declarations = static::get_css_declarations( $style_value, $style_definition, $options ); + if ( ! empty( $css_declarations ) ) { + $parsed_styles['declarations'] = array_merge( $parsed_styles['declarations'], $css_declarations ); + } } }