[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Appending the wp-block-heading to before rendering the stored `core/heading` block contents. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Adds a wp-block-heading class to the heading block content. 10 * 11 * For example, the following block content: 12 * <h2 class="align-left">Hello World</h2> 13 * 14 * Would be transformed to: 15 * <h2 class="align-left wp-block-heading">Hello World</h2> 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_heading_render( $attributes, $content ) { 23 if ( ! $content ) { 24 return $content; 25 } 26 27 $p = new WP_HTML_Tag_Processor( $content ); 28 29 $header_tags = array( 'H1', 'H2', 'H3', 'H4', 'H5', 'H6' ); 30 while ( $p->next_tag() ) { 31 if ( in_array( $p->get_tag(), $header_tags, true ) ) { 32 $p->add_class( 'wp-block-heading' ); 33 break; 34 } 35 } 36 37 return $p->get_updated_html(); 38 } 39 40 /** 41 * Registers the `core/heading` block on server. 42 */ 43 function register_block_core_heading() { 44 register_block_type_from_metadata( 45 __DIR__ . '/heading', 46 array( 47 'render_callback' => 'block_core_heading_render', 48 ) 49 ); 50 } 51 52 add_action( 'init', 'register_block_core_heading' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Fri Mar 29 08:20:02 2024 | Cross-referenced by PHPXref |