From 9caf1c4adeddff2577c24d622ebbbf278a671271 Mon Sep 17 00:00:00 2001 From: spacedmonkey Date: Mon, 13 Mar 2023 16:32:20 +0000 Subject: [PATCH] Editor: Move variables to where used in wp_render_layout_support_flag. Improves the performance of wp_render_layout_support_flag() function by moving variables to where each is used. If a return happens before the variable is needed, this change avoids unnecessary processing and memory. Props spacedmonkey, hellofromTonya, mukesh27. Fixes #57815. Built from https://develop.svn.wordpress.org/trunk@55541 git-svn-id: http://core.svn.wordpress.org/trunk@55053 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-supports/layout.php | 20 ++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/wp-includes/block-supports/layout.php b/wp-includes/block-supports/layout.php index bad9430136..22fe6d7b7a 100644 --- a/wp-includes/block-supports/layout.php +++ b/wp-includes/block-supports/layout.php @@ -319,8 +319,8 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false * @return string Filtered block content. */ function wp_render_layout_support_flag( $block_content, $block ) { - $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); - $support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false ); + $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); + $support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false ); $has_child_layout = isset( $block['attrs']['style']['layout']['selfStretch'] ); if ( ! $support_layout && ! $has_child_layout ) { @@ -369,14 +369,9 @@ function wp_render_layout_support_flag( $block_content, $block ) { return (string) $content; } - $global_settings = wp_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; + $global_settings = wp_get_global_settings(); + $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null ); + $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() ); if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) { return $block_content; @@ -392,6 +387,8 @@ function wp_render_layout_support_flag( $block_content, $block ) { $used_layout['type'] = 'constrained'; } + $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false ); + if ( $root_padding_aware_alignments && isset( $used_layout['type'] ) && @@ -458,6 +455,9 @@ function wp_render_layout_support_flag( $block_content, $block ) { */ $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' ); + $block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null ); + $has_block_gap_support = isset( $block_gap ); + $style = wp_get_layout_style( ".$container_class.$container_class", $used_layout, diff --git a/wp-includes/version.php b/wp-includes/version.php index ecd6379884..f58263a908 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.3-alpha-55540'; +$wp_version = '6.3-alpha-55541'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.