6 */ |
6 */ |
7 |
7 |
8 /** |
8 /** |
9 * Renders the `core/site-tagline` block on the server. |
9 * Renders the `core/site-tagline` block on the server. |
10 * |
10 * |
|
11 * @since 5.8.0 |
|
12 * |
11 * @param array $attributes The block attributes. |
13 * @param array $attributes The block attributes. |
12 * |
14 * |
13 * @return string The render. |
15 * @return string The render. |
14 */ |
16 */ |
15 function render_block_core_site_tagline( $attributes ) { |
17 function render_block_core_site_tagline( $attributes ) { |
16 $site_tagline = get_bloginfo( 'description' ); |
18 $site_tagline = get_bloginfo( 'description' ); |
17 if ( ! $site_tagline ) { |
19 if ( ! $site_tagline ) { |
18 return; |
20 return; |
19 } |
21 } |
|
22 |
|
23 $tag_name = 'p'; |
20 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
24 $align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}"; |
21 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); |
25 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) ); |
22 |
26 |
|
27 if ( isset( $attributes['level'] ) && 0 !== $attributes['level'] ) { |
|
28 $tag_name = 'h' . (int) $attributes['level']; |
|
29 } |
|
30 |
23 return sprintf( |
31 return sprintf( |
24 '<p %1$s>%2$s</p>', |
32 '<%1$s %2$s>%3$s</%1$s>', |
|
33 $tag_name, |
25 $wrapper_attributes, |
34 $wrapper_attributes, |
26 $site_tagline |
35 $site_tagline |
27 ); |
36 ); |
28 } |
37 } |
29 |
38 |
30 /** |
39 /** |
31 * Registers the `core/site-tagline` block on the server. |
40 * Registers the `core/site-tagline` block on the server. |
|
41 * |
|
42 * @since 5.8.0 |
32 */ |
43 */ |
33 function register_block_core_site_tagline() { |
44 function register_block_core_site_tagline() { |
34 register_block_type_from_metadata( |
45 register_block_type_from_metadata( |
35 __DIR__ . '/site-tagline', |
46 __DIR__ . '/site-tagline', |
36 array( |
47 array( |
37 'render_callback' => 'render_block_core_site_tagline', |
48 'render_callback' => 'render_block_core_site_tagline', |
38 ) |
49 ) |
39 ); |
50 ); |
40 } |
51 } |
|
52 |
41 add_action( 'init', 'register_block_core_site_tagline' ); |
53 add_action( 'init', 'register_block_core_site_tagline' ); |