diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-09-19 04:51:18 +0000 |
commit | 0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch) | |
tree | e139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/blocks/list.php | |
parent | Adding upstream version 6.5.5+dfsg1. (diff) | |
download | wordpress-upstream/6.6.1+dfsg1.tar.xz wordpress-upstream/6.6.1+dfsg1.zip |
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/blocks/list.php')
-rw-r--r-- | wp-includes/blocks/list.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/wp-includes/blocks/list.php b/wp-includes/blocks/list.php new file mode 100644 index 0000000..1bffd81 --- /dev/null +++ b/wp-includes/blocks/list.php @@ -0,0 +1,54 @@ +<?php +/** + * Adds the wp-block-list class to the rendered list block. + * + * @package WordPress + */ + +/** + * Adds the wp-block-list class to the rendered list block. + * Ensures that pre-existing list blocks use the class name on the front. + * For example, <ol> is transformed to <ol class="wp-block-list">. + * + * @since 6.6.0 + * + * @see https://github.com/WordPress/gutenberg/issues/12420 + * + * @param array $attributes Attributes of the block being rendered. + * @param string $content Content of the block being rendered. + * + * @return string The content of the block being rendered. + */ +function block_core_list_render( $attributes, $content ) { + if ( ! $content ) { + return $content; + } + + $processor = new WP_HTML_Tag_Processor( $content ); + + $list_tags = array( 'OL', 'UL' ); + while ( $processor->next_tag() ) { + if ( in_array( $processor->get_tag(), $list_tags, true ) ) { + $processor->add_class( 'wp-block-list' ); + break; + } + } + + return $processor->get_updated_html(); +} + +/** + * Registers the `core/list` block on server. + * + * @since 6.6.0 + */ +function register_block_core_list() { + register_block_type_from_metadata( + __DIR__ . '/list', + array( + 'render_callback' => 'block_core_list_render', + ) + ); +} + +add_action( 'init', 'register_block_core_list' ); |