PluginProbe
Twentig Supercharged Block Editor – Blocks, Patterns, Starter Sites, Portfolio / trunk
Twentig Supercharged Block Editor – Blocks, Patterns, Starter Sites, Portfolio vtrunk
2.0.5 2.0.4 2.0.3 2.0.2 trunk 0.0.1 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.9.1 0.9.2 1.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 All 88 releases
twentig / inc / blocks / separator.php

separator.php in Twentig Supercharged Block Editor – Blocks, Patterns, Starter Sites, Portfolio trunk, at inc/blocks/separator.php

52 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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