From a41ea8177b7ac9c2b1861bbacf5768ec459195b0 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Tue, 6 Dec 2022 10:45:02 +0000 Subject: [PATCH] Update: Improve performance of gutenberg_render_layout_support_flag. (#46074) * Update: Improve performance of gutenberg_render_layout_support_flag. * Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> * Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> * Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> * Fix indentation Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Co-authored-by: Ari Stathopoulos --- lib/block-supports/layout.php | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 824646c9c36a3..39869baa4e516 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -370,16 +370,17 @@ 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; - } + $global_settings = gutenberg_get_global_settings(); + $block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null ); + $has_block_gap_support = isset( $block_gap ); + $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null ); + $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), 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'] && ! $global_layout_settings ) { + return $block_content; } $class_names = array(); @@ -393,7 +394,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'] ) {