Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Change syntax from ?? to isset()
  • Loading branch information
aristath committed Sep 26, 2023
commit d522626558d38cebeb7649366e431b47a0a4f957
12 changes: 9 additions & 3 deletions src/wp-includes/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ function wp_render_background_support( $block_content, $block ) {
return $block_content;
}

$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_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();

Expand Down
8 changes: 5 additions & 3 deletions src/wp-includes/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $block_attributes['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 = $block_attributes['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,
Expand Down Expand Up @@ -153,7 +153,9 @@ 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' ) ) {
$block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value;
$block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] )
? $block_type->supports['__experimentalBorder']
: $default_value;
if ( true === $block_type_supports_border ) {
return true;
}
Expand Down
20 changes: 10 additions & 10 deletions src/wp-includes/block-supports/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
function wp_register_colors_support( $block_type ) {
$color_support = false;
if ( property_exists( $block_type, 'supports' ) ) {
$color_support = $block_type->supports['color'] ?? false;
$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 = $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_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 ||
Expand Down Expand Up @@ -81,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 = $block_type->supports['color'] ?? false;
$color_support = isset( $block_type->supports['color'] ) ? $block_type->supports['color'] : false;

if (
is_array( $color_support ) &&
Expand All @@ -96,27 +96,27 @@ function wp_apply_colors_support( $block_type, $block_attributes ) {
$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_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 = $block_attributes['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 = $block_attributes['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 = $block_attributes['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;
}

Expand Down
4 changes: 3 additions & 1 deletion src/wp-includes/block-supports/dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ function wp_apply_dimensions_support( $block_type, $block_attributes ) { // phpc
$dimensions_block_styles = array();
$dimensions_block_styles['minHeight'] = null;
if ( $has_min_height_support && ! $skip_min_height ) {
$dimensions_block_styles['minHeight'] = $block_styles['dimensions']['minHeight'] ?? null;
$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 ) );

Expand Down
6 changes: 4 additions & 2 deletions src/wp-includes/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ function wp_render_elements_support_styles( $pre_render, $block ) {
continue;
}

$element_style_object = $element_block_styles[ $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 ) {
Expand All @@ -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 = $element_block_styles[ $element ] ?? null;
$element_style_object = isset( $element_block_styles[ $element ] )
? $element_block_styles[ $element ]
: null;

if ( $element_style_object ) {
wp_style_engine_get_styles(
Expand Down
42 changes: 30 additions & 12 deletions src/wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function wp_register_layout_support( $block_type ) {
* @return string CSS styles on success. Else, empty string.
*/
function wp_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 = $layout['type'] ?? 'default';
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
$layout_styles = array();

if ( 'default' === $layout_type ) {
Expand Down Expand Up @@ -416,7 +416,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
foreach ( $gap_sides as $gap_side ) {
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = $gap_value[ $gap_side ] ?? $fallback_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|' ) ) {
Expand Down Expand Up @@ -500,7 +500,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
foreach ( $gap_sides as $gap_side ) {
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = $gap_value[ $gap_side ] ?? $fallback_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|' ) ) {
Expand Down Expand Up @@ -604,9 +604,13 @@ function wp_render_layout_support_flag( $block_content, $block ) {
}

$global_settings = wp_get_global_settings();
$fallback_layout = $block_type->supports['layout']['default'] ?? array();
$fallback_layout = isset( $block_type->supports['layout']['default'] )
? $block_type->supports['layout']['default']
: array();
if ( empty( $fallback_layout ) ) {
$fallback_layout = $block_type->supports['__experimentalLayout']['default'] ?? array();
$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;

Expand All @@ -620,7 +624,9 @@ function wp_render_layout_support_flag( $block_content, $block ) {
$used_layout['type'] = 'constrained';
}

$root_padding_aware_alignments = $global_settings['useRootPaddingAwareAlignments'] ?? false;
$root_padding_aware_alignments = isset( $global_settings['useRootPaddingAwareAlignments'] )
? $global_settings['useRootPaddingAwareAlignments']
: false;

if (
$root_padding_aware_alignments &&
Expand Down Expand Up @@ -650,9 +656,13 @@ function wp_render_layout_support_flag( $block_content, $block ) {

// Get classname for layout type.
if ( isset( $used_layout['type'] ) ) {
$layout_classname = $layout_definitions[ $used_layout['type'] ]['className'] ?? '';
$layout_classname = isset( $layout_definitions[ $used_layout['type'] ]['className'] )
? $layout_definitions[ $used_layout['type'] ]['className']
: '';
} else {
$layout_classname = $layout_definitions['default']['className'] ?? '';
$layout_classname = isset( $layout_definitions['default']['className'] )
? $layout_definitions['default']['className']
: '';
}

if ( $layout_classname && is_string( $layout_classname ) ) {
Expand All @@ -665,7 +675,9 @@ function wp_render_layout_support_flag( $block_content, $block ) {
*/
if ( ! current_theme_supports( 'disable-layout-styles' ) ) {

$gap_value = $block['attrs']['style']['spacing']['blockGap'] ?? null;
$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
Expand All @@ -679,16 +691,22 @@ function wp_render_layout_support_flag( $block_content, $block ) {
$gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
}

$fallback_gap_value = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? '0.5em';
$block_spacing = $block['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,
* don't apply the user-defined value to the styles.
*/
$should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );

$block_gap = $global_settings['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(
Expand Down
10 changes: 5 additions & 5 deletions src/wp-includes/block-supports/position.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ function wp_render_position_support( $block_content, $block ) {
}

$global_settings = wp_get_global_settings();
$theme_has_sticky_support = $global_settings['position']['sticky'] ?? false;
$theme_has_fixed_support = $global_settings['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();
Expand All @@ -63,11 +63,11 @@ function wp_render_position_support( $block_content, $block ) {
$allowed_position_types[] = 'fixed';
}

$style_attribute = $block['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 = $style_attribute['position']['type'] ?? '';
$position_type = isset( $style_attribute['position']['type'] ) ? $style_attribute['position']['type'] : '';
$wrapper_classes = array();

if (
Expand All @@ -78,7 +78,7 @@ function wp_render_position_support( $block_content, $block ) {
$sides = array( 'top', 'right', 'bottom', 'left' );

foreach ( $sides as $side ) {
$side_value = $style_attribute['position'][ $side ] ?? null;
$side_value = isset( $style_attribute['position'][ $side ] ) ? $style_attribute['position'][ $side ] : null;
if ( null !== $side_value ) {
/*
* For fixed or sticky top positions,
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/block-supports/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $block['attrs']['settings'] ?? null;
$block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
if ( empty( $block_settings ) ) {
return $block_content;
}
Expand Down Expand Up @@ -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 = $block['attrs']['settings'] ?? null;
$block_settings = isset( $block['attrs']['settings'] ) ? $block['attrs']['settings'] : null;
if ( empty( $block_settings ) ) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/wp-includes/block-supports/spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ function wp_apply_spacing_support( $block_type, $block_attributes ) {
'margin' => null,
);
if ( $has_padding_support && ! $skip_padding ) {
$spacing_block_styles['padding'] = $block_styles['spacing']['padding'] ?? null;
$spacing_block_styles['padding'] = isset( $block_styles['spacing']['padding'] ) ? $block_styles['spacing']['padding'] : null;
}
if ( $has_margin_support && ! $skip_margin ) {
$spacing_block_styles['margin'] = $block_styles['spacing']['margin'] ?? null;
$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 ) );

Expand Down
Loading