wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_apply_border_support › WordPress Function

Since5.8.0
Deprecatedn/a
wp_apply_border_support ( $block_type, $block_attributes )
Access:
  • private
Parameters: (2)
  • (WP_Block_type) $block_type Block type.
    Required: Yes
  • (array) $block_attributes Block attributes.
    Required: Yes
Returns:
  • (array) Border CSS classes and inline styles.
Defined at:
Codex:

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.



Source

function wp_apply_border_support( $block_type, $block_attributes ) {
	$border_support = _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), false );

	if (
		is_array( $border_support ) &&
		array_key_exists( '__experimentalSkipSerialization', $border_support ) &&
		$border_support['__experimentalSkipSerialization']
	) {
		return array();
	}

	// Arrays used to ease addition of further border related features in future.
	$styles = array();

	// Border Radius.
	$has_border_radius_support = block_has_support( $block_type, array( '__experimentalBorder', 'radius' ), false );
	if ( $has_border_radius_support ) {
		if ( isset( $block_attributes['style']['border']['radius'] ) ) {
			$border_radius = intval( $block_attributes['style']['border']['radius'] );
			$styles[]      = sprintf( 'border-radius: %dpx;', $border_radius );
		}
	}

	// Border width, style etc can be added here.

	// Collect classes and styles.
	$attributes = array();

	if ( ! empty( $styles ) ) {
		$attributes['style'] = implode( ' ', $styles );
	}

	return $attributes;
}