Make WordPress Core


Ignore:
Timestamp:
03/13/2023 04:30:09 PM (17 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/layout.php

    r55439 r55541  
    320320 */
    321321function wp_render_layout_support_flag( $block_content, $block ) {
    322     $block_type     = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
    323     $support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
     322    $block_type       = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
     323    $support_layout   = block_has_support( $block_type, array( '__experimentalLayout' ), false );
    324324    $has_child_layout = isset( $block['attrs']['style']['layout']['selfStretch'] );
    325325
     
    370370    }
    371371
    372     $global_settings               = wp_get_global_settings();
    373     $block_gap                     = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
    374     $has_block_gap_support         = isset( $block_gap );
    375     $global_layout_settings        = _wp_array_get( $global_settings, array( 'layout' ), null );
    376     $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );
    377 
    378     $default_block_layout = _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
    379     $used_layout          = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $default_block_layout;
     372    $global_settings        = wp_get_global_settings();
     373    $global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
     374    $used_layout            = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
    380375
    381376    if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) {
     
    392387        $used_layout['type'] = 'constrained';
    393388    }
     389
     390    $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );
    394391
    395392    if (
     
    458455         */
    459456        $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
     457
     458        $block_gap             = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
     459        $has_block_gap_support = isset( $block_gap );
    460460
    461461        $style = wp_get_layout_style(
Note: See TracChangeset for help on using the changeset viewer.