Skip to content

Commit

Permalink
Update border radius block support for per corner radii
Browse files Browse the repository at this point in the history
Maintains support for flat string value for setting all border radii at once.
  • Loading branch information
aaronrobertshaw committed Jun 7, 2021
1 parent 3d5196a commit b27a966
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,21 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
) {
$border_radius = $block_attributes['style']['border']['radius'];

// This check handles original unitless implementation.
if ( is_numeric( $border_radius ) ) {
$border_radius .= 'px';
if ( is_array( $border_radius ) ) {
// We have individual border radius corner values.
foreach ( $border_radius as $key => $radius ) {
// Convert CamelCase corner name to kebab-case.
$corner = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) );
$styles[] = sprintf( 'border-%s-radius: %s;', $corner, $radius );
}
} else {
// This check handles original unitless implementation.
if ( is_numeric( $border_radius ) ) {
$border_radius .= 'px';
}

$styles[] = sprintf( 'border-radius: %s;', $border_radius );
}

$styles[] = sprintf( 'border-radius: %s;', $border_radius );
}

// Border style.
Expand Down

0 comments on commit b27a966

Please sign in to comment.