Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update PHP block support code in lib/block-supports/border.php to use… #65966

Closed
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
25 changes: 15 additions & 10 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$block_type->attributes = array();
}

if ( block_has_support( $block_type, array( '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
if ( block_has_support( $block_type, array( 'border', '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
$block_type->attributes['style'] = array(
'type' => 'object',
);
Expand Down Expand Up @@ -52,7 +52,8 @@
if (
gutenberg_has_border_feature_support( $block_type, 'radius' ) &&
isset( $block_attributes['style']['border']['radius'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' )
(! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' ) ||

Check failure on line 55 in lib/block-supports/border.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space after open parenthesis; 0 found

Check failure on line 55 in lib/block-supports/border.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space before "!"; 0 found
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'radius' ))

Check failure on line 56 in lib/block-supports/border.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space before close parenthesis; 0 found
) {
$border_radius = $block_attributes['style']['border']['radius'];

Expand All @@ -67,7 +68,8 @@
if (
gutenberg_has_border_feature_support( $block_type, 'style' ) &&
isset( $block_attributes['style']['border']['style'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' )
( ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ||
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' ) )
) {
$border_block_styles['style'] = $block_attributes['style']['border']['style'];
}
Expand All @@ -76,7 +78,8 @@
if (
$has_border_width_support &&
isset( $block_attributes['style']['border']['width'] ) &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' )
( ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ||
! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' ) )
) {
$border_width = $block_attributes['style']['border']['width'];

Expand All @@ -91,7 +94,8 @@
// Border color.
if (
$has_border_color_support &&
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
( ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ||
! wp_should_skip_block_supports_serialization( $block_type, 'border', '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;
Expand All @@ -103,9 +107,9 @@
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
$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,
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' ) ? $border['style'] : null,
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'width' ) ? $border['width'] : null,

Check failure on line 110 in lib/block-supports/border.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Expected 1 space before "?"; 2 found
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'color' ) ? $border['color'] : null,
'style' => isset( $border['style'] ) && ! wp_should_skip_block_supports_serialization( $block_type, 'border', 'style' ) ? $border['style'] : null,
);
$border_block_styles[ $side ] = $border_side_values;
}
Expand Down Expand Up @@ -143,15 +147,16 @@
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 ( $block_type instanceof WP_Block_Type ) {
$block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value;
$block_type_supports_border = $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
// via nested flag under `__experimentalBorder`.
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value );
return block_has_support( $block_type, array( '__experimentalBorder', $feature ), $default_value )
|| block_has_support( $block_type, array( 'border', $feature ), $default_value );
}

// Register the block support.
Expand Down
Loading