| 1 |
<?php |
| 2 |
/** |
| 3 |
* Server-side rendering of the `core/term-description` block. |
| 4 |
* |
| 5 |
* @package WordPress |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Renders the `core/term-description` block on the server. |
| 10 |
* |
| 11 |
* @since 5.9.0 |
| 12 |
* |
| 13 |
* @param array $attributes Block attributes. |
| 14 |
* |
| 15 |
* @return string Returns the description of the current taxonomy term, if available |
| 16 |
*/ |
| 17 |
function gutenberg_render_block_core_term_description( $attributes ) { |
| 18 |
$term_description = ''; |
| 19 |
|
| 20 |
if ( is_category() || is_tag() || is_tax() ) { |
| 21 |
$term_description = term_description(); |
| 22 |
} |
| 23 |
|
| 24 |
if ( empty( $term_description ) ) { |
| 25 |
return ''; |
| 26 |
} |
| 27 |
|
| 28 |
$classes = array(); |
| 29 |
if ( isset( $attributes['textAlign'] ) ) { |
| 30 |
$classes[] = 'has-text-align-' . $attributes['textAlign']; |
| 31 |
} |
| 32 |
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { |
| 33 |
$classes[] = 'has-link-color'; |
| 34 |
} |
| 35 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); |
| 36 |
|
| 37 |
return '<div ' . $wrapper_attributes . '>' . $term_description . '</div>'; |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Registers the `core/term-description` block on the server. |
| 42 |
* |
| 43 |
* @since 5.9.0 |
| 44 |
*/ |
| 45 |
function gutenberg_register_block_core_term_description() { |
| 46 |
register_block_type_from_metadata( |
| 47 |
__DIR__ . '/term-description', |
| 48 |
array( |
| 49 |
'render_callback' => 'gutenberg_render_block_core_term_description', |
| 50 |
) |
| 51 |
); |
| 52 |
} |
| 53 |
add_action( 'init', 'gutenberg_register_block_core_term_description', 20 ); |
| 54 |
|