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 / post-template.php

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

60 lines 1.7 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/post-template` block.
4 *
5 * @package twentig
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Filters the post template 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_post_template_block( $block_content, $block ) {
18
19 $attributes = $block['attrs'] ?? array();
20 $layout = $attributes['layout']['type'] ?? null;
21 $class_names = array();
22
23 if ( 'grid' !== $layout ) {
24 return $block_content;
25 }
26
27 $columns_count = $attributes['layout']['columnCount'] ?? 3;
28 $has_minimum_column_width = ! empty( $attributes['layout']['minimumColumnWidth'] );
29
30 if ( 1 !== $columns_count ) {
31 if ( isset( $attributes['twVerticalAlignment'] ) ) {
32 $class_names[] = 'tw-valign-' . $attributes['twVerticalAlignment'];
33 }
34 if ( ! empty( $attributes['twColumnWidth'] ) && ! $has_minimum_column_width ) {
35 $class_names[] = 'tw-cols-' . $attributes['twColumnWidth'];
36 }
37 if ( $has_minimum_column_width ) {
38 $class_names[] = 'tw-is-responsive';
39 }
40 }
41
42 if ( $has_minimum_column_width || ! empty( $class_names ) ) {
43 $tag_processor = new WP_HTML_Tag_Processor( $block_content );
44 $tag_processor->next_tag();
45
46 if ( $has_minimum_column_width ) {
47 $tag_processor->remove_class( 'tw-cols-small' );
48 $tag_processor->remove_class( 'tw-cols-large' );
49 }
50
51 foreach ( $class_names as $class_name ) {
52 $tag_processor->add_class( sanitize_html_class( $class_name ) );
53 }
54 $block_content = $tag_processor->get_updated_html();
55 }
56
57 return $block_content;
58 }
59 add_filter( 'render_block_core/post-template', 'twentig_filter_post_template_block', 10, 2 );
60