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

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

49 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/paragraph` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Append the `wp-block-paragraph` class before rendering the stored
10 * `core/paragraph` block contents.
11 *
12 * For example, the following block content:
13 * <p class="align-left">Hello World</p>
14 *
15 * Would be transformed to:
16 * <p class="align-left wp-block-paragraph">Hello World</p>
17 *
18 * @since 7.0.0
19 *
20 * @param string $block_content The block content.
21 *
22 * @return string Filtered block content.
23 */
24 function gutenberg_block_core_paragraph_add_class( $block_content ) {
25 if ( ! $block_content ) {
26 return $block_content;
27 }
28
29 $processor = new WP_HTML_Tag_Processor( $block_content );
30
31 if ( $processor->next_tag( 'p' ) ) {
32 $processor->add_class( 'wp-block-paragraph' );
33 }
34
35 return $processor->get_updated_html();
36 }
37
38 add_filter( 'render_block_core/paragraph', 'gutenberg_block_core_paragraph_add_class' );
39
40 /**
41 * Registers the `core/paragraph` block on server.
42 *
43 * @since 7.0.0
44 */
45 function gutenberg_register_block_core_paragraph() {
46 register_block_type_from_metadata( __DIR__ . '/paragraph' );
47 }
48 add_action( 'init', 'gutenberg_register_block_core_paragraph', 20 );
49