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



block_core_post_navigation_link_get_support_styles › WordPress Function

Seit7.2.0
Veraltetn/v
› block_core_post_navigation_link_get_support_styles ( $attributes )
Parameter:
  • (array) $attributes The block attributes.
    Erforderlich: Ja
Gibt zurück:
  • (array) {
    Border, shadow and spacing class names and inline styles.

    @type string $class Class names generated by the style engine, or an empty string.
    @type string $style Inline styles generated by the style engine, or an empty string.
    }
Definiert in:
Codex:

Generates the border, shadow and spacing class names and inline styles for the `core/post-navigation-link` block.

Mirrors the default border, shadow and spacing block support serialization, which the block opts out of so the styles are only applied when a link is rendered.


Quellcode

function block_core_post_navigation_link_get_support_styles( $attributes ) {
	$block_styles  = $attributes['style'] ?? array();
	$border        = $block_styles['border'] ?? array();
	$border_styles = array();

	// Border radius and width accept unitless numbers from the original implementation.
	if ( isset( $border['radius'] ) ) {
		$border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius'];
	}

	if ( isset( $border['width'] ) ) {
		$border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width'];
	}

	if ( isset( $border['style'] ) ) {
		$border_styles['style'] = $border['style'];
	}

	// A preset border color is stored in its own attribute rather than under `style`.
	$border_styles['color'] = isset( $attributes['borderColor'] )
		? "var:preset|color|{$attributes['borderColor']}"
		: ( $border['color'] ?? null );

	// Individual border sides e.g. top, left etc.
	foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
		$border_styles[ $side ] = array(
			'width' => $border[ $side ]['width'] ?? null,
			'color' => $border[ $side ]['color'] ?? null,
			'style' => $border[ $side ]['style'] ?? null,
		);
	}

	$styles = wp_style_engine_get_styles(
		array(
			'border'  => $border_styles,
			'shadow'  => $block_styles['shadow'] ?? null,
			'spacing' => array(
				'margin'  => $block_styles['spacing']['margin'] ?? null,
				'padding' => $block_styles['spacing']['padding'] ?? null,
			),
		)
	);

	return array(
		'class' => $styles['classnames'] ?? '',
		'style' => $styles['css'] ?? '',
	);
}