| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side customizations for the `core/separator` block. |
| 4 |
* |
| 5 |
* @package twentig |
| 6 |
*/ |
| 7 |
|
| 8 |
defined( 'ABSPATH' ) || exit; |
| 9 |
|
| 10 |
/** |
| 11 |
* Filters the separator block output. |
| 12 |
* |
| 13 |
* @param string $block_content Rendered block content. |
| 14 |
* @param array $block Block object. |
| 15 |
* @return string Filtered block content. |
| 16 |
*/ |
| 17 |
function twentig_filter_separator_block( $block_content, $block ) { |
| 18 |
$attributes = $block['attrs'] ?? array(); |
| 19 |
$width = $attributes['twWidth'] ?? ''; |
| 20 |
$height = $attributes['twHeight'] ?? ''; |
| 21 |
$style = ''; |
| 22 |
|
| 23 |
if ( |
| 24 |
( empty( $width ) && empty( $height ) ) || |
| 25 |
str_contains( $block_content, 'is-style-dots' ) || |
| 26 |
str_contains( $block_content, 'is-style-tw-asterisks' ) |
| 27 |
) { |
| 28 |
return $block_content; |
| 29 |
} |
| 30 |
|
| 31 |
$tag_processor = new WP_HTML_Tag_Processor( $block_content ); |
| 32 |
$tag_processor->next_tag(); |
| 33 |
|
| 34 |
if ( ! empty( $width ) ) { |
| 35 |
$style .= 'width: ' . esc_attr( $width ) . '; max-width: 100%;'; |
| 36 |
} |
| 37 |
|
| 38 |
if ( ! empty( $height ) ) { |
| 39 |
$style .= 'height: ' . esc_attr( $height ) . ';'; |
| 40 |
if ( ! empty( $width ) && intval( $height ) > intval( $width ) ) { |
| 41 |
$tag_processor->add_class( 'is-vertical' ); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
$style_attr = $tag_processor->get_attribute( 'style' ); |
| 46 |
$style .= $style_attr; |
| 47 |
$tag_processor->set_attribute( 'style', $style ); |
| 48 |
|
| 49 |
return $tag_processor->get_updated_html(); |
| 50 |
} |
| 51 |
add_filter( 'render_block_core/separator', 'twentig_filter_separator_block', 10, 2 ); |
| 52 |
|