diff --git a/lib/block-supports/background.php b/lib/block-supports/background.php index 08a9c012a3145..a32ee72fd90c6 100644 --- a/lib/block-supports/background.php +++ b/lib/block-supports/background.php @@ -51,9 +51,9 @@ function gutenberg_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 = $block_attributes['style']['background']['backgroundImage']['source'] ?? null; + $background_image_url = $block_attributes['style']['background']['backgroundImage']['url'] ?? null; + $background_size = $block_attributes['style']['background']['backgroundSize'] ?? 'cover'; $background_block_styles = array(); diff --git a/lib/block-supports/border.php b/lib/block-supports/border.php index 51e484c43af42..1a54371d082e1 100644 --- a/lib/block-supports/border.php +++ b/lib/block-supports/border.php @@ -94,14 +94,14 @@ function gutenberg_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 = $block_attributes['style']['border']['color'] ?? null; $border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color; } // Generate 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 = $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, @@ -142,11 +142,11 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) { */ function gutenberg_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 = $block_type->supports['__experimentalBorder'] ?? $default_value; + if ( true === $block_type_supports_border ) { + return true; + } } // Check if the specific feature has been opted into individually diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index 88e13abfc9cc9..6919f58c067e4 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -11,13 +11,20 @@ * @param WP_Block_Type $block_type Block Type. */ function gutenberg_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 = $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 = $color_support['gradients'] ?? false; + $has_link_colors_support = $color_support['link'] ?? false; + $has_button_colors_support = $color_support['button'] ?? false; + $has_heading_colors_support = $color_support['heading'] ?? false; $has_color_support = $has_text_colors_support || $has_background_colors_support || $has_gradients_support || @@ -65,7 +72,7 @@ function gutenberg_register_colors_support( $block_type ) { * @return array Colors CSS classes and inline styles. */ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { - $color_support = _wp_array_get( $block_type->supports, array( 'color' ), false ); + $color_support = $block_type->supports['color'] ?? false; if ( is_array( $color_support ) && @@ -74,23 +81,27 @@ function gutenberg_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 = $color_support['gradients'] ?? false; $color_block_styles = array(); // Text colors. // Check support for 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 = $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 = $block_attributes['style']['color']['background'] ?? null; $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; } @@ -98,7 +109,7 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { 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 = $block_attributes['style']['color']['gradient'] ?? null; $color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color; } diff --git a/lib/block-supports/dimensions.php b/lib/block-supports/dimensions.php index d4d15cd609e63..1ef43133c2cdf 100644 --- a/lib/block-supports/dimensions.php +++ b/lib/block-supports/dimensions.php @@ -61,8 +61,11 @@ function gutenberg_apply_dimensions_support( $block_type, $block_attributes ) { $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 = gutenberg_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'] = $block_styles['dimensions']['minHeight'] ?? null; + } + $styles = gutenberg_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) ); if ( ! empty( $styles['css'] ) ) { $attributes['style'] = $styles['css']; diff --git a/lib/block-supports/layout.php b/lib/block-supports/layout.php index 3acef1f7df4d4..0fe217cf83270 100644 --- a/lib/block-supports/layout.php +++ b/lib/block-supports/layout.php @@ -222,7 +222,7 @@ function gutenberg_register_layout_support( $block_type ) { * @return string CSS styles on success. Else, empty string. */ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em', $block_spacing = null ) { - $layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default'; + $layout_type = $layout['type'] ?? 'default'; $layout_styles = array(); if ( 'default' === $layout_type ) { @@ -401,7 +401,10 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support $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 = $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; @@ -482,7 +485,10 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support $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 = $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; @@ -594,8 +600,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) { } $global_settings = gutenberg_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 = $block_type->supports['layout']['default'] ?? array(); + if ( empty( $fallback_layout ) ) { + $fallback_layout = $block_type->supports['__experimentalLayout']['default'] ?? array(); + } + $used_layout = $block['attrs']['layout'] ?? $fallback_layout; $class_names = array(); $layout_definitions = gutenberg_get_layout_definitions(); @@ -606,7 +615,7 @@ function gutenberg_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 = $global_settings['useRootPaddingAwareAlignments'] ?? false; if ( $root_padding_aware_alignments && isset( $used_layout['type'] ) && 'constrained' === $used_layout['type'] ) { $class_names[] = 'has-global-padding'; @@ -632,9 +641,9 @@ function gutenberg_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 = $layout_definitions[ $used_layout['type'] ]['className'] ?? ''; } else { - $layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' ); + $layout_classname = $layout_definitions['default']['className'] ?? ''; } if ( $layout_classname && is_string( $layout_classname ) ) { @@ -647,7 +656,7 @@ function gutenberg_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 = $block['attrs']['style']['spacing']['blockGap'] ?? null; /* * Skip if gap value contains unsupported characters. @@ -662,8 +671,8 @@ function gutenberg_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 = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? '0.5em'; + $block_spacing = $block['attrs']['style']['spacing'] ?? null; /* * If a block's block.json skips serialization for spacing or spacing.blockGap, @@ -671,7 +680,7 @@ function gutenberg_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 = $global_settings['spacing']['blockGap'] ?? null; $has_block_gap_support = isset( $block_gap ); $style = gutenberg_get_layout_style( diff --git a/lib/block-supports/position.php b/lib/block-supports/position.php index 62a51c486362e..930e726d12321 100644 --- a/lib/block-supports/position.php +++ b/lib/block-supports/position.php @@ -44,8 +44,8 @@ function gutenberg_render_position_support( $block_content, $block ) { } $global_settings = gutenberg_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 = $global_settings['position']['sticky'] ?? false; + $theme_has_fixed_support = $global_settings['position']['fixed'] ?? false; // Only allow output for position types that the theme supports. $allowed_position_types = array(); @@ -56,11 +56,11 @@ function gutenberg_render_position_support( $block_content, $block ) { $allowed_position_types[] = 'fixed'; } - $style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null ); + $style_attribute = $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 = $style_attribute['position']['type'] ?? ''; $wrapper_classes = array(); if ( @@ -71,7 +71,7 @@ function gutenberg_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 = $style_attribute['position'][ $side ] ?? null; if ( null !== $side_value ) { /* * For fixed or sticky top positions, diff --git a/lib/block-supports/settings.php b/lib/block-supports/settings.php index aac4774b62fe8..b175fe778ce1b 100644 --- a/lib/block-supports/settings.php +++ b/lib/block-supports/settings.php @@ -26,7 +26,7 @@ function _gutenberg_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 = $block['attrs']['settings'] ?? null; if ( empty( $block_settings ) ) { return $block_content; } @@ -59,7 +59,7 @@ function _gutenberg_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 = $block['attrs']['settings'] ?? null; if ( empty( $block_settings ) ) { return null; } diff --git a/lib/block-supports/spacing.php b/lib/block-supports/spacing.php index e78fac6d62419..86e6c750185a5 100644 --- a/lib/block-supports/spacing.php +++ b/lib/block-supports/spacing.php @@ -52,12 +52,19 @@ function gutenberg_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 = gutenberg_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'] = $block_styles['spacing']['padding'] ?? null; + } + if ( $has_margin_support && ! $skip_margin ) { + $spacing_block_styles['margin'] = $block_styles['spacing']['margin'] ?? null; + } + $styles = gutenberg_style_engine_get_styles( array( 'spacing' => $spacing_block_styles ) ); if ( ! empty( $styles['css'] ) ) { $attributes['style'] = $styles['css']; diff --git a/lib/block-supports/typography.php b/lib/block-supports/typography.php index 1e8c894387de6..5c051ee05cc2c 100644 --- a/lib/block-supports/typography.php +++ b/lib/block-supports/typography.php @@ -15,21 +15,21 @@ function gutenberg_register_typography_support( $block_type ) { return; } - $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false ); + $typography_supports = $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 = $typography_supports['__experimentalFontFamily'] ?? false; + $has_font_size_support = $typography_supports['fontSize'] ?? false; + $has_font_style_support = $typography_supports['__experimentalFontStyle'] ?? false; + $has_font_weight_support = $typography_supports['__experimentalFontWeight'] ?? false; + $has_letter_spacing_support = $typography_supports['__experimentalLetterSpacing'] ?? false; + $has_line_height_support = $typography_supports['lineHeight'] ?? false; + $has_text_columns_support = $typography_supports['textColumns'] ?? false; + $has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false; + $has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false; + $has_writing_mode_support = $typography_supports['__experimentalWritingMode'] ?? false; $has_typography_support = $has_font_family_support || $has_font_size_support @@ -80,7 +80,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) { return array(); } - $typography_supports = _wp_array_get( $block_type->supports, array( 'typography' ), false ); + $typography_supports = $block_type->supports['typography'] ?? false; if ( ! $typography_supports ) { return array(); } @@ -89,16 +89,16 @@ function gutenberg_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 = $typography_supports['__experimentalFontFamily'] ?? false; + $has_font_size_support = $typography_supports['fontSize'] ?? false; + $has_font_style_support = $typography_supports['__experimentalFontStyle'] ?? false; + $has_font_weight_support = $typography_supports['__experimentalFontWeight'] ?? false; + $has_letter_spacing_support = $typography_supports['__experimentalLetterSpacing'] ?? false; + $has_line_height_support = $typography_supports['lineHeight'] ?? false; + $has_text_columns_support = $typography_supports['textColumns'] ?? false; + $has_text_decoration_support = $typography_supports['__experimentalTextDecoration'] ?? false; + $has_text_transform_support = $typography_supports['__experimentalTextTransform'] ?? false; + $has_writing_mode_support = $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' ); @@ -140,11 +140,11 @@ function gutenberg_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' ), null ); + $typography_block_styles['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'] = $block_attributes['style']['typography']['textColumns'] ?? null; } if ( $has_text_decoration_support && ! $should_skip_text_decoration && isset( $block_attributes['style']['typography']['textDecoration'] ) ) { @@ -163,7 +163,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) { } if ( $has_writing_mode_support && ! $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'] = $block_attributes['style']['typography']['writingMode'] ?? null; } $attributes = array(); diff --git a/lib/class-wp-duotone-gutenberg.php b/lib/class-wp-duotone-gutenberg.php index 5c4b4a3cc9d9c..270c13875787f 100644 --- a/lib/class-wp-duotone-gutenberg.php +++ b/lib/class-wp-duotone-gutenberg.php @@ -655,14 +655,14 @@ private static function get_selector( $block_name ) { // `supports.filter.duotone` has not been set and the experimental // property has been, the experimental property value is copied into // `supports.filter.duotone`. - $duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), false ); + $duotone_support = $block_type->supports['filter']['duotone'] ?? false; if ( ! $duotone_support ) { return null; } // 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 = $block_type->supports['color']['__experimentalDuotone'] ?? false; if ( $experimental_duotone ) { $root_selector = wp_get_block_css_selector( $block_type ); return is_string( $experimental_duotone ) @@ -750,7 +750,7 @@ public static function register_duotone_support( $block_type ) { if ( property_exists( $block_type, 'supports' ) ) { // Previous `color.__experimentalDuotone` support flag is migrated // to `filter.duotone` via `block_type_metadata_settings` filter. - $has_duotone_support = _wp_array_get( $block_type->supports, array( 'filter', 'duotone' ), null ); + $has_duotone_support = $block_type->supports['filter']['duotone'] ?? null; } if ( $has_duotone_support ) { @@ -775,7 +775,7 @@ public static function register_duotone_support( $block_type ) { public static function set_global_styles_presets() { // Get the per block settings from the theme.json. $tree = gutenberg_get_global_settings(); - $presets_by_origin = _wp_array_get( $tree, array( 'color', 'duotone' ), array() ); + $presets_by_origin = $tree['color']['duotone'] ?? array(); foreach ( $presets_by_origin as $presets ) { foreach ( $presets as $preset ) { @@ -995,7 +995,7 @@ public static function add_editor_settings( $settings ) { * @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 = $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 ); diff --git a/lib/class-wp-theme-json-gutenberg.php b/lib/class-wp-theme-json-gutenberg.php index 64b29497bef72..59a3bbc3eb2ef 100644 --- a/lib/class-wp-theme-json-gutenberg.php +++ b/lib/class-wp-theme-json-gutenberg.php @@ -928,7 +928,7 @@ protected static function get_blocks_metadata() { // 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 = $block_type->supports['color']['__experimentalDuotone'] ?? null; if ( $duotone_support ) { $root_selector = wp_get_block_css_selector( $block_type ); @@ -1161,12 +1161,12 @@ protected function process_blocks_custom_css( $css, $selector ) { */ public function get_custom_css() { // Add the global styles root CSS. - $stylesheet = _wp_array_get( $this->theme_json, array( 'styles', 'css' ), '' ); + $stylesheet = $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 = $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 +1284,7 @@ protected function get_layout_styles( $block_metadata ) { } $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 = gutenberg_get_layout_definitions(); @@ -1298,7 +1298,7 @@ protected function get_layout_styles( $block_metadata ) { 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 = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? null; } } else { $block_gap_value = static::get_property_value( $node, array( 'spacing', 'blockGap' ) ); @@ -1324,8 +1324,8 @@ protected function get_layout_styles( $block_metadata ) { continue; } - $class_name = _wp_array_get( $layout_definition, array( 'className' ), false ); - $spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() ); + $class_name = $layout_definition['className'] ?? false; + $spacing_rules = $layout_definition['spacingStyles'] ?? array(); if ( ! empty( $class_name ) && @@ -1381,8 +1381,8 @@ protected function get_layout_styles( $block_metadata ) { ) { $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 = $layout_definition['className'] ?? false; + $base_style_rules = $layout_definition['baseStyles'] ?? array(); if ( ! empty( $class_name ) && @@ -1814,7 +1814,7 @@ protected static function compute_preset_vars( $settings, $origins ) { */ protected static function compute_theme_vars( $settings ) { $declarations = array(); - $custom_values = _wp_array_get( $settings, array( 'custom' ), array() ); + $custom_values = $settings['custom'] ?? array(); $css_vars = static::flatten_tree( $custom_values ); foreach ( $css_vars as $key => $value ) { $declarations[] = array( @@ -2326,7 +2326,7 @@ public function get_styles_for_block( $block_metadata ) { $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 = $this->theme_json['settings'] ?? null; $feature_declarations = static::get_feature_declarations_for_node( $block_metadata, $node ); @@ -2479,7 +2479,7 @@ static function ( $pseudo_selector ) use ( $selector ) { */ public function get_root_layout_rules( $selector, $block_metadata ) { $css = ''; - $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); + $settings = $this->theme_json['settings'] ?? array(); $use_root_padding = isset( $this->theme_json['settings']['useRootPaddingAwareAlignments'] ) && true === $this->theme_json['settings']['useRootPaddingAwareAlignments']; /* @@ -2528,8 +2528,8 @@ public function get_root_layout_rules( $selector, $block_metadata ) { $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 = $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; }"; @@ -3360,7 +3360,7 @@ public function get_data() { * @return null|void */ public function set_spacing_sizes() { - $spacing_scale = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'spacingScale' ), array() ); + $spacing_scale = $this->theme_json['settings']['spacing']['spacingScale'] ?? array(); // Gutenberg didn't have the 1st isset check. if ( ! isset( $spacing_scale['steps'] ) @@ -3546,7 +3546,7 @@ protected function get_feature_declarations_for_node( $metadata, &$node ) { return $declarations; } - $settings = _wp_array_get( $this->theme_json, array( 'settings' ) ); + $settings = $this->theme_json['settings'] ?? null; foreach ( $metadata['selectors'] as $feature => $feature_selectors ) { // Skip if this is the block's root selector or the block doesn't diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 363c25f63761c..950d9e00e6243 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -383,7 +383,7 @@ public static function get_block_data() { 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. // The real blockGap value to be used will be determined when the styles are rendered for output. diff --git a/lib/experimental/blocks.php b/lib/experimental/blocks.php index e509c889a9ef8..2102834dc6a15 100644 --- a/lib/experimental/blocks.php +++ b/lib/experimental/blocks.php @@ -141,7 +141,7 @@ function gutenberg_render_block_connections( $block_content, $block, $block_inst } // Get all the attributes that have a connection. - $connected_attributes = _wp_array_get( $block['attrs'], array( 'connections', 'attributes' ), false ); + $connected_attributes = $block['attrs']['connections']['attributes'] ?? false; if ( ! $connected_attributes ) { return $block_content; } diff --git a/packages/block-library/src/avatar/index.php b/packages/block-library/src/avatar/index.php index 1566fe6edfebc..d404fb81ca357 100644 --- a/packages/block-library/src/avatar/index.php +++ b/packages/block-library/src/avatar/index.php @@ -112,12 +112,12 @@ function get_block_core_avatar_border_attributes( $attributes ) { // Border color. $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; - $custom_color = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null ); + $custom_color = $attributes['style']['border']['color'] ?? null; $border_styles['color'] = $preset_color ? $preset_color : $custom_color; // Individual border styles e.g. top, left etc. foreach ( $sides as $side ) { - $border = _wp_array_get( $attributes, array( 'style', 'border', $side ), null ); + $border = $attributes['style']['border'][ $side ] ?? null; $border_styles[ $side ] = array( 'color' => isset( $border['color'] ) ? $border['color'] : null, 'style' => isset( $border['style'] ) ? $border['style'] : null, diff --git a/packages/block-library/src/calendar/index.php b/packages/block-library/src/calendar/index.php index 07a5e9d032cf7..f1f7967235620 100644 --- a/packages/block-library/src/calendar/index.php +++ b/packages/block-library/src/calendar/index.php @@ -44,12 +44,12 @@ function render_block_core_calendar( $attributes ) { // Text color. $preset_text_color = array_key_exists( 'textColor', $attributes ) ? "var:preset|color|{$attributes['textColor']}" : null; - $custom_text_color = _wp_array_get( $attributes, array( 'style', 'color', 'text' ), null ); + $custom_text_color = $attributes['style']['color']['text'] ?? null; $color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color; // Background Color. $preset_background_color = array_key_exists( 'backgroundColor', $attributes ) ? "var:preset|color|{$attributes['backgroundColor']}" : null; - $custom_background_color = _wp_array_get( $attributes, array( 'style', 'color', 'background' ), null ); + $custom_background_color = $attributes['style']['color']['background'] ?? null; $color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color; // Generate color styles and classes. diff --git a/packages/block-library/src/gallery/index.php b/packages/block-library/src/gallery/index.php index 86c86acfff927..edde9b4da101a 100644 --- a/packages/block-library/src/gallery/index.php +++ b/packages/block-library/src/gallery/index.php @@ -44,7 +44,7 @@ function block_core_gallery_data_id_backcompatibility( $parsed_block ) { * @return string The content of the block being rendered. */ function block_core_gallery_render( $attributes, $content ) { - $gap = _wp_array_get( $attributes, array( 'style', 'spacing', 'blockGap' ) ); + $gap = $attributes['style']['spacing']['blockGap'] ?? null; // Skip if gap value contains unsupported characters. // Regex for CSS value borrowed from `safecss_filter_attr`, and used here // because we only want to match against the value, not the CSS attribute. diff --git a/packages/block-library/src/navigation/index.php b/packages/block-library/src/navigation/index.php index 7d2a8888afde1..3de146739b059 100644 --- a/packages/block-library/src/navigation/index.php +++ b/packages/block-library/src/navigation/index.php @@ -529,7 +529,7 @@ function render_block_core_navigation( $attributes, $content, $block ) { } // Manually add block support text decoration as CSS class. - $text_decoration = _wp_array_get( $attributes, array( 'style', 'typography', 'textDecoration' ), null ); + $text_decoration = $attributes['style']['typography']['textDecoration'] ?? null; $text_decoration_class = sprintf( 'has-text-decoration-%s', $text_decoration ); $colors = block_core_navigation_build_css_colors( $attributes ); diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php index 67c889b0befa5..4a7aa2f3d8ab9 100644 --- a/packages/block-library/src/post-featured-image/index.php +++ b/packages/block-library/src/post-featured-image/index.php @@ -184,12 +184,12 @@ function get_block_core_post_featured_image_border_attributes( $attributes ) { // Border color. $preset_color = array_key_exists( 'borderColor', $attributes ) ? "var:preset|color|{$attributes['borderColor']}" : null; - $custom_color = _wp_array_get( $attributes, array( 'style', 'border', 'color' ), null ); + $custom_color = $attributes['style']['border']['color'] ?? null; $border_styles['color'] = $preset_color ? $preset_color : $custom_color; // Individual border styles e.g. top, left etc. foreach ( $sides as $side ) { - $border = _wp_array_get( $attributes, array( 'style', 'border', $side ), null ); + $border = $attributes['style']['border'][ $side ] ?? null; $border_styles[ $side ] = array( 'color' => isset( $border['color'] ) ? $border['color'] : null, 'style' => isset( $border['style'] ) ? $border['style'] : null, diff --git a/packages/block-library/src/search/index.php b/packages/block-library/src/search/index.php index 779130d6c21fb..2b69d469c157b 100644 --- a/packages/block-library/src/search/index.php +++ b/packages/block-library/src/search/index.php @@ -266,7 +266,7 @@ function classnames_for_block_core_search( $attributes ) { * @return void */ function apply_block_core_search_border_style( $attributes, $property, $side, &$wrapper_styles, &$button_styles, &$input_styles ) { - $is_button_inside = 'button-inside' === _wp_array_get( $attributes, array( 'buttonPosition' ), false ); + $is_button_inside = isset( $attributes['buttonPosition'] ) && 'button-inside' === $attributes['buttonPosition']; $path = array( 'style', 'border', $property ); diff --git a/packages/style-engine/docs/using-the-style-engine-with-block-supports.md b/packages/style-engine/docs/using-the-style-engine-with-block-supports.md index 3587a89388ed0..07d91c54a28d6 100644 --- a/packages/style-engine/docs/using-the-style-engine-with-block-supports.md +++ b/packages/style-engine/docs/using-the-style-engine-with-block-supports.md @@ -133,8 +133,14 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) { $color_block_styles = array(); // Set the color style values according to whether the block has support and does not skip serialization. - $spacing_block_styles['text'] = $has_text_support && ! $skips_serialization_of_color_text ? _wp_array_get( $block_color_styles, array( 'text' ), null ) : null; - $spacing_block_styles['background'] = $has_background_support && ! $skips_serialization_of_color_background ? _wp_array_get( $block_color_styles, array( 'background' ), null ) : null; + $spacing_block_styles['text'] = null; + $spacing_block_styles['background'] = null; + if ( $has_text_support && ! $skips_serialization_of_color_text ) { + $spacing_block_styles['text'] = $block_color_styles['text'] ?? null; + } + if $has_background_support && ! $skips_serialization_of_color_background ) { + $spacing_block_styles['background'] = $block_color_styles['background'] ?? null; + } // Pass the color styles, excluding those that have no support or skip serialization, to the Style Engine. $styles = wp_style_engine_get_styles( array( 'color' => $block_color_styles ) );