diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/block-supports/border.php --- a/wp/wp-includes/block-supports/border.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/block-supports/border.php Fri Sep 05 18:40:08 2025 +0200 @@ -11,27 +11,24 @@ * types that support borders. * * @since 5.8.0 + * @since 6.1.0 Improved conditional blocks optimization. * @access private * * @param WP_Block_Type $block_type Block Type. */ function wp_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 = wp_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, '__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 ( wp_has_border_feature_support( $block_type, 'color' ) && ! array_key_exists( 'borderColor', $block_type->attributes ) ) { $block_type->attributes['borderColor'] = array( 'type' => 'string', ); @@ -43,6 +40,7 @@ * attributes array. This will be applied to the block markup in the front-end. * * @since 5.8.0 + * @since 6.1.0 Implemented the style engine to generate CSS and classnames. * @access private * * @param WP_Block_Type $block_type Block type. @@ -54,8 +52,9 @@ return array(); } - $classes = array(); - $styles = array(); + $border_block_styles = array(); + $has_border_color_support = wp_has_border_feature_support( $block_type, 'color' ); + $has_border_width_support = wp_has_border_feature_support( $block_type, 'width' ); // Border radius. if ( @@ -65,21 +64,11 @@ ) { $border_radius = $block_attributes['style']['border']['radius']; - 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( '/(? 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, + ); + $border_block_styles[ $side ] = $border_side_values; } } // Collect classes and styles. $attributes = array(); + $styles = wp_style_engine_get_styles( array( 'border' => $border_block_styles ) ); - if ( ! empty( $classes ) ) { - $attributes['class'] = implode( ' ', $classes ); + if ( ! empty( $styles['classnames'] ) ) { + $attributes['class'] = $styles['classnames']; } - if ( ! empty( $styles ) ) { - $attributes['style'] = implode( ' ', $styles ); + if ( ! empty( $styles['css'] ) ) { + $attributes['style'] = $styles['css']; } return $attributes; @@ -160,11 +152,13 @@ */ 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' ) && - ( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default_value ) ) - ) { - return true; + if ( $block_type instanceof WP_Block_Type ) { + $block_type_supports_border = isset( $block_type->supports['__experimentalBorder'] ) + ? $block_type->supports['__experimentalBorder'] + : $default_value; + if ( true === $block_type_supports_border ) { + return true; + } } // Check if the specific feature has been opted into individually