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 / term-description.php

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

62 lines 1.8 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/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 * @param string $content Block default content.
15 * @param WP_Block $block Block instance.
16 *
17 * @return string Returns the description of the current taxonomy term, if available
18 */
19 function gutenberg_render_block_core_term_description( $attributes, $content, $block ) {
20 $term_description = '';
21
22 // Get term from context or from the current query.
23 if ( isset( $block->context['termId'] ) && isset( $block->context['taxonomy'] ) ) {
24 $term = get_term( $block->context['termId'], $block->context['taxonomy'] );
25 if ( $term && ! is_wp_error( $term ) ) {
26 $term_description = $term->description;
27 }
28 } elseif ( is_category() || is_tag() || is_tax() ) {
29 $term_description = term_description();
30 }
31
32 if ( empty( $term_description ) ) {
33 return '';
34 }
35
36 $classes = array();
37 if ( isset( $attributes['textAlign'] ) ) {
38 $classes[] = 'has-text-align-' . $attributes['textAlign'];
39 }
40 if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
41 $classes[] = 'has-link-color';
42 }
43 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
44
45 return '<div ' . $wrapper_attributes . '>' . $term_description . '</div>';
46 }
47
48 /**
49 * Registers the `core/term-description` block on the server.
50 *
51 * @since 5.9.0
52 */
53 function gutenberg_register_block_core_term_description() {
54 register_block_type_from_metadata(
55 __DIR__ . '/term-description',
56 array(
57 'render_callback' => 'gutenberg_render_block_core_term_description',
58 )
59 );
60 }
61 add_action( 'init', 'gutenberg_register_block_core_term_description', 20 );
62