Skip to content

Commit

Permalink
minor PHP tweaks (#43375)
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath authored Aug 29, 2022
1 parent ffe6c62 commit 0cb2f52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
14 changes: 4 additions & 10 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_border_support( $block_type ) {
// Determine if any border related features are supported.
$has_border_support = block_has_support( $block_type, array( '__experimentalBorder' ) );
$has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' );

// Setup attributes and styles within that if needed.
if ( ! $block_type->attributes ) {
$block_type->attributes = array();
}

if ( $has_border_support && ! array_key_exists( 'style', $block_type->attributes ) ) {
if ( block_has_support( $block_type, array( '__experimentalBorder' ) ) && ! array_key_exists( 'style', $block_type->attributes ) ) {
$block_type->attributes['style'] = array(
'type' => 'object',
);
}

if ( $has_border_color_support && ! array_key_exists( 'borderColor', $block_type->attributes ) ) {
if ( gutenberg_has_border_feature_support( $block_type, 'color' ) && ! array_key_exists( 'borderColor', $block_type->attributes ) ) {
$block_type->attributes['borderColor'] = array(
'type' => 'string',
);
Expand All @@ -48,9 +44,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
return array();
}

$sides = array( 'top', 'right', 'bottom', 'left' );
$border_block_styles = array();

$border_block_styles = array();
$has_border_color_support = gutenberg_has_border_feature_support( $block_type, 'color' );
$has_border_width_support = gutenberg_has_border_feature_support( $block_type, 'width' );

Expand Down Expand Up @@ -106,7 +100,7 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {

// Generate styles for individual border sides.
if ( $has_border_color_support || $has_border_width_support ) {
foreach ( $sides as $side ) {
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
$border = _wp_array_get( $block_attributes, array( 'style', 'border', $side ), null );
$border_side_values = array(
'width' => isset( $border['width'] ) && ! gutenberg_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
Expand Down
5 changes: 1 addition & 4 deletions lib/block-supports/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_colors_support( $block_type ) {
$color_support = false;
if ( property_exists( $block_type, 'supports' ) ) {
$color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
}
$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 );
Expand Down

0 comments on commit 0cb2f52

Please sign in to comment.