author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 19 | 3d72ae0968f4 |
child 22 | 8c2e4d02f4ef |
permissions | -rw-r--r-- |
9 | 1 |
<?php |
2 |
/** |
|
3 |
* Server-side rendering of the `core/tag-cloud` block. |
|
4 |
* |
|
5 |
* @package WordPress |
|
6 |
*/ |
|
7 |
||
8 |
/** |
|
9 |
* Renders the `core/tag-cloud` block on 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.2.0 |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
12 |
* |
9 | 13 |
* @param array $attributes The block attributes. |
14 |
* |
|
15 |
* @return string Returns the tag cloud for selected taxonomy. |
|
16 |
*/ |
|
17 |
function render_block_core_tag_cloud( $attributes ) { |
|
19 | 18 |
$smallest_font_size = $attributes['smallestFontSize']; |
19 |
$unit = ( preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt' ); |
|
20 |
||
18 | 21 |
$args = array( |
9 | 22 |
'echo' => false, |
19 | 23 |
'unit' => $unit, |
9 | 24 |
'taxonomy' => $attributes['taxonomy'], |
25 |
'show_count' => $attributes['showTagCounts'], |
|
19 | 26 |
'number' => $attributes['numberOfTags'], |
27 |
'smallest' => floatVal( $attributes['smallestFontSize'] ), |
|
28 |
'largest' => floatVal( $attributes['largestFontSize'] ), |
|
9 | 29 |
); |
30 |
$tag_cloud = wp_tag_cloud( $args ); |
|
31 |
||
32 |
if ( ! $tag_cloud ) { |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
33 |
$tag_cloud = __( 'There’s no content to show here yet.' ); |
9 | 34 |
} |
35 |
||
18 | 36 |
$wrapper_attributes = get_block_wrapper_attributes(); |
37 |
||
9 | 38 |
return sprintf( |
18 | 39 |
'<p %1$s>%2$s</p>', |
40 |
$wrapper_attributes, |
|
9 | 41 |
$tag_cloud |
42 |
); |
|
43 |
} |
|
44 |
||
45 |
/** |
|
46 |
* Registers the `core/tag-cloud` block on server. |
|
21
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
47 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
48 |
* @since 5.2.0 |
9 | 49 |
*/ |
50 |
function register_block_core_tag_cloud() { |
|
16 | 51 |
register_block_type_from_metadata( |
52 |
__DIR__ . '/tag-cloud', |
|
9 | 53 |
array( |
54 |
'render_callback' => 'render_block_core_tag_cloud', |
|
55 |
) |
|
56 |
); |
|
57 |
} |
|
58 |
add_action( 'init', 'register_block_core_tag_cloud' ); |