wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_apply_border_support › WordPress Function

Seit5.8.0
Veraltetn/v
wp_apply_border_support ( $block_type, $block_attributes )
Zugriff:
  • private
Parameter: (2)
  • (WP_Block_type) $block_type Block type.
    Erforderlich: Ja
  • (array) $block_attributes Block attributes.
    Erforderlich: Ja
Gibt zurück:
  • (array) Border CSS classes and inline styles.
Definiert in:
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.



Quellcode

function wp_apply_border_support( $block_type, $block_attributes ) {
	if ( wp_skip_border_serialization( $block_type ) ) {
		return array();
	}

	$classes = array();
	$styles  = array();

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

	// Border style.
	if (
		block_has_support( $block_type, array( '__experimentalBorder', 'style' ) ) &&
		isset( $block_attributes['style']['border']['style'] )
	) {
		$border_style = $block_attributes['style']['border']['style'];
		$styles[]     = sprintf( 'border-style: %s;', $border_style );
	}

	// Border width.
	if (
		block_has_support( $block_type, array( '__experimentalBorder', 'width' ) ) &&
		isset( $block_attributes['style']['border']['width'] )
	) {
		$border_width = intval( $block_attributes['style']['border']['width'] );
		$styles[]     = sprintf( 'border-width: %dpx;', $border_width );
	}

	// Border color.
	if ( block_has_support( $block_type, array( '__experimentalBorder', 'color' ) ) ) {
		$has_named_border_color  = array_key_exists( 'borderColor', $block_attributes );
		$has_custom_border_color = isset( $block_attributes['style']['border']['color'] );

		if ( $has_named_border_color || $has_custom_border_color ) {
			$classes[] = 'has-border-color';
		}

		if ( $has_named_border_color ) {
			$classes[] = sprintf( 'has-%s-border-color', $block_attributes['borderColor'] );
		} elseif ( $has_custom_border_color ) {
			$border_color = $block_attributes['style']['border']['color'];
			$styles[]     = sprintf( 'border-color: %s;', $border_color );
		}
	}

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

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

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

	return $attributes;
}