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

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

55 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Adds the wp-block-list class to the rendered list block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Adds the wp-block-list class to the rendered list block.
10 * Ensures that pre-existing list blocks use the class name on the front.
11 * For example, <ol> is transformed to <ol class="wp-block-list">.
12 *
13 * @since 6.6.0
14 *
15 * @see https://github.com/WordPress/gutenberg/issues/12420
16 *
17 * @param array $attributes Attributes of the block being rendered.
18 * @param string $content Content of the block being rendered.
19 *
20 * @return string The content of the block being rendered.
21 */
22 function gutenberg_block_core_list_render( $attributes, $content ) {
23 if ( ! $content ) {
24 return $content;
25 }
26
27 $processor = new WP_HTML_Tag_Processor( $content );
28
29 $list_tags = array( 'OL', 'UL' );
30 while ( $processor->next_tag() ) {
31 if ( in_array( $processor->get_tag(), $list_tags, true ) ) {
32 $processor->add_class( 'wp-block-list' );
33 break;
34 }
35 }
36
37 return $processor->get_updated_html();
38 }
39
40 /**
41 * Registers the `core/list` block on server.
42 *
43 * @since 6.6.0
44 */
45 function gutenberg_register_block_core_list() {
46 register_block_type_from_metadata(
47 __DIR__ . '/list',
48 array(
49 'render_callback' => 'gutenberg_block_core_list_render',
50 )
51 );
52 }
53
54 add_action( 'init', 'gutenberg_register_block_core_list', 20 );
55