Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 4 additions & 24 deletions lib/block-editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,30 +75,15 @@ function gutenberg_get_block_editor_settings( $settings ) {
// These settings may need to be updated based on data coming from theme.json sources.
if ( isset( $settings['__experimentalFeatures']['color']['palette'] ) ) {
$colors_by_origin = $settings['__experimentalFeatures']['color']['palette'];
$settings['colors'] = isset( $colors_by_origin['custom'] ) ?
$colors_by_origin['custom'] : (
isset( $colors_by_origin['theme'] ) ?
$colors_by_origin['theme'] :
$colors_by_origin['default']
);
$settings['colors'] = $colors_by_origin['custom'] ?? $colors_by_origin['theme'] ?? $colors_by_origin['default'];
Copy link
Member Author

@westonruter westonruter Jan 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow. This change makes the code so much easier to read!

}
if ( isset( $settings['__experimentalFeatures']['color']['gradients'] ) ) {
$gradients_by_origin = $settings['__experimentalFeatures']['color']['gradients'];
$settings['gradients'] = isset( $gradients_by_origin['custom'] ) ?
$gradients_by_origin['custom'] : (
isset( $gradients_by_origin['theme'] ) ?
$gradients_by_origin['theme'] :
$gradients_by_origin['default']
);
$settings['gradients'] = $gradients_by_origin['custom'] ?? $gradients_by_origin['theme'] ?? $gradients_by_origin['default'];
}
if ( isset( $settings['__experimentalFeatures']['typography']['fontSizes'] ) ) {
$font_sizes_by_origin = $settings['__experimentalFeatures']['typography']['fontSizes'];
$settings['fontSizes'] = isset( $font_sizes_by_origin['custom'] ) ?
$font_sizes_by_origin['custom'] : (
isset( $font_sizes_by_origin['theme'] ) ?
$font_sizes_by_origin['theme'] :
$font_sizes_by_origin['default']
);
$settings['fontSizes'] = $font_sizes_by_origin['custom'] ?? $font_sizes_by_origin['theme'] ?? $font_sizes_by_origin['default'];
}
if ( isset( $settings['__experimentalFeatures']['color']['custom'] ) ) {
$settings['disableCustomColors'] = ! $settings['__experimentalFeatures']['color']['custom'];
Expand Down Expand Up @@ -131,12 +116,7 @@ function gutenberg_get_block_editor_settings( $settings ) {

if ( isset( $settings['__experimentalFeatures']['spacing']['spacingSizes'] ) ) {
$spacing_sizes_by_origin = $settings['__experimentalFeatures']['spacing']['spacingSizes'];
$settings['spacingSizes'] = isset( $spacing_sizes_by_origin['custom'] ) ?
$spacing_sizes_by_origin['custom'] : (
isset( $spacing_sizes_by_origin['theme'] ) ?
$spacing_sizes_by_origin['theme'] :
$spacing_sizes_by_origin['default']
);
$settings['spacingSizes'] = $spacing_sizes_by_origin['custom'] ?? $spacing_sizes_by_origin['theme'] ?? $spacing_sizes_by_origin['default'];
}

return $settings;
Expand Down
28 changes: 14 additions & 14 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
if ( 'default' === $layout_type ) {
if ( $has_block_gap_support ) {
if ( is_array( $gap_value ) ) {
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
$gap_value = $gap_value['top'] ?? null;
}
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
// Get spacing CSS variable from preset value if provided.
Expand Down Expand Up @@ -258,9 +258,9 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
}
}
} elseif ( 'constrained' === $layout_type ) {
$content_size = isset( $layout['contentSize'] ) ? $layout['contentSize'] : '';
$wide_size = isset( $layout['wideSize'] ) ? $layout['wideSize'] : '';
$justify_content = isset( $layout['justifyContent'] ) ? $layout['justifyContent'] : 'center';
$content_size = $layout['contentSize'] ?? '';
$wide_size = $layout['wideSize'] ?? '';
$justify_content = $layout['justifyContent'] ?? 'center';

$all_max_width_value = $content_size ? $content_size : $wide_size;
$wide_max_width_value = $wide_size ? $wide_size : $content_size;
Expand Down Expand Up @@ -345,7 +345,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support

if ( $has_block_gap_support ) {
if ( is_array( $gap_value ) ) {
$gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
$gap_value = $gap_value['top'] ?? null;
}
if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
// Get spacing CSS variable from preset value if provided.
Expand Down Expand Up @@ -375,7 +375,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
}
}
} elseif ( 'flex' === $layout_type ) {
$layout_orientation = isset( $layout['orientation'] ) ? $layout['orientation'] : 'horizontal';
$layout_orientation = $layout['orientation'] ?? 'horizontal';

$justify_content_options = array(
'left' => 'flex-start',
Expand Down Expand Up @@ -651,7 +651,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$child_layout_declarations = array();
$child_layout_styles = array();

$self_stretch = isset( $block['attrs']['style']['layout']['selfStretch'] ) ? $block['attrs']['style']['layout']['selfStretch'] : null;
$self_stretch = $block['attrs']['style']['layout']['selfStretch'] ?? null;

if ( 'fixed' === $self_stretch && isset( $block['attrs']['style']['layout']['flexSize'] ) ) {
$child_layout_declarations['flex-basis'] = $block['attrs']['style']['layout']['flexSize'];
Expand All @@ -660,8 +660,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$child_layout_declarations['flex-grow'] = '1';
}

$column_start = isset( $block['attrs']['style']['layout']['columnStart'] ) ? $block['attrs']['style']['layout']['columnStart'] : null;
$column_span = isset( $block['attrs']['style']['layout']['columnSpan'] ) ? $block['attrs']['style']['layout']['columnSpan'] : null;
$column_start = $block['attrs']['style']['layout']['columnStart'] ?? null;
$column_span = $block['attrs']['style']['layout']['columnSpan'] ?? null;
if ( $column_start && $column_span ) {
$child_layout_declarations['grid-column'] = "$column_start / span $column_span";
} elseif ( $column_start ) {
Expand All @@ -670,8 +670,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$child_layout_declarations['grid-column'] = "span $column_span";
}

$row_start = isset( $block['attrs']['style']['layout']['rowStart'] ) ? $block['attrs']['style']['layout']['rowStart'] : null;
$row_span = isset( $block['attrs']['style']['layout']['rowSpan'] ) ? $block['attrs']['style']['layout']['rowSpan'] : null;
$row_start = $block['attrs']['style']['layout']['rowStart'] ?? null;
$row_span = $block['attrs']['style']['layout']['rowSpan'] ?? null;
if ( $row_start && $row_span ) {
$child_layout_declarations['grid-row'] = "$row_start / span $row_span";
} elseif ( $row_start ) {
Expand All @@ -685,8 +685,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
'declarations' => $child_layout_declarations,
);

$minimum_column_width = isset( $block['parentLayout']['minimumColumnWidth'] ) ? $block['parentLayout']['minimumColumnWidth'] : null;
$column_count = isset( $block['parentLayout']['columnCount'] ) ? $block['parentLayout']['columnCount'] : null;
$minimum_column_width = $block['parentLayout']['minimumColumnWidth'] ?? null;
$column_count = $block['parentLayout']['columnCount'] ?? null;

/*
* If columnSpan or columnStart is set, and the parent grid is responsive, i.e. if it has a minimumColumnWidth set,
Expand Down Expand Up @@ -1051,7 +1051,7 @@ function ( $parsed_block, $source_block, $parent_block ) {
* @return string Filtered block content.
*/
function gutenberg_restore_group_inner_container( $block_content, $block ) {
$tag_name = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : 'div';
$tag_name = $block['attrs']['tagName'] ?? 'div';
$group_with_inner_container_regex = sprintf(
'/(^\s*<%1$s\b[^>]*wp-block-group(\s|")[^>]*>)(\s*<div\b[^>]*wp-block-group__inner-container(\s|")[^>]*>)((.|\S|\s)*)/U',
preg_quote( $tag_name, '/' )
Expand Down
2 changes: 1 addition & 1 deletion lib/block-supports/spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function gutenberg_apply_spacing_support( $block_type, $block_attributes ) {
$attributes = array();
$has_padding_support = block_has_support( $block_type, array( 'spacing', 'padding' ), false );
$has_margin_support = block_has_support( $block_type, array( 'spacing', 'margin' ), false );
$block_styles = isset( $block_attributes['style'] ) ? $block_attributes['style'] : null;
$block_styles = $block_attributes['style'] ?? null;

if ( ! $block_styles ) {
return $attributes;
Expand Down
24 changes: 12 additions & 12 deletions lib/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function gutenberg_apply_typography_support( $block_type, $block_attributes ) {
$typography_block_styles = array();
if ( $has_font_size_support && ! $should_skip_font_size ) {
$preset_font_size = array_key_exists( 'fontSize', $block_attributes ) ? "var:preset|font-size|{$block_attributes['fontSize']}" : null;
$custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] ) ? $block_attributes['style']['typography']['fontSize'] : null;
$custom_font_size = $block_attributes['style']['typography']['fontSize'] ?? null;
$typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : gutenberg_get_typography_font_size_value(
array(
'size' => $custom_font_size,
Expand Down Expand Up @@ -382,11 +382,11 @@ function gutenberg_get_typography_value_and_unit( $raw_value, $options = array()
* @return string|null A font-size value using clamp().
*/
function gutenberg_get_computed_fluid_typography_value( $args = array() ) {
$maximum_viewport_width_raw = isset( $args['maximum_viewport_width'] ) ? $args['maximum_viewport_width'] : null;
$minimum_viewport_width_raw = isset( $args['minimum_viewport_width'] ) ? $args['minimum_viewport_width'] : null;
$maximum_font_size_raw = isset( $args['maximum_font_size'] ) ? $args['maximum_font_size'] : null;
$minimum_font_size_raw = isset( $args['minimum_font_size'] ) ? $args['minimum_font_size'] : null;
$scale_factor = isset( $args['scale_factor'] ) ? $args['scale_factor'] : null;
$maximum_viewport_width_raw = $args['maximum_viewport_width'] ?? null;
$minimum_viewport_width_raw = $args['minimum_viewport_width'] ?? null;
$maximum_font_size_raw = $args['maximum_font_size'] ?? null;
$minimum_font_size_raw = $args['minimum_font_size'] ?? null;
$scale_factor = $args['scale_factor'] ?? null;

// Normalizes the minimum font size in order to use the value for calculations.
$minimum_font_size = gutenberg_get_typography_value_and_unit( $minimum_font_size_raw );
Expand All @@ -395,7 +395,7 @@ function gutenberg_get_computed_fluid_typography_value( $args = array() ) {
* We get a 'preferred' unit to keep units consistent when calculating,
* otherwise the result will not be accurate.
*/
$font_size_unit = isset( $minimum_font_size['unit'] ) ? $minimum_font_size['unit'] : 'rem';
$font_size_unit = $minimum_font_size['unit'] ?? 'rem';

// Grabs the maximum font size and normalize it in order to use the value for calculations.
$maximum_font_size = gutenberg_get_typography_value_and_unit(
Expand Down Expand Up @@ -529,8 +529,8 @@ function gutenberg_get_typography_font_size_value( $preset, $settings = array()
return $preset['size'];
}

$fluid_settings = isset( $typography_settings['fluid'] ) ? $typography_settings['fluid'] : array();
$layout_settings = isset( $settings['layout'] ) ? $settings['layout'] : array();
$fluid_settings = $typography_settings['fluid'] ?? array();
$layout_settings = $settings['layout'] ?? array();

// Defaults.
$default_maximum_viewport_width = '1600px';
Expand All @@ -541,7 +541,7 @@ function gutenberg_get_typography_font_size_value( $preset, $settings = array()
$default_minimum_font_size_limit = '14px';

// Defaults overrides.
$minimum_viewport_width = isset( $fluid_settings['minViewportWidth'] ) ? $fluid_settings['minViewportWidth'] : $default_minimum_viewport_width;
$minimum_viewport_width = $fluid_settings['minViewportWidth'] ?? $default_minimum_viewport_width;
$maximum_viewport_width = isset( $layout_settings['wideSize'] ) && ! empty( gutenberg_get_typography_value_and_unit( $layout_settings['wideSize'] ) ) ? $layout_settings['wideSize'] : $default_maximum_viewport_width;
if ( isset( $fluid_settings['maxViewportWidth'] ) ) {
$maximum_viewport_width = $fluid_settings['maxViewportWidth'];
Expand All @@ -550,8 +550,8 @@ function gutenberg_get_typography_font_size_value( $preset, $settings = array()
$minimum_font_size_limit = $has_min_font_size ? $fluid_settings['minFontSize'] : $default_minimum_font_size_limit;

// Try to grab explicit min and max fluid font sizes.
$minimum_font_size_raw = isset( $fluid_font_size_settings['min'] ) ? $fluid_font_size_settings['min'] : null;
$maximum_font_size_raw = isset( $fluid_font_size_settings['max'] ) ? $fluid_font_size_settings['max'] : null;
$minimum_font_size_raw = $fluid_font_size_settings['min'] ?? null;
$maximum_font_size_raw = $fluid_font_size_settings['max'] ?? null;

// Font sizes.
$preferred_size = gutenberg_get_typography_value_and_unit( $preset['size'] );
Expand Down
4 changes: 2 additions & 2 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ function gutenberg_reregister_core_block_types() {
* $script_handle,
* $script_uri,
* $script_dependencies,
* - isset( $script_asset['version'] ) ? $script_asset['version'] : false
* + isset( $script_asset['version'] ) ? $script_asset['version'] : false,
* - $script_asset['version'] ?? false
* + $script_asset['version'] ?? false,
* + array( 'strategy' => 'defer' )
* );
* if ( ! $result ) {
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ public function get_theme_item( $request ) {

if ( rest_is_field_included( 'styles', $fields ) ) {
$raw_data = $theme->get_raw_data();
$data['styles'] = isset( $raw_data['styles'] ) ? $raw_data['styles'] : array();
$data['styles'] = $raw_data['styles'] ?? array();
}

$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
Expand Down
30 changes: 14 additions & 16 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ public function get_custom_css() {
*/
public function get_base_custom_css() {
_deprecated_function( __METHOD__, 'Gutenberg 18.6.0', 'get_stylesheet' );
return isset( $this->theme_json['styles']['css'] ) ? $this->theme_json['styles']['css'] : '';
return $this->theme_json['styles']['css'] ?? '';
}

/**
Expand All @@ -1586,9 +1586,7 @@ public function get_block_custom_css_nodes() {
// 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 = isset( $this->theme_json['styles']['blocks'][ $name ]['css'] )
? $this->theme_json['styles']['blocks'][ $name ]['css']
: null;
$custom_block_css = $this->theme_json['styles']['blocks'][ $name ]['css'] ?? null;
if ( $custom_block_css ) {
$block_nodes[] = array(
'name' => $name,
Expand Down Expand Up @@ -1632,8 +1630,8 @@ public function get_custom_templates() {
foreach ( $this->theme_json['customTemplates'] as $item ) {
if ( isset( $item['name'] ) ) {
$custom_templates[ $item['name'] ] = array(
'title' => isset( $item['title'] ) ? $item['title'] : '',
'postTypes' => isset( $item['postTypes'] ) ? $item['postTypes'] : array( 'page' ),
'title' => $item['title'] ?? '',
'postTypes' => $item['postTypes'] ?? array( 'page' ),
);
}
}
Expand All @@ -1656,8 +1654,8 @@ public function get_template_parts() {
foreach ( $this->theme_json['templateParts'] as $item ) {
if ( isset( $item['name'] ) ) {
$template_parts[ $item['name'] ] = array(
'title' => isset( $item['title'] ) ? $item['title'] : '',
'area' => isset( $item['area'] ) ? $item['area'] : '',
'title' => $item['title'] ?? '',
'area' => $item['area'] ?? '',
);
}
}
Expand Down Expand Up @@ -1723,7 +1721,7 @@ protected function get_layout_styles( $block_metadata, $options = array() ) {
}
}

$selector = isset( $block_metadata['selector'] ) ? $block_metadata['selector'] : '';
$selector = $block_metadata['selector'] ?? '';
$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() );
Expand Down Expand Up @@ -2977,7 +2975,7 @@ static function ( $split_selector ) use ( $clean_style_variation_selector ) {
$style_variation_declarations[ $style_variation['selector'] ] = static::compute_style_properties( $style_variation_node, $settings, null, $this->theme_json );

// Process pseudo-selectors for this variation (e.g., :hover, :focus).
$block_name = isset( $block_metadata['name'] ) ? $block_metadata['name'] : ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? static::get_block_name_from_metadata_path( $block_metadata ) : null );
$block_name = $block_metadata['name'] ?? ( in_array( 'blocks', $block_metadata['path'], true ) && count( $block_metadata['path'] ) >= 3 ? static::get_block_name_from_metadata_path( $block_metadata ) : null );
$variation_pseudo_declarations = static::process_pseudo_selectors( $style_variation_node, $style_variation['selector'], $settings, $block_name );
$style_variation_declarations = array_merge( $style_variation_declarations, $variation_pseudo_declarations );

Expand Down Expand Up @@ -3038,7 +3036,7 @@ static function ( $pseudo_selector ) use ( $selector ) {
)
);

$pseudo_selector = isset( $pseudo_matches[0] ) ? $pseudo_matches[0] : null;
$pseudo_selector = $pseudo_matches[0] ?? null;

/*
* If the current selector is a pseudo selector that's defined in the allow list for the current
Expand All @@ -3055,7 +3053,7 @@ static function ( $pseudo_selector ) use ( $selector ) {
// For block pseudo-selectors, we need to get the block data first, then access the pseudo-selector.
$block_name = static::get_block_name_from_metadata_path( $block_metadata ); // 'core/button'
$block_data = _wp_array_get( $this->theme_json, array( 'styles', 'blocks', $block_name ), array() );
$pseudo_data = isset( $block_data[ $block_pseudo_selector ] ) ? $block_data[ $block_pseudo_selector ] : array();
$pseudo_data = $block_data[ $block_pseudo_selector ] ?? array();

$declarations = static::compute_style_properties( $pseudo_data, $settings, null, $this->theme_json, $selector, $use_root_padding );
} else {
Expand Down Expand Up @@ -3198,9 +3196,9 @@ public function get_root_layout_rules( $selector, $block_metadata, $options = ar
* as custom properties on the body element so all blocks can use them.
*/
if ( isset( $settings['layout']['contentSize'] ) || isset( $settings['layout']['wideSize'] ) ) {
$content_size = isset( $settings['layout']['contentSize'] ) ? $settings['layout']['contentSize'] : $settings['layout']['wideSize'];
$content_size = $settings['layout']['contentSize'] ?? $settings['layout']['wideSize'];
$content_size = static::is_safe_css_declaration( 'max-width', $content_size ) ? $content_size : 'initial';
$wide_size = isset( $settings['layout']['wideSize'] ) ? $settings['layout']['wideSize'] : $settings['layout']['contentSize'];
$wide_size = $settings['layout']['wideSize'] ?? $settings['layout']['contentSize'];
$wide_size = static::is_safe_css_declaration( 'max-width', $wide_size ) ? $wide_size : 'initial';
$css .= static::ROOT_CSS_PROPERTIES_SELECTOR . ' { --wp--style--global--content-size: ' . $content_size . ';';
$css .= '--wp--style--global--wide-size: ' . $wide_size . '; }';
Expand Down Expand Up @@ -4652,8 +4650,8 @@ private static function convert_variables_to_value( $styles, $values ) {
$fallback,
),
array(
isset( $values[ $key_in_values ] ) ? $values[ $key_in_values ] : $rule_to_replace,
isset( $values[ $fallback ] ) ? $values[ $fallback ] : $fallback,
$values[ $key_in_values ] ?? $rule_to_replace,
$values[ $fallback ] ?? $fallback,
),
$resolved_style
);
Expand Down
Loading
Loading