PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / scripts / block-library / accordion.php

accordion.php in Gutenberg 22.9.0, at build/scripts/block-library/accordion.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of the `core/accordion` block.
4 *
5 * @package WordPress
6 * @since 6.9.0
7 *
8 * @param array $attributes The block attributes.
9 * @param string $content The block content.
10 *
11 * @return string Returns the updated markup.
12 */
13 function gutenberg_render_block_core_accordion( $attributes, $content ) {
14 if ( ! $content ) {
15 return $content;
16 }
17
18 $p = new WP_HTML_Tag_Processor( $content );
19 $autoclose = $attributes['autoclose'] ? 'true' : 'false';
20
21 if ( $p->next_tag( array( 'class_name' => 'wp-block-accordion' ) ) ) {
22 $p->set_attribute( 'data-wp-interactive', 'core/accordion' );
23 $p->set_attribute( 'data-wp-context', '{ "autoclose": ' . $autoclose . ', "accordionItems": [] }' );
24
25 // Only modify content if directives have been set.
26 $content = $p->get_updated_html();
27 }
28
29 return $content;
30 }
31
32 /**
33 * Registers the `core/accordion` block on server.
34 *
35 * @since 6.9.0
36 */
37 function gutenberg_register_block_core_accordion() {
38 register_block_type_from_metadata(
39 __DIR__ . '/accordion',
40 array(
41 'render_callback' => 'gutenberg_render_block_core_accordion',
42 )
43 );
44 }
45 add_action( 'init', 'gutenberg_register_block_core_accordion', 20 );
46