author | ymh <ymh.work@gmail.com> |
Mon, 08 Sep 2025 19:44:41 +0200 | |
changeset 23 | 417f20492bf7 |
parent 21 | 48c4eec2b7e6 |
permissions | -rw-r--r-- |
19 | 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 |
* |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
11 |
* @since 5.9.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* |
19 | 13 |
* @param array $attributes Block attributes. |
14 |
* |
|
15 |
* @return string Returns the description of the current taxonomy term, if available |
|
16 |
*/ |
|
17 |
function 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 |
||
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
28 |
$classes = array(); |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
29 |
if ( isset( $attributes['textAlign'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
30 |
$classes[] = 'has-text-align-' . $attributes['textAlign']; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
31 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
32 |
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) { |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
$classes[] = 'has-link-color'; |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
34 |
} |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
35 |
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) ); |
19 | 36 |
|
37 |
return '<div ' . $wrapper_attributes . '>' . $term_description . '</div>'; |
|
38 |
} |
|
39 |
||
40 |
/** |
|
41 |
* Registers the `core/term-description` block on the server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
42 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
43 |
* @since 5.9.0 |
19 | 44 |
*/ |
45 |
function register_block_core_term_description() { |
|
46 |
register_block_type_from_metadata( |
|
47 |
__DIR__ . '/term-description', |
|
48 |
array( |
|
49 |
'render_callback' => 'render_block_core_term_description', |
|
50 |
) |
|
51 |
); |
|
52 |
} |
|
53 |
add_action( 'init', 'register_block_core_term_description' ); |