From 22ab467e6f8bfb6c56f8b3c8cea5585fcb91777d Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 25 Nov 2022 19:09:29 +0000 Subject: [PATCH] Update: Improve performance of gutenberg_render_layout_support_flag. --- lib/block-supports/layout.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 8bda090263037..a6f997d1d40fe 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -371,16 +371,24 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { return (string) $content; } - $block_gap = gutenberg_get_global_settings( array( 'spacing', 'blockGap' ) ); - $global_layout_settings = gutenberg_get_global_settings( array( 'layout' ) ); - $has_block_gap_support = isset( $block_gap ) ? null !== $block_gap : false; - $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); - $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; - - if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] ) { - if ( ! $global_layout_settings ) { - return $block_content; - } + static $static_information_computed = false; + static $has_block_gap_support = false; + static $global_layout_settings = null; + static $root_padding_aware_alignments = false; + if ( ! $static_information_computed ) { + $global_settings = gutenberg_get_global_settings(); + $block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), $global_settings ); + $has_block_gap_support = isset( $block_gap ); + $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), $global_settings ); + $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), $global_settings ); + $static_information_computed = true; + } + + $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); + $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout; + + if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) { + return $block_content; } $class_names = array(); @@ -394,7 +402,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { } if ( - gutenberg_get_global_settings( array( 'useRootPaddingAwareAlignments' ) ) && + $root_padding_aware_alignments && isset( $used_layout['type'] ) && 'constrained' === $used_layout['type'] ) {