From f7027e504565b2cc502c217496648e53cc97b99c Mon Sep 17 00:00:00 2001 From: Jorge Date: Fri, 25 Nov 2022 19:09:29 +0000 Subject: [PATCH 1/5] Update: Improve performance of gutenberg_render_layout_support_flag. --- lib/block-supports/layout.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 824646c9c36a3c..0c139dcb118a3f 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -370,17 +370,25 @@ 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; + 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'] ) { - if ( ! $global_layout_settings ) { + if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) { return $block_content; } - } $class_names = array(); $layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() ); @@ -393,7 +401,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'] ) { From a16c4dd2d4813572b0f9089085a7861f8f2a5a09 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 5 Dec 2022 14:31:13 +0000 Subject: [PATCH 2/5] Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> --- lib/block-supports/layout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 0c139dcb118a3f..b1e0db3f0faf8d 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -379,7 +379,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $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 ); + $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false ); $static_information_computed = true; } From cd4e43d3ade041c664c875268a04732ab67a99c3 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 5 Dec 2022 14:31:23 +0000 Subject: [PATCH 3/5] Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> --- lib/block-supports/layout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index b1e0db3f0faf8d..cbf1e80d560bda 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -378,7 +378,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $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 ); + $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null ); $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false ); $static_information_computed = true; } From d5f575ff472e8654158d2fe434f8298d66843f26 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 5 Dec 2022 14:31:32 +0000 Subject: [PATCH 4/5] Update lib/block-supports/layout.php Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> --- lib/block-supports/layout.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index cbf1e80d560bda..e89fe2c8dbda22 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -370,25 +370,18 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { return (string) $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' ), null ); - $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false ); - $static_information_computed = true; - } + $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; + $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(); $layout_definitions = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() ); From f40ba0c3c845e5d9bab8da03a3ccaf2ac0531d34 Mon Sep 17 00:00:00 2001 From: Ari Stathopoulos Date: Tue, 6 Dec 2022 08:41:56 +0200 Subject: [PATCH 5/5] Fix indentation --- lib/block-supports/layout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index e89fe2c8dbda22..39869baa4e5167 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -380,7 +380,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { $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; + return $block_content; } $class_names = array();