[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 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 register_block_core_list() { 46 register_block_type_from_metadata( 47 __DIR__ . '/list', 48 array( 49 'render_callback' => 'block_core_list_render', 50 ) 51 ); 52 } 53 54 add_action( 'init', 'register_block_core_list' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Nov 23 08:20:01 2024 | Cross-referenced by PHPXref |