author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:52:52 +0200 | |
changeset 22 | 8c2e4d02f4ef |
parent 21 | 48c4eec2b7e6 |
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 |
||
22
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
32 |
if ( empty( $tag_cloud ) ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
33 |
// Display placeholder content when there are no tags only in editor. |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
34 |
if ( wp_is_serving_rest_request() ) { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
35 |
$tag_cloud = __( 'There’s no content to show here yet.' ); |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
36 |
} else { |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
37 |
return ''; |
8c2e4d02f4ef
Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents:
21
diff
changeset
|
38 |
} |
9 | 39 |
} |
40 |
||
18 | 41 |
$wrapper_attributes = get_block_wrapper_attributes(); |
42 |
||
9 | 43 |
return sprintf( |
18 | 44 |
'<p %1$s>%2$s</p>', |
45 |
$wrapper_attributes, |
|
9 | 46 |
$tag_cloud |
47 |
); |
|
48 |
} |
|
49 |
||
50 |
/** |
|
51 |
* 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
|
52 |
* |
48c4eec2b7e6
Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents:
19
diff
changeset
|
53 |
* @since 5.2.0 |
9 | 54 |
*/ |
55 |
function register_block_core_tag_cloud() { |
|
16 | 56 |
register_block_type_from_metadata( |
57 |
__DIR__ . '/tag-cloud', |
|
9 | 58 |
array( |
59 |
'render_callback' => 'render_block_core_tag_cloud', |
|
60 |
) |
|
61 |
); |
|
62 |
} |
|
63 |
add_action( 'init', 'register_block_core_tag_cloud' ); |