Skip to content

Commit

Permalink
Editor: Move variables to where used in wp_render_layout_support_flag.
Browse files Browse the repository at this point in the history
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: https://core.svn.wordpress.org/trunk@55053 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
spacedmonkey committed Mar 13, 2023
1 parent a20ed3e commit 457dba5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand All @@ -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'] ) &&
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 457dba5

Please sign in to comment.