Make WordPress Core

Changeset 56709


Ignore:
Timestamp:
09/26/2023 01:45:23 PM (18 months ago)
Author:
SergeyBiryukov
Message:

Editor: Reduce the use of the _wp_array_get() function to improve performance.

_wp_array_get() is an expensive function, and it's called thousands of times on each page view on the front end. While the function performance was slightly improved in #58376, it is still called more times than it should be.

This commit aims to further optimize its usage:

  • In many cases, _wp_array_get() can be replaced with a much simpler and faster isset() check.
  • The isset() function is capable of checking nested arrays, so isset( $foo['a']['b']['c'] ) will return false even if $foo['a'] is unset, without throwing any errors or warnings.
  • When _wp_array_get() cannot be directly replaced with isset(), it would be good practice to wrap it in an isset() function so that _wp_array_get() only runs when it needs to.

Original PR from Gutenberg repository:

Follow-up to [55851], [56382].

Props aristath, jrf, spacedmonkey, mukesh27, swissspidy, hellofromTonya.
Fixes #59405.

Location:
trunk/src/wp-includes
Files:
15 edited

Legend:

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

    r56614 r56709  
    5959    }
    6060
    61     $background_image_source = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'source' ), null );
    62     $background_image_url    = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'url' ), null );
    63     $background_size         = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundSize' ), 'cover' );
     61    $background_image_source = isset( $block_attributes['style']['background']['backgroundImage']['source'] )
     62        ? $block_attributes['style']['background']['backgroundImage']['source']
     63        : null;
     64    $background_image_url    = isset( $block_attributes['style']['background']['backgroundImage']['url'] )
     65        ? $block_attributes['style']['background']['backgroundImage']['url']
     66        : null;
     67    $background_size         = isset( $block_attributes['style']['background']['backgroundSize'] )
     68        ? $block_attributes['style']['background']['backgroundSize']
     69        : 'cover';
    6470
    6571    $background_block_styles = array();
  • trunk/src/wp-includes/block-supports/border.php

    r56382 r56709  
    103103    ) {
    104104        $preset_border_color          = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
    105         $custom_border_color          = _wp_array_get( $block_attributes, array( 'style', 'border', 'color' ), null );
     105        $custom_border_color          = isset( $block_attributes['style']['border']['color'] ) ? $block_attributes['style']['border']['color'] : null;
    106106        $border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color;
    107107    }
     
    110110    if ( $has_border_color_support || $has_border_width_support ) {
    111111        foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
    112             $border                       = _wp_array_get( $block_attributes, array( 'style', 'border', $side ), null );
     112            $border                       = isset( $block_attributes['style']['border'][ $side ] ) ? $block_attributes['style']['border'][ $side ] : null;
    113113            $border_side_values           = array(
    114114                'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
     
    153153function wp_has_border_feature_support( $block_type, $feature, $default_value = false ) {
    154154    // Check if all border support features have been opted into via `"__experimentalBorder": true`.
    155     if (
    156         property_exists( $block_type, 'supports' ) &&
    157         ( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default_value ) )
    158     ) {
    159         return true;
     155    if ( property_exists( $block_type, 'supports' ) ) {
     156        $block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] )
     157            ? $block_type->supports['__experimentalBorder']
     158            : $default_value;
     159        if ( true === $block_type_supports_border ) {
     160            return true;
     161        }
    160162    }
    161163
  • trunk/src/wp-includes/block-supports/colors.php

    r56604 r56709  
    1717 */
    1818function wp_register_colors_support( $block_type ) {
    19     $color_support                 = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( 'color' ), false ) : false;
    20     $has_text_colors_support       = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
    21     $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
    22     $has_gradients_support         = _wp_array_get( $color_support, array( 'gradients' ), false );
    23     $has_link_colors_support       = _wp_array_get( $color_support, array( 'link' ), false );
    24     $has_button_colors_support     = _wp_array_get( $color_support, array( 'button' ), false );
    25     $has_heading_colors_support    = _wp_array_get( $color_support, array( 'heading' ), false );
     19    $color_support = false;
     20    if ( property_exists( $block_type, 'supports' ) ) {
     21        $color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
     22    }
     23    $has_text_colors_support       = true === $color_support ||
     24        ( isset( $color_support['text'] ) && $color_support['text'] ) ||
     25        ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
     26    $has_background_colors_support = true === $color_support ||
     27        ( isset( $color_support['background'] ) && $color_support['background'] ) ||
     28        ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
     29    $has_gradients_support         = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
     30    $has_link_colors_support       = isset( $color_support['link'] ) ? $color_support['link'] : false;
     31    $has_button_colors_support     = isset( $color_support['button'] ) ? $color_support['button'] : false;
     32    $has_heading_colors_support    = isset( $color_support['heading'] ) ? $color_support['heading'] : false;
    2633    $has_color_support             = $has_text_colors_support ||
    2734        $has_background_colors_support ||
     
    7582 */
    7683function wp_apply_colors_support( $block_type, $block_attributes ) {
    77     $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
     84    $color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
    7885
    7986    if (
     
    8491    }
    8592
    86     $has_text_colors_support       = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
    87     $has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
    88     $has_gradients_support         = _wp_array_get( $color_support, array( 'gradients' ), false );
     93    $has_text_colors_support       = true === $color_support ||
     94        ( isset( $color_support['text'] ) && $color_support['text'] ) ||
     95        ( is_array( $color_support ) && ! isset( $color_support['text'] ) );
     96    $has_background_colors_support = true === $color_support ||
     97        ( isset( $color_support['background'] ) && $color_support['background'] ) ||
     98        ( is_array( $color_support ) && ! isset( $color_support['background'] ) );
     99    $has_gradients_support         = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
    89100    $color_block_styles            = array();
    90101
     
    92103    if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) {
    93104        $preset_text_color          = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
    94         $custom_text_color          = _wp_array_get( $block_attributes, array( 'style', 'color', 'text' ), null );
     105        $custom_text_color          = isset( $block_attributes['style']['color']['text'] ) ? $block_attributes['style']['color']['text'] : null;
    95106        $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
    96107    }
     
    99110    if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) {
    100111        $preset_background_color          = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
    101         $custom_background_color          = _wp_array_get( $block_attributes, array( 'style', 'color', 'background' ), null );
     112        $custom_background_color          = isset( $block_attributes['style']['color']['background'] ) ? $block_attributes['style']['color']['background'] : null;
    102113        $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
    103114    }
     
    106117    if ( $has_gradients_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) {
    107118        $preset_gradient_color          = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
    108         $custom_gradient_color          = _wp_array_get( $block_attributes, array( 'style', 'color', 'gradient' ), null );
     119        $custom_gradient_color          = isset( $block_attributes['style']['color']['gradient'] ) ? $block_attributes['style']['color']['gradient'] : null;
    109120        $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
    110121    }
  • trunk/src/wp-includes/block-supports/dimensions.php

    r56382 r56709  
    6969    $skip_min_height                      = wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'minHeight' );
    7070    $dimensions_block_styles              = array();
    71     $dimensions_block_styles['minHeight'] = $has_min_height_support && ! $skip_min_height ? _wp_array_get( $block_styles, array( 'dimensions', 'minHeight' ), null ) : null;
    72     $styles                               = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
     71    $dimensions_block_styles['minHeight'] = null;
     72    if ( $has_min_height_support && ! $skip_min_height ) {
     73        $dimensions_block_styles['minHeight'] = isset( $block_styles['dimensions']['minHeight'] )
     74            ? $block_styles['dimensions']['minHeight']
     75            : null;
     76    }
     77    $styles = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
    7378
    7479    if ( ! empty( $styles['css'] ) ) {
  • trunk/src/wp-includes/block-supports/elements.php

    r56680 r56709  
    176176        }
    177177
    178         $element_style_object = _wp_array_get( $element_block_styles, array( $element_type ), null );
     178        $element_style_object = isset( $element_block_styles[ $element_type ] ) ? $element_block_styles[ $element_type ] : null;
    179179
    180180        // Process primary element type styles.
     
    202202        if ( isset( $element_config['elements'] ) ) {
    203203            foreach ( $element_config['elements'] as $element ) {
    204                 $element_style_object = _wp_array_get( $element_block_styles, array( $element ), null );
     204                $element_style_object = isset( $element_block_styles[ $element ] )
     205                    ? $element_block_styles[ $element ]
     206                    : null;
    205207
    206208                if ( $element_style_object ) {
  • trunk/src/wp-includes/block-supports/layout.php

    r56700 r56709  
    415415
    416416            foreach ( $gap_sides as $gap_side ) {
    417                 $process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
     417                $process_value = $gap_value;
     418                if ( is_array( $gap_value ) ) {
     419                    $process_value = isset( $gap_value[ $gap_side ] ) ? $gap_value[ $gap_side ] : $fallback_gap_value;
     420                }
    418421                // Get spacing CSS variable from preset value if provided.
    419422                if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
     
    496499
    497500            foreach ( $gap_sides as $gap_side ) {
    498                 $process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
     501                $process_value = $gap_value;
     502                if ( is_array( $gap_value ) ) {
     503                    $process_value = isset( $gap_value[ $gap_side ] ) ? $gap_value[ $gap_side ] : $fallback_gap_value;
     504                }
    499505                // Get spacing CSS variable from preset value if provided.
    500506                if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
     
    613619
    614620    $global_settings = wp_get_global_settings();
    615     $fallback_layout = ! empty( _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) ) ? _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
    616     $used_layout     = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
     621    $fallback_layout = isset( $block_type->supports['layout']['default'] )
     622        ? $block_type->supports['layout']['default']
     623        : array();
     624    if ( empty( $fallback_layout ) ) {
     625        $fallback_layout = isset( $block_type->supports['__experimentalLayout']['default'] )
     626            ? $block_type->supports['__experimentalLayout']['default']
     627            : array();
     628    }
     629    $used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
    617630
    618631    $class_names        = array();
     
    625638    }
    626639
    627     $root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );
     640    $root_padding_aware_alignments = isset( $global_settings['useRootPaddingAwareAlignments'] )
     641        ? $global_settings['useRootPaddingAwareAlignments']
     642        : false;
    628643
    629644    if (
     
    655670    // Get classname for layout type.
    656671    if ( isset( $used_layout['type'] ) ) {
    657         $layout_classname = _wp_array_get( $layout_definitions, array( $used_layout['type'], 'className' ), '' );
     672        $layout_classname = isset( $layout_definitions[ $used_layout['type'] ]['className'] )
     673            ? $layout_definitions[ $used_layout['type'] ]['className']
     674            : '';
    658675    } else {
    659         $layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' );
     676        $layout_classname = isset( $layout_definitions['default']['className'] )
     677            ? $layout_definitions['default']['className']
     678            : '';
    660679    }
    661680
     
    670689    if ( ! current_theme_supports( 'disable-layout-styles' ) ) {
    671690
    672         $gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
     691        $gap_value = isset( $block['attrs']['style']['spacing']['blockGap'] )
     692            ? $block['attrs']['style']['spacing']['blockGap']
     693            : null;
    673694        /*
    674695         * Skip if gap value contains unsupported characters.
     
    684705        }
    685706
    686         $fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' );
    687         $block_spacing      = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null );
     707        $fallback_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
     708            ? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
     709            : '0.5em';
     710        $block_spacing      = isset( $block['attrs']['style']['spacing'] )
     711            ? $block['attrs']['style']['spacing']
     712            : null;
    688713
    689714        /*
     
    693718        $should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );
    694719
    695         $block_gap             = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
     720        $block_gap             = isset( $global_settings['spacing']['blockGap'] )
     721            ? $global_settings['spacing']['blockGap']
     722            : null;
    696723        $has_block_gap_support = isset( $block_gap );
    697724
  • trunk/src/wp-includes/block-supports/position.php

    r56382 r56709  
    5252
    5353    $global_settings          = wp_get_global_settings();
    54     $theme_has_sticky_support = _wp_array_get( $global_settings, array( 'position', 'sticky' ), false );
    55     $theme_has_fixed_support  = _wp_array_get( $global_settings, array( 'position', 'fixed' ), false );
     54    $theme_has_sticky_support = isset( $global_settings['position']['sticky'] ) ? $global_settings['position']['sticky'] : false;
     55    $theme_has_fixed_support  = isset( $global_settings['position']['fixed'] ) ? $global_settings['position']['fixed'] : false;
    5656
    5757    // Only allow output for position types that the theme supports.
     
    6464    }
    6565
    66     $style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null );
     66    $style_attribute = isset( $block['attrs']['style'] ) ? $block['attrs']['style'] : null;
    6767    $class_name      = wp_unique_id( 'wp-container-' );
    6868    $selector        = ".$class_name";
    6969    $position_styles = array();
    70     $position_type   = _wp_array_get( $style_attribute, array( 'position', 'type' ), '' );
     70    $position_type   = isset( $style_attribute['position']['type'] ) ? $style_attribute['position']['type'] : '';
    7171    $wrapper_classes = array();
    7272
     
    7979
    8080        foreach ( $sides as $side ) {
    81             $side_value = _wp_array_get( $style_attribute, array( 'position', $side ) );
     81            $side_value = isset( $style_attribute['position'][ $side ] ) ? $style_attribute['position'][ $side ] : null;
    8282            if ( null !== $side_value ) {
    8383                /*
  • trunk/src/wp-includes/block-supports/settings.php

    r56382 r56709  
    4646
    4747    // return early if no settings are found on the block attributes.
    48     $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
     48    $block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
    4949    if ( empty( $block_settings ) ) {
    5050        return $block_content;
     
    8383
    8484    // return early if no settings are found on the block attributes.
    85     $block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
     85    $block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
    8686    if ( empty( $block_settings ) ) {
    8787        return null;
  • trunk/src/wp-includes/block-supports/spacing.php

    r56382 r56709  
    5959    }
    6060
    61     $skip_padding                    = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
    62     $skip_margin                     = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
    63     $spacing_block_styles            = array();
    64     $spacing_block_styles['padding'] = $has_padding_support && ! $skip_padding ? _wp_array_get( $block_styles, array( 'spacing', 'padding' ), null ) : null;
    65     $spacing_block_styles['margin']  = $has_margin_support && ! $skip_margin ? _wp_array_get( $block_styles, array( 'spacing', 'margin' ), null ) : null;
    66     $styles                          = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
     61    $skip_padding         = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
     62    $skip_margin          = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
     63    $spacing_block_styles = array(
     64        'padding' => null,
     65        'margin'  => null,
     66    );
     67    if ( $has_padding_support && ! $skip_padding ) {
     68        $spacing_block_styles['padding'] = isset( $block_styles['spacing']['padding'] ) ? $block_styles['spacing']['padding'] : null;
     69    }
     70    if ( $has_margin_support && ! $skip_margin ) {
     71        $spacing_block_styles['margin'] = isset( $block_styles['spacing']['margin'] ) ? $block_styles['spacing']['margin'] : null;
     72    }
     73    $styles = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
    6774
    6875    if ( ! empty( $styles['css'] ) ) {
  • trunk/src/wp-includes/block-supports/typography.php

    r56605 r56709  
    2121    }
    2222
    23     $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
     23    $typography_supports = isset( $block_type->supports['typography'] ) ? $block_type->supports['typography'] : false;
    2424    if ( ! $typography_supports ) {
    2525        return;
    2626    }
    2727
    28     $has_font_family_support     = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
    29     $has_font_size_support       = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
    30     $has_font_style_support      = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
    31     $has_font_weight_support     = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
    32     $has_letter_spacing_support  = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
    33     $has_line_height_support     = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
    34     $has_text_columns_support    = _wp_array_get( $typography_supports, array( 'textColumns' ), false );
    35     $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
    36     $has_text_transform_support  = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
    37     $has_writing_mode_support    = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );
     28    $has_font_family_support     = isset( $typography_supports['__experimentalFontFamily'] ) ? $typography_supports['__experimentalFontFamily'] : false;
     29    $has_font_size_support       = isset( $typography_supports['fontSize'] ) ? $typography_supports['fontSize'] : false;
     30    $has_font_style_support      = isset( $typography_supports['__experimentalFontStyle'] ) ? $typography_supports['__experimentalFontStyle'] : false;
     31    $has_font_weight_support     = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
     32    $has_letter_spacing_support  = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
     33    $has_line_height_support     = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
     34    $has_text_columns_support    = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
     35    $has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
     36    $has_text_transform_support  = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
     37    $has_writing_mode_support    = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
    3838
    3939    $has_typography_support = $has_font_family_support
     
    9090    }
    9191
    92     $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
     92    $typography_supports = isset( $block_type->supports['typography'] )
     93        ? $block_type->supports['typography']
     94        : false;
    9395    if ( ! $typography_supports ) {
    9496        return array();
     
    99101    }
    100102
    101     $has_font_family_support     = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
    102     $has_font_size_support       = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
    103     $has_font_style_support      = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
    104     $has_font_weight_support     = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
    105     $has_letter_spacing_support  = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
    106     $has_line_height_support     = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
    107     $has_text_columns_support    = _wp_array_get( $typography_supports, array( 'textColumns' ), false );
    108     $has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
    109     $has_text_transform_support  = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
    110     $has_writing_mode_support    = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );
     103    $has_font_family_support     = isset( $typography_supports['__experimentalFontFamily'] ) ? $typography_supports['__experimentalFontFamily'] : false;
     104    $has_font_size_support       = isset( $typography_supports['fontSize'] ) ? $typography_supports['fontSize'] : false;
     105    $has_font_style_support      = isset( $typography_supports['__experimentalFontStyle'] ) ? $typography_supports['__experimentalFontStyle'] : false;
     106    $has_font_weight_support     = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
     107    $has_letter_spacing_support  = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
     108    $has_line_height_support     = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
     109    $has_text_columns_support    = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
     110    $has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
     111    $has_text_transform_support  = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
     112    $has_writing_mode_support    = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
    111113
    112114    // Whether to skip individual block support features.
     
    170172
    171173    if ( $has_line_height_support && ! $should_skip_line_height ) {
    172         $typography_block_styles['lineHeight'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'lineHeight' ) );
     174        $typography_block_styles['lineHeight'] = isset( $block_attributes['style']['typography']['lineHeight'] )
     175            ? $block_attributes['style']['typography']['lineHeight']
     176            : null;
    173177    }
    174178
    175179    if ( $has_text_columns_support && ! $should_skip_text_columns && isset( $block_attributes['style']['typography']['textColumns'] ) ) {
    176         $typography_block_styles['textColumns'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'textColumns' ), null );
     180        $typography_block_styles['textColumns'] = isset( $block_attributes['style']['typography']['textColumns'] )
     181            ? $block_attributes['style']['typography']['textColumns']
     182            : null;
    177183    }
    178184
     
    214220        isset( $block_attributes['style']['typography']['writingMode'] )
    215221    ) {
    216         $typography_block_styles['writingMode'] = _wp_array_get(
    217             $block_attributes,
    218             array( 'style', 'typography', 'writingMode' ),
    219             null
    220         );
     222        $typography_block_styles['writingMode'] = isset( $block_attributes['style']['typography']['writingMode'] )
     223            ? $block_attributes['style']['typography']['writingMode']
     224            : null;
    221225    }
    222226
  • trunk/src/wp-includes/blocks.php

    r56704 r56709  
    16371637
    16381638    foreach ( $typography_keys as $typography_key ) {
    1639         $support_for_key = _wp_array_get( $metadata['supports'], array( $typography_key ), null );
     1639        $support_for_key = isset( $metadata['supports'][ $typography_key ] ) ? $metadata['supports'][ $typography_key ] : null;
    16401640
    16411641        if ( null !== $support_for_key ) {
  • trunk/src/wp-includes/class-wp-duotone.php

    r56226 r56709  
    972972         * treated as a selector and requires scoping.
    973973         */
    974         $experimental_duotone = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
     974        $experimental_duotone = isset( $block_type->supports['color']['__experimentalDuotone'] )
     975            ? $block_type->supports['color']['__experimentalDuotone']
     976            : false;
    975977        if ( $experimental_duotone ) {
    976978            $root_selector = wp_get_block_css_selector( $block_type );
     
    10011003        // Get the per block settings from the theme.json.
    10021004        $tree              = wp_get_global_settings();
    1003         $presets_by_origin = _wp_array_get( $tree, array( 'color', 'duotone' ), array() );
     1005        $presets_by_origin = isset( $tree['color']['duotone'] ) ? $tree['color']['duotone'] : array();
    10041006
    10051007        self::$global_styles_presets = array();
     
    12631265     */
    12641266    public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
    1265         $duotone_support = _wp_array_get( $metadata, array( 'supports', 'color', '__experimentalDuotone' ), null );
     1267        $duotone_support = isset( $metadata['supports']['color']['__experimentalDuotone'] )
     1268            ? $metadata['supports']['color']['__experimentalDuotone']
     1269            : null;
    12661270
    12671271        if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
  • trunk/src/wp-includes/class-wp-theme-json-resolver.php

    r56179 r56709  
    357357            if (
    358358                isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
    359                 null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null )
     359                ! isset( $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] )
    360360            ) {
    361361                /*
  • trunk/src/wp-includes/class-wp-theme-json.php

    r56643 r56709  
    924924            // Keep backwards compatibility for support.color.__experimentalDuotone.
    925925            if ( null === $duotone_selector ) {
    926                 $duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null );
     926                $duotone_support = isset( $block_type->supports['color']['__experimentalDuotone'] )
     927                    ? $block_type->supports['color']['__experimentalDuotone']
     928                    : null;
    927929
    928930                if ( $duotone_support ) {
     
    11611163    public function get_custom_css() {
    11621164        // Add the global styles root CSS.
    1163         $stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' );
     1165        $stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';
    11641166
    11651167        // Add the global styles block CSS.
    11661168        if ( isset( $this->theme_json['styles']['blocks'] ) ) {
    11671169            foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
    1168                 $custom_block_css = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $name, 'css' ) );
     1170                $custom_block_css = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
     1171                    ? $this->theme_json['styles']['blocks'][ $name ]['css']
     1172                    : null;
    11691173                if ( $custom_block_css ) {
    11701174                    $selector    = static::$blocks_metadata[ $name ]['selector'];
     
    12851289
    12861290        $selector                 = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
    1287         $has_block_gap_support    = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
     1291        $has_block_gap_support    = isset( $this->theme_json['settings']['spacing']['blockGap'] );
    12881292        $has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
    12891293        $node                     = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
     
    13011305                $block_gap_value = static::ROOT_BLOCK_SELECTOR === $selector ? '0.5em' : null;
    13021306                if ( ! empty( $block_type ) ) {
    1303                     $block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), null );
     1307                    $block_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
     1308                        ? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
     1309                        : null;
    13041310                }
    13051311            } else {
     
    13271333                    }
    13281334
    1329                     $class_name    = _wp_array_get( $layout_definition, array( 'className' ), false );
    1330                     $spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() );
     1335                    $class_name    = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
     1336                    $spacing_rules = isset( $layout_definition['spacingStyles'] ) ? $layout_definition['spacingStyles'] : array();
    13311337
    13321338                    if (
     
    13841390            $valid_display_modes = array( 'block', 'flex', 'grid' );
    13851391            foreach ( $layout_definitions as $layout_definition ) {
    1386                 $class_name       = _wp_array_get( $layout_definition, array( 'className' ), false );
    1387                 $base_style_rules = _wp_array_get( $layout_definition, array( 'baseStyles' ), array() );
     1392                $class_name       = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
     1393                $base_style_rules = isset( $layout_definition['baseStyles'] ) ? $layout_definition['baseStyles'] : array();
    13881394
    13891395                if (
     
    18131819    protected static function compute_theme_vars( $settings ) {
    18141820        $declarations  = array();
    1815         $custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
     1821        $custom_values = isset( $settings['custom'] ) ? $settings['custom'] : array();
    18161822        $css_vars      = static::flatten_tree( $custom_values );
    18171823        foreach ( $css_vars as $key => $value ) {
     
    23272333        $use_root_padding     = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
    23282334        $selector             = $block_metadata['selector'];
    2329         $settings             = _wp_array_get( $this->theme_json, array( 'settings' ) );
     2335        $settings             = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
    23302336        $feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node );
    23312337
     
    24672473    public function get_root_layout_rules( $selector, $block_metadata ) {
    24682474        $css              = '';
    2469         $settings         = _wp_array_get( $this->theme_json, array( 'settings' ) );
     2475        $settings         = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
    24702476        $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
    24712477
     
    25162522        $css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
    25172523
    2518         $block_gap_value       = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' );
    2519         $has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
     2524        $block_gap_value       = isset( $this->theme_json['styles']['spacing']['blockGap'] ) ? $this->theme_json['styles']['spacing']['blockGap'] : '0.5em';
     2525        $has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
    25202526        if ( $has_block_gap_support ) {
    25212527            $block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
     
    33563362     */
    33573363    public function set_spacing_sizes() {
    3358         $spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() );
     3364        $spacing_scale = isset( $this->theme_json['settings']['spacing']['spacingScale'] )
     3365            ? $this->theme_json['settings']['spacing']['spacingScale']
     3366            : array();
    33593367
    33603368        if ( ! isset( $spacing_scale['steps'] )
     
    35953603        }
    35963604
    3597         $settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
     3605        $settings = isset( $this->theme_json['settings'] )
     3606            ? $this->theme_json['settings']
     3607            : array();
    35983608
    35993609        foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
  • trunk/src/wp-includes/deprecated.php

    r56690 r56709  
    42544254    _deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
    42554255
    4256     $border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false );
     4256    $border_support = isset( $block_type->supports['__experimentalBorder'] )
     4257        ? $block_type->supports['__experimentalBorder']
     4258        : false;
    42574259
    42584260    return is_array( $border_support ) &&
     
    42764278    _deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
    42774279
    4278     $dimensions_support = _wp_array_get( $block_type->supports, array( '__experimentalDimensions' ), false );
     4280    $dimensions_support = isset( $block_type->supports['__experimentalDimensions'] )
     4281        ? $block_type->supports['__experimentalDimensions']
     4282        : false;
    42794283
    42804284    return is_array( $dimensions_support ) &&
     
    42984302    _deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
    42994303
    4300     $spacing_support = _wp_array_get( $block_type->supports, array( 'spacing' ), false );
     4304    $spacing_support = isset( $block_type->supports['spacing'] )
     4305        ? $block_type->supports['spacing']
     4306        : false;
    43014307
    43024308    return is_array( $spacing_support ) &&
Note: See TracChangeset for help on using the changeset viewer.