wppaste
WordPress

wp_apply_border_support( WP_Block_Type $block_type, array $block_attributes ): array

Since
5.8.0, 6.1.0
Source
wp-includes/block-supports/border.php:50
Adds CSS classes and inline styles for border styles to the incoming attributes array. This will be applied to the block markup in the front-end.

Compatibility

WordPress
since 6.1.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$block_typeWP_Block_Type
Block type.
$block_attributesarray
Block attributes.

Return value

array
Border CSS classes and inline styles.

Performance profile

How much work a call to wp_apply_border_support() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
42–96

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 175.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_apply_border_support() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!wp_should_skip_block_supports_serialization() && !wp_has_border_feature_support()42–59wp_should_skip_block_supports_serialization(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), border()
!wp_should_skip_block_supports_serialization() && !wp_has_border_feature_support()49–83wp_should_skip_block_supports_serialization(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_should_skip_block_supports_serialization(), border()
!wp_should_skip_block_supports_serialization() && !wp_has_border_feature_support() && isset($value)59–96wp_should_skip_block_supports_serialization(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_has_border_feature_support(), wp_should_skip_block_supports_serialization(), wp_should_skip_block_supports_serialization(), border()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17542–9630
8.517542–9630
8.417542–96304 fewer instructions than PHP 8.3
8.317942–9830
8.217942–9830
8.117942–98304 fewer instructions than PHP 7.4
7.418342–9830

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 3

Source code

function wp_apply_border_support( $block_type, $block_attributes ) {	if ( wp_should_skip_block_supports_serialization( $block_type, 'border' ) ) {		return 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 (		wp_has_border_feature_support( $block_type, 'radius' ) &&		isset( $block_attributes['style']['border']['radius'] ) &&		! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'radius' )	) {		$border_radius = $block_attributes['style']['border']['radius']; 		if ( is_numeric( $border_radius ) ) {			$border_radius .= 'px';		} 		$border_block_styles['radius'] = $border_radius;	} 	// Border style.	if (		wp_has_border_feature_support( $block_type, 'style' ) &&		isset( $block_attributes['style']['border']['style'] ) &&		! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'style' )	) {		$border_block_styles['style'] = $block_attributes['style']['border']['style'];	} 	// Border width.	if (		$has_border_width_support &&		isset( $block_attributes['style']['border']['width'] ) &&		! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' )	) {		$border_width = $block_attributes['style']['border']['width']; 		// This check handles original unitless implementation.		if ( is_numeric( $border_width ) ) {			$border_width .= 'px';		} 		$border_block_styles['width'] = $border_width;	} 	// Border color.	if (		$has_border_color_support &&		! 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;		$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_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,			);			$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( $styles['classnames'] ) ) {		$attributes['class'] = $styles['classnames'];	}

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.1.0
Implemented the style engine to generate CSS and classnames.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/block-supports/border.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.