wpseek.com
Uma área de pesquisa sobre o WordPress para devs e autores do tema
wp_get_border_classes_and_styles › WordPress Function
Desde7.3.0
Obsoleton/a
› wp_get_border_classes_and_styles ( $block_attributes )
| Parâmetros: |
|
| Retorna: |
|
| Definido em: |
|
| Codex: |
Returns border classes and inline styles for block attributes, like the JS `getBorderClassesAndStyles()`. Does not check block support or skipped serialization.
Fonte
function wp_get_border_classes_and_styles( $block_attributes ) {
if ( ! is_array( $block_attributes ) ) {
return array();
}
$border = isset( $block_attributes['style']['border'] ) && is_array( $block_attributes['style']['border'] )
? $block_attributes['style']['border']
: array();
$border_styles = array();
// Unitless radius and width are from the original implementation.
if ( isset( $border['radius'] ) ) {
$border_styles['radius'] = is_numeric( $border['radius'] ) ? "{$border['radius']}px" : $border['radius'];
}
if ( isset( $border['style'] ) ) {
$border_styles['style'] = $border['style'];
}
if ( isset( $border['width'] ) ) {
$border_styles['width'] = is_numeric( $border['width'] ) ? "{$border['width']}px" : $border['width'];
}
// Preset slugs are strings in theme.json and the editor.
$preset_slug = $block_attributes['borderColor'] ?? null;
$border_styles['color'] = is_string( $preset_slug ) && '' !== $preset_slug ? "var:preset|color|{$preset_slug}" : ( $border['color'] ?? null );
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
if ( ! isset( $border[ $side ] ) || ! is_array( $border[ $side ] ) ) {
continue;
}
$border_styles[ $side ] = array(
'width' => $border[ $side ]['width'] ?? null,
'color' => $border[ $side ]['color'] ?? null,
'style' => $border[ $side ]['style'] ?? null,
);
}
$attributes = array();
$styles = wp_style_engine_get_styles( array( 'border' => $border_styles ) );
if ( ! empty( $styles['classnames'] ) ) {
$attributes['class'] = $styles['classnames'];
}
if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
}
return $attributes;
}