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 / details.php

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

45 lines 2.0 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/details` block.
4 *
5 * @package twentig
6 */
7
8 defined( 'ABSPATH' ) || exit;
9
10 /**
11 * Filters the details 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_details_block( $block_content, $block ) {
18 $icon_type = $block['attrs']['twIcon'] ?? '';
19
20 if ( empty( $icon_type ) ) {
21 return $block_content;
22 }
23
24 $icon_position = $block['attrs']['twIconPosition'] ?? 'right';
25 $tag_processor = new WP_HTML_Tag_Processor( $block_content );
26 $tag_processor->next_tag();
27 $tag_processor->add_class( 'tw-has-icon' );
28 $tag_processor->add_class( 'tw-icon-' . sanitize_html_class( $icon_type ) );
29
30 if ( 'left' === $icon_position ) {
31 $tag_processor->add_class( 'tw-has-icon-left' );
32 }
33
34 $block_content = $tag_processor->get_updated_html();
35
36 $icon_svg = '<svg class="details-arrow" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" version="1.1" aria-hidden="true" focusable="false"><path d="m12 15.4-6-6L7.4 8l4.6 4.6L16.6 8 18 9.4z"></path></svg>';
37 if ( 'plus' === $icon_type ) {
38 $icon_svg = '<svg class="details-plus" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" version="1.1" aria-hidden="true" focusable="false"><path class="plus-vertical" d="M11 6h2v12h-2z"/><path d="M6 11h12v2H6z"/></svg>';
39 } elseif ( 'plus-circle' === $icon_type ) {
40 $icon_svg = '<svg class="details-plus" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" version="1.1" aria-hidden="true" focusable="false"><path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m0 1.75a8.25 8.25 0 1 0 0 16.5 8.25 8.25 0 0 0 0-16.5" /><path d="M11.125 7.5h1.75v9h-1.75z" class="plus-vertical" /><path d="M7.5 11.125h9v1.75h-9z" /></svg>';
41 }
42 return str_replace( '</summary>', $icon_svg . '</summary>', $block_content );
43 }
44 add_filter( 'render_block_core/details', 'twentig_filter_details_block', 10, 2 );
45