wpseek.com
A WordPress-centric search engine for devs and theme authors
block_core_post_navigation_link_get_support_styles › WordPress Function
Since7.2.0
Deprecatedn/a
› block_core_post_navigation_link_get_support_styles ( $attributes )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Generates the background, border, dimensions, shadow and spacing class names and inline styles for the `core/post-navigation-link` block.
Mirrors the default background, border, dimensions, shadow and spacing block support serialization, which the block opts out of so the styles are only applied when a link is rendered.Source
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,
);
}
$background = $block_styles['background'] ?? array();
$background_styles = array(
'backgroundImage' => $background['backgroundImage'] ?? null,
'backgroundSize' => $background['backgroundSize'] ?? null,
'backgroundPosition' => $background['backgroundPosition'] ?? null,
'backgroundRepeat' => $background['backgroundRepeat'] ?? null,
'backgroundAttachment' => $background['backgroundAttachment'] ?? null,
'gradient' => $background['gradient'] ?? null,
);
// Mirrors the background image defaults of the background block support.
if ( ! empty( $background_styles['backgroundImage'] ) ) {
$background_styles['backgroundSize'] = $background_styles['backgroundSize'] ?? 'cover';
if ( 'contain' === $background_styles['backgroundSize'] && ! $background_styles['backgroundPosition'] ) {
$background_styles['backgroundPosition'] = '50% 50%';
}
}
$styles = wp_style_engine_get_styles(
array(
'background' => $background_styles,
'border' => $border_styles,
'dimensions' => array(
'minHeight' => $block_styles['dimensions']['minHeight'] ?? null,
'minWidth' => $block_styles['dimensions']['minWidth'] ?? null,
),
'shadow' => $block_styles['shadow'] ?? null,
'spacing' => array(
'margin' => $block_styles['spacing']['margin'] ?? null,
'padding' => $block_styles['spacing']['padding'] ?? null,
),
)
);
$class_names = $styles['classnames'] ?? '';
// The style engine only adds `has-background` for a gradient, the background block support adds it for an image too.
if ( ! empty( $background_styles['backgroundImage'] ) && ! in_array( 'has-background', explode( ' ', $class_names ), true ) ) {
$class_names = trim( "{$class_names} has-background" );
}
return array(
'class' => $class_names,
'style' => $styles['css'] ?? '',
);
}