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:
* [https://github.com/WordPress/gutenberg/pull/51116 #51116 Performance improvement: Reduce the use of the _wp_array_get() function]

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

Props aristath, jrf, spacedmonkey, mukesh27, swissspidy, hellofromTonya.
Fixes #59405.
Built from https://develop.svn.wordpress.org/trunk@56709


git-svn-id: http://core.svn.wordpress.org/trunk@56221 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2023-09-26 13:47:20 +00:00
parent 72460848c9
commit 9bf6faff7c
16 changed files with 190 additions and 106 deletions

View File

@ -58,9 +58,15 @@ function wp_render_background_support( $block_content, $block ) {
return $block_content;
}
$background_image_source = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'source' ), null );
$background_image_url = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'url' ), null );
$background_size = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundSize' ), 'cover' );
$background_image_source = isset( $block_attributes['style']['background']['backgroundImage']['source'] )
? $block_attributes['style']['background']['backgroundImage']['source']
: null;
$background_image_url = isset( $block_attributes['style']['background']['backgroundImage']['url'] )
? $block_attributes['style']['background']['backgroundImage']['url']
: null;
$background_size = isset( $block_attributes['style']['background']['backgroundSize'] )
? $block_attributes['style']['background']['backgroundSize']
: 'cover';
$background_block_styles = array();

View File

@ -102,14 +102,14 @@ function wp_apply_border_support( $block_type, $block_attributes ) {
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
) {
$preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
$custom_border_color = _wp_array_get( $block_attributes, array( 'style', 'border', 'color' ), null );
$custom_border_color = isset( $block_attributes['style']['border']['color'] ) ? $block_attributes['style']['border']['color'] : null;
$border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color;
}
// Generates styles for individual border sides.
if ( $has_border_color_support || $has_border_width_support ) {
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
$border = _wp_array_get( $block_attributes, array( 'style', 'border', $side ), null );
$border = isset( $block_attributes['style']['border'][ $side ] ) ? $block_attributes['style']['border'][ $side ] : null;
$border_side_values = array(
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
@ -152,11 +152,13 @@ function wp_apply_border_support( $block_type, $block_attributes ) {
*/
function wp_has_border_feature_support( $block_type, $feature, $default_value = false ) {
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
if (
property_exists( $block_type, 'supports' ) &&
( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default_value ) )
) {
return true;
if ( property_exists( $block_type, 'supports' ) ) {
$block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] )
? $block_type->supports['__experimentalBorder']
: $default_value;
if ( true === $block_type_supports_border ) {
return true;
}
}
// Check if the specific feature has been opted into individually

View File

@ -16,13 +16,20 @@
* @param WP_Block_Type $block_type Block Type.
*/
function wp_register_colors_support( $block_type ) {
$color_support = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( 'color' ), false ) : false;
$has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
$has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
$has_link_colors_support = _wp_array_get( $color_support, array( 'link' ), false );
$has_button_colors_support = _wp_array_get( $color_support, array( 'button' ), false );
$has_heading_colors_support = _wp_array_get( $color_support, array( 'heading' ), false );
$color_support = false;
if ( property_exists( $block_type, 'supports' ) ) {
$color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
}
$has_text_colors_support = true === $color_support ||
( isset( $color_support['text'] ) && $color_support['text'] ) ||
( is_array( $color_support ) && ! isset( $color_support['text'] ) );
$has_background_colors_support = true === $color_support ||
( isset( $color_support['background'] ) && $color_support['background'] ) ||
( is_array( $color_support ) && ! isset( $color_support['background'] ) );
$has_gradients_support = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
$has_link_colors_support = isset( $color_support['link'] ) ? $color_support['link'] : false;
$has_button_colors_support = isset( $color_support['button'] ) ? $color_support['button'] : false;
$has_heading_colors_support = isset( $color_support['heading'] ) ? $color_support['heading'] : false;
$has_color_support = $has_text_colors_support ||
$has_background_colors_support ||
$has_gradients_support ||
@ -74,7 +81,7 @@ function wp_register_colors_support( $block_type ) {
* @return array Colors CSS classes and inline styles.
*/
function wp_apply_colors_support( $block_type, $block_attributes ) {
$color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
$color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;
if (
is_array( $color_support ) &&
@ -83,29 +90,33 @@ function wp_apply_colors_support( $block_type, $block_attributes ) {
return array();
}
$has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
$has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
$has_text_colors_support = true === $color_support ||
( isset( $color_support['text'] ) && $color_support['text'] ) ||
( is_array( $color_support ) && ! isset( $color_support['text'] ) );
$has_background_colors_support = true === $color_support ||
( isset( $color_support['background'] ) && $color_support['background'] ) ||
( is_array( $color_support ) && ! isset( $color_support['background'] ) );
$has_gradients_support = isset( $color_support['gradients'] ) ? $color_support['gradients'] : false;
$color_block_styles = array();
// Text colors.
if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) {
$preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
$custom_text_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'text' ), null );
$custom_text_color = isset( $block_attributes['style']['color']['text'] ) ? $block_attributes['style']['color']['text'] : null;
$color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
}
// Background colors.
if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) {
$preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
$custom_background_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'background' ), null );
$custom_background_color = isset( $block_attributes['style']['color']['background'] ) ? $block_attributes['style']['color']['background'] : null;
$color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
}
// Gradients.
if ( $has_gradients_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) {
$preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
$custom_gradient_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'gradient' ), null );
$custom_gradient_color = isset( $block_attributes['style']['color']['gradient'] ) ? $block_attributes['style']['color']['gradient'] : null;
$color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
}

View File

@ -68,8 +68,13 @@ function wp_apply_dimensions_support( $block_type, $block_attributes ) { // phpc
$skip_min_height = wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'minHeight' );
$dimensions_block_styles = array();
$dimensions_block_styles['minHeight'] = $has_min_height_support && ! $skip_min_height ? _wp_array_get( $block_styles, array( 'dimensions', 'minHeight' ), null ) : null;
$styles = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
$dimensions_block_styles['minHeight'] = null;
if ( $has_min_height_support && ! $skip_min_height ) {
$dimensions_block_styles['minHeight'] = isset( $block_styles['dimensions']['minHeight'] )
? $block_styles['dimensions']['minHeight']
: null;
}
$styles = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];

View File

@ -175,7 +175,7 @@ function wp_render_elements_support_styles( $pre_render, $block ) {
continue;
}
$element_style_object = _wp_array_get( $element_block_styles, array( $element_type ), null );
$element_style_object = isset( $element_block_styles[ $element_type ] ) ? $element_block_styles[ $element_type ] : null;
// Process primary element type styles.
if ( $element_style_object ) {
@ -201,7 +201,9 @@ function wp_render_elements_support_styles( $pre_render, $block ) {
// Process related elements e.g. h1-h6 for headings.
if ( isset( $element_config['elements'] ) ) {
foreach ( $element_config['elements'] as $element ) {
$element_style_object = _wp_array_get( $element_block_styles, array( $element ), null );
$element_style_object = isset( $element_block_styles[ $element ] )
? $element_block_styles[ $element ]
: null;
if ( $element_style_object ) {
wp_style_engine_get_styles(

View File

@ -414,7 +414,10 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );
foreach ( $gap_sides as $gap_side ) {
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = isset( $gap_value[ $gap_side ] ) ? $gap_value[ $gap_side ] : $fallback_gap_value;
}
// Get spacing CSS variable from preset value if provided.
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
$index_to_splice = strrpos( $process_value, '|' ) + 1;
@ -495,7 +498,10 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );
foreach ( $gap_sides as $gap_side ) {
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = isset( $gap_value[ $gap_side ] ) ? $gap_value[ $gap_side ] : $fallback_gap_value;
}
// Get spacing CSS variable from preset value if provided.
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
$index_to_splice = strrpos( $process_value, '|' ) + 1;
@ -612,8 +618,15 @@ function wp_render_layout_support_flag( $block_content, $block ) {
}
$global_settings = wp_get_global_settings();
$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() );
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
$fallback_layout = isset( $block_type->supports['layout']['default'] )
? $block_type->supports['layout']['default']
: array();
if ( empty( $fallback_layout ) ) {
$fallback_layout = isset( $block_type->supports['__experimentalLayout']['default'] )
? $block_type->supports['__experimentalLayout']['default']
: array();
}
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
$class_names = array();
$layout_definitions = wp_get_layout_definitions();
@ -624,7 +637,9 @@ 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 );
$root_padding_aware_alignments = isset( $global_settings['useRootPaddingAwareAlignments'] )
? $global_settings['useRootPaddingAwareAlignments']
: false;
if (
$root_padding_aware_alignments &&
@ -654,9 +669,13 @@ function wp_render_layout_support_flag( $block_content, $block ) {
// Get classname for layout type.
if ( isset( $used_layout['type'] ) ) {
$layout_classname = _wp_array_get( $layout_definitions, array( $used_layout['type'], 'className' ), '' );
$layout_classname = isset( $layout_definitions[ $used_layout['type'] ]['className'] )
? $layout_definitions[ $used_layout['type'] ]['className']
: '';
} else {
$layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' );
$layout_classname = isset( $layout_definitions['default']['className'] )
? $layout_definitions['default']['className']
: '';
}
if ( $layout_classname && is_string( $layout_classname ) ) {
@ -669,7 +688,9 @@ function wp_render_layout_support_flag( $block_content, $block ) {
*/
if ( ! current_theme_supports( 'disable-layout-styles' ) ) {
$gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
$gap_value = isset( $block['attrs']['style']['spacing']['blockGap'] )
? $block['attrs']['style']['spacing']['blockGap']
: null;
/*
* Skip if gap value contains unsupported characters.
* Regex for CSS value borrowed from `safecss_filter_attr`, and used here
@ -683,8 +704,12 @@ function wp_render_layout_support_flag( $block_content, $block ) {
$gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
}
$fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' );
$block_spacing = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null );
$fallback_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
: '0.5em';
$block_spacing = isset( $block['attrs']['style']['spacing'] )
? $block['attrs']['style']['spacing']
: null;
/*
* If a block's block.json skips serialization for spacing or spacing.blockGap,
@ -692,7 +717,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 );
$block_gap = isset( $global_settings['spacing']['blockGap'] )
? $global_settings['spacing']['blockGap']
: null;
$has_block_gap_support = isset( $block_gap );
$style = wp_get_layout_style(

View File

@ -51,8 +51,8 @@ function wp_render_position_support( $block_content, $block ) {
}
$global_settings = wp_get_global_settings();
$theme_has_sticky_support = _wp_array_get( $global_settings, array( 'position', 'sticky' ), false );
$theme_has_fixed_support = _wp_array_get( $global_settings, array( 'position', 'fixed' ), false );
$theme_has_sticky_support = isset( $global_settings['position']['sticky'] ) ? $global_settings['position']['sticky'] : false;
$theme_has_fixed_support = isset( $global_settings['position']['fixed'] ) ? $global_settings['position']['fixed'] : false;
// Only allow output for position types that the theme supports.
$allowed_position_types = array();
@ -63,11 +63,11 @@ function wp_render_position_support( $block_content, $block ) {
$allowed_position_types[] = 'fixed';
}
$style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null );
$style_attribute = isset( $block['attrs']['style'] ) ? $block['attrs']['style'] : null;
$class_name = wp_unique_id( 'wp-container-' );
$selector = ".$class_name";
$position_styles = array();
$position_type = _wp_array_get( $style_attribute, array( 'position', 'type' ), '' );
$position_type = isset( $style_attribute['position']['type'] ) ? $style_attribute['position']['type'] : '';
$wrapper_classes = array();
if (
@ -78,7 +78,7 @@ function wp_render_position_support( $block_content, $block ) {
$sides = array( 'top', 'right', 'bottom', 'left' );
foreach ( $sides as $side ) {
$side_value = _wp_array_get( $style_attribute, array( 'position', $side ) );
$side_value = isset( $style_attribute['position'][ $side ] ) ? $style_attribute['position'][ $side ] : null;
if ( null !== $side_value ) {
/*
* For fixed or sticky top positions,

View File

@ -45,7 +45,7 @@ function _wp_add_block_level_presets_class( $block_content, $block ) {
}
// return early if no settings are found on the block attributes.
$block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
$block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
if ( empty( $block_settings ) ) {
return $block_content;
}
@ -82,7 +82,7 @@ function _wp_add_block_level_preset_styles( $pre_render, $block ) {
}
// return early if no settings are found on the block attributes.
$block_settings = _wp_array_get( $block, array( 'attrs', 'settings' ), null );
$block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
if ( empty( $block_settings ) ) {
return null;
}

View File

@ -58,12 +58,19 @@ function wp_apply_spacing_support( $block_type, $block_attributes ) {
return $attributes;
}
$skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
$skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
$spacing_block_styles = array();
$spacing_block_styles['padding'] = $has_padding_support && ! $skip_padding ? _wp_array_get( $block_styles, array( 'spacing', 'padding' ), null ) : null;
$spacing_block_styles['margin'] = $has_margin_support && ! $skip_margin ? _wp_array_get( $block_styles, array( 'spacing', 'margin' ), null ) : null;
$styles = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
$skip_padding = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'padding' );
$skip_margin = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'margin' );
$spacing_block_styles = array(
'padding' => null,
'margin' => null,
);
if ( $has_padding_support && ! $skip_padding ) {
$spacing_block_styles['padding'] = isset( $block_styles['spacing']['padding'] ) ? $block_styles['spacing']['padding'] : null;
}
if ( $has_margin_support && ! $skip_margin ) {
$spacing_block_styles['margin'] = isset( $block_styles['spacing']['margin'] ) ? $block_styles['spacing']['margin'] : null;
}
$styles = wp_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) );
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];

View File

@ -20,21 +20,21 @@ function wp_register_typography_support( $block_type ) {
return;
}
$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
$typography_supports = isset( $block_type->supports['typography'] ) ? $block_type->supports['typography'] : false;
if ( ! $typography_supports ) {
return;
}
$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
$has_writing_mode_support = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );
$has_font_family_support = isset( $typography_supports['__experimentalFontFamily'] ) ? $typography_supports['__experimentalFontFamily'] : false;
$has_font_size_support = isset( $typography_supports['fontSize'] ) ? $typography_supports['fontSize'] : false;
$has_font_style_support = isset( $typography_supports['__experimentalFontStyle'] ) ? $typography_supports['__experimentalFontStyle'] : false;
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
$has_letter_spacing_support = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
$has_line_height_support = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
$has_writing_mode_support = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
$has_typography_support = $has_font_family_support
|| $has_font_size_support
@ -89,7 +89,9 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
return array();
}
$typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false );
$typography_supports = isset( $block_type->supports['typography'] )
? $block_type->supports['typography']
: false;
if ( ! $typography_supports ) {
return array();
}
@ -98,16 +100,16 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
return array();
}
$has_font_family_support = _wp_array_get( $typography_supports, array( '__experimentalFontFamily' ), false );
$has_font_size_support = _wp_array_get( $typography_supports, array( 'fontSize' ), false );
$has_font_style_support = _wp_array_get( $typography_supports, array( '__experimentalFontStyle' ), false );
$has_font_weight_support = _wp_array_get( $typography_supports, array( '__experimentalFontWeight' ), false );
$has_letter_spacing_support = _wp_array_get( $typography_supports, array( '__experimentalLetterSpacing' ), false );
$has_line_height_support = _wp_array_get( $typography_supports, array( 'lineHeight' ), false );
$has_text_columns_support = _wp_array_get( $typography_supports, array( 'textColumns' ), false );
$has_text_decoration_support = _wp_array_get( $typography_supports, array( '__experimentalTextDecoration' ), false );
$has_text_transform_support = _wp_array_get( $typography_supports, array( '__experimentalTextTransform' ), false );
$has_writing_mode_support = _wp_array_get( $typography_supports, array( '__experimentalWritingMode' ), false );
$has_font_family_support = isset( $typography_supports['__experimentalFontFamily'] ) ? $typography_supports['__experimentalFontFamily'] : false;
$has_font_size_support = isset( $typography_supports['fontSize'] ) ? $typography_supports['fontSize'] : false;
$has_font_style_support = isset( $typography_supports['__experimentalFontStyle'] ) ? $typography_supports['__experimentalFontStyle'] : false;
$has_font_weight_support = isset( $typography_supports['__experimentalFontWeight'] ) ? $typography_supports['__experimentalFontWeight'] : false;
$has_letter_spacing_support = isset( $typography_supports['__experimentalLetterSpacing'] ) ? $typography_supports['__experimentalLetterSpacing'] : false;
$has_line_height_support = isset( $typography_supports['lineHeight'] ) ? $typography_supports['lineHeight'] : false;
$has_text_columns_support = isset( $typography_supports['textColumns'] ) ? $typography_supports['textColumns'] : false;
$has_text_decoration_support = isset( $typography_supports['__experimentalTextDecoration'] ) ? $typography_supports['__experimentalTextDecoration'] : false;
$has_text_transform_support = isset( $typography_supports['__experimentalTextTransform'] ) ? $typography_supports['__experimentalTextTransform'] : false;
$has_writing_mode_support = isset( $typography_supports['__experimentalWritingMode'] ) ? $typography_supports['__experimentalWritingMode'] : false;
// Whether to skip individual block support features.
$should_skip_font_size = wp_should_skip_block_supports_serialization( $block_type, 'typography', 'fontSize' );
@ -169,11 +171,15 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
}
if ( $has_line_height_support && ! $should_skip_line_height ) {
$typography_block_styles['lineHeight'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'lineHeight' ) );
$typography_block_styles['lineHeight'] = isset( $block_attributes['style']['typography']['lineHeight'] )
? $block_attributes['style']['typography']['lineHeight']
: null;
}
if ( $has_text_columns_support && ! $should_skip_text_columns && isset( $block_attributes['style']['typography']['textColumns'] ) ) {
$typography_block_styles['textColumns'] = _wp_array_get( $block_attributes, array( 'style', 'typography', 'textColumns' ), null );
$typography_block_styles['textColumns'] = isset( $block_attributes['style']['typography']['textColumns'] )
? $block_attributes['style']['typography']['textColumns']
: null;
}
if (
@ -213,11 +219,9 @@ function wp_apply_typography_support( $block_type, $block_attributes ) {
! $should_skip_writing_mode &&
isset( $block_attributes['style']['typography']['writingMode'] )
) {
$typography_block_styles['writingMode'] = _wp_array_get(
$block_attributes,
array( 'style', 'typography', 'writingMode' ),
null
);
$typography_block_styles['writingMode'] = isset( $block_attributes['style']['typography']['writingMode'] )
? $block_attributes['style']['typography']['writingMode']
: null;
}
$attributes = array();

View File

@ -1636,7 +1636,7 @@ function wp_migrate_old_typography_shape( $metadata ) {
);
foreach ( $typography_keys as $typography_key ) {
$support_for_key = _wp_array_get( $metadata['supports'], array( $typography_key ), null );
$support_for_key = isset( $metadata['supports'][ $typography_key ] ) ? $metadata['supports'][ $typography_key ] : null;
if ( null !== $support_for_key ) {
_doing_it_wrong(

View File

@ -971,7 +971,9 @@ class WP_Duotone {
* If the experimental duotone support was set, that value is to be
* treated as a selector and requires scoping.
*/
$experimental_duotone = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
$experimental_duotone = isset( $block_type->supports['color']['__experimentalDuotone'] )
? $block_type->supports['color']['__experimentalDuotone']
: false;
if ( $experimental_duotone ) {
$root_selector = wp_get_block_css_selector( $block_type );
return is_string( $experimental_duotone )
@ -1000,7 +1002,7 @@ class WP_Duotone {
}
// Get the per block settings from the theme.json.
$tree = wp_get_global_settings();
$presets_by_origin = _wp_array_get( $tree, array( 'color', 'duotone' ), array() );
$presets_by_origin = isset( $tree['color']['duotone'] ) ? $tree['color']['duotone'] : array();
self::$global_styles_presets = array();
foreach ( $presets_by_origin as $presets ) {
@ -1262,7 +1264,9 @@ class WP_Duotone {
* @return array Filtered block type settings.
*/
public static function migrate_experimental_duotone_support_flag( $settings, $metadata ) {
$duotone_support = _wp_array_get( $metadata, array( 'supports', 'color', '__experimentalDuotone' ), null );
$duotone_support = isset( $metadata['supports']['color']['__experimentalDuotone'] )
? $metadata['supports']['color']['__experimentalDuotone']
: null;
if ( ! isset( $settings['supports']['filter']['duotone'] ) && null !== $duotone_support ) {
_wp_array_set( $settings, array( 'supports', 'filter', 'duotone' ), (bool) $duotone_support );

View File

@ -356,7 +356,7 @@ class WP_Theme_JSON_Resolver {
if (
isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ) &&
null === _wp_array_get( $config, array( 'styles', 'blocks', $block_name, 'spacing', 'blockGap' ), null )
! isset( $config['styles']['blocks'][ $block_name ]['spacing']['blockGap'] )
) {
/*
* Ensure an empty placeholder value exists for the block, if it provides a default blockGap value.

View File

@ -923,7 +923,9 @@ class WP_Theme_JSON {
// Keep backwards compatibility for support.color.__experimentalDuotone.
if ( null === $duotone_selector ) {
$duotone_support = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), null );
$duotone_support = isset( $block_type->supports['color']['__experimentalDuotone'] )
? $block_type->supports['color']['__experimentalDuotone']
: null;
if ( $duotone_support ) {
$root_selector = wp_get_block_css_selector( $block_type );
@ -1160,12 +1162,14 @@ class WP_Theme_JSON {
*/
public function get_custom_css() {
// Add the global styles root CSS.
$stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' );
$stylesheet = isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';
// Add the global styles block CSS.
if ( isset( $this->theme_json['styles']['blocks'] ) ) {
foreach ( $this->theme_json['styles']['blocks'] as $name => $node ) {
$custom_block_css = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $name, 'css' ) );
$custom_block_css = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
? $this->theme_json['styles']['blocks'][ $name ]['css']
: null;
if ( $custom_block_css ) {
$selector = static::$blocks_metadata[ $name ]['selector'];
$stylesheet .= $this->process_blocks_custom_css( $custom_block_css, $selector );
@ -1284,7 +1288,7 @@ class WP_Theme_JSON {
}
$selector = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
$has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
$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.
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$layout_definitions = wp_get_layout_definitions();
@ -1300,7 +1304,9 @@ class WP_Theme_JSON {
if ( ! $has_block_gap_support ) {
$block_gap_value = static::ROOT_BLOCK_SELECTOR === $selector ? '0.5em' : null;
if ( ! empty( $block_type ) ) {
$block_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), null );
$block_gap_value = isset( $block_type->supports['spacing']['blockGap']['__experimentalDefault'] )
? $block_type->supports['spacing']['blockGap']['__experimentalDefault']
: null;
}
} else {
$block_gap_value = static::get_property_value( $node, array( 'spacing', 'blockGap' ) );
@ -1326,8 +1332,8 @@ class WP_Theme_JSON {
continue;
}
$class_name = _wp_array_get( $layout_definition, array( 'className' ), false );
$spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() );
$class_name = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
$spacing_rules = isset( $layout_definition['spacingStyles'] ) ? $layout_definition['spacingStyles'] : array();
if (
! empty( $class_name ) &&
@ -1383,8 +1389,8 @@ class WP_Theme_JSON {
) {
$valid_display_modes = array( 'block', 'flex', 'grid' );
foreach ( $layout_definitions as $layout_definition ) {
$class_name = _wp_array_get( $layout_definition, array( 'className' ), false );
$base_style_rules = _wp_array_get( $layout_definition, array( 'baseStyles' ), array() );
$class_name = isset( $layout_definition['className'] ) ? $layout_definition['className'] : false;
$base_style_rules = isset( $layout_definition['baseStyles'] ) ? $layout_definition['baseStyles'] : array();
if (
! empty( $class_name ) &&
@ -1812,7 +1818,7 @@ class WP_Theme_JSON {
*/
protected static function compute_theme_vars( $settings ) {
$declarations = array();
$custom_values = _wp_array_get( $settings, array( 'custom' ), array() );
$custom_values = isset( $settings['custom'] ) ? $settings['custom'] : array();
$css_vars = static::flatten_tree( $custom_values );
foreach ( $css_vars as $key => $value ) {
$declarations[] = array(
@ -2326,7 +2332,7 @@ class WP_Theme_JSON {
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
$use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
$selector = $block_metadata['selector'];
$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
$feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node );
// If there are style variations, generate the declarations for them, including any feature selectors the block may have.
@ -2466,7 +2472,7 @@ class WP_Theme_JSON {
*/
public function get_root_layout_rules( $selector, $block_metadata ) {
$css = '';
$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] ) ? $this->theme_json['settings'] : array();
$use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments'];
/*
@ -2515,8 +2521,8 @@ class WP_Theme_JSON {
$css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
$block_gap_value = _wp_array_get( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ), '0.5em' );
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
$block_gap_value = isset( $this->theme_json['styles']['spacing']['blockGap'] ) ? $this->theme_json['styles']['spacing']['blockGap'] : '0.5em';
$has_block_gap_support = isset( $this->theme_json['settings']['spacing']['blockGap'] );
if ( $has_block_gap_support ) {
$block_gap_value = static::get_property_value( $this->theme_json, array( 'styles', 'spacing', 'blockGap' ) );
$css .= ":where(.wp-site-blocks) > * { margin-block-start: $block_gap_value; margin-block-end: 0; }";
@ -3355,7 +3361,9 @@ class WP_Theme_JSON {
* @return null|void
*/
public function set_spacing_sizes() {
$spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() );
$spacing_scale = isset( $this->theme_json['settings']['spacing']['spacingScale'] )
? $this->theme_json['settings']['spacing']['spacingScale']
: array();
if ( ! isset( $spacing_scale['steps'] )
|| ! is_numeric( $spacing_scale['steps'] )
@ -3594,7 +3602,9 @@ class WP_Theme_JSON {
return $declarations;
}
$settings = _wp_array_get( $this->theme_json, array( 'settings' ) );
$settings = isset( $this->theme_json['settings'] )
? $this->theme_json['settings']
: array();
foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
/*

View File

@ -4253,7 +4253,9 @@ function wp_render_duotone_filter_preset( $preset ) {
function wp_skip_border_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false );
$border_support = isset( $block_type->supports['__experimentalBorder'] )
? $block_type->supports['__experimentalBorder']
: false;
return is_array( $border_support ) &&
array_key_exists( '__experimentalSkipSerialization', $border_support ) &&
@ -4275,7 +4277,9 @@ function wp_skip_border_serialization( $block_type ) {
function wp_skip_dimensions_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$dimensions_support = _wp_array_get( $block_type->supports, array( '__experimentalDimensions' ), false );
$dimensions_support = isset( $block_type->supports['__experimentalDimensions'] )
? $block_type->supports['__experimentalDimensions']
: false;
return is_array( $dimensions_support ) &&
array_key_exists( '__experimentalSkipSerialization', $dimensions_support ) &&
@ -4297,7 +4301,9 @@ function wp_skip_dimensions_serialization( $block_type ) {
function wp_skip_spacing_serialization( $block_type ) {
_deprecated_function( __FUNCTION__, '6.0.0', 'wp_should_skip_block_supports_serialization()' );
$spacing_support = _wp_array_get( $block_type->supports, array( 'spacing' ), false );
$spacing_support = isset( $block_type->supports['spacing'] )
? $block_type->supports['spacing']
: false;
return is_array( $spacing_support ) &&
array_key_exists( '__experimentalSkipSerialization', $spacing_support ) &&

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.4-alpha-56708';
$wp_version = '6.4-alpha-56709';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.