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 |
* |
|
11 |
* @param array $attributes The block attributes. |
|
12 |
* |
|
13 |
* @return string Returns the tag cloud for selected taxonomy. |
|
14 |
*/ |
|
15 |
function render_block_core_tag_cloud( $attributes ) { |
18
|
16 |
$args = array( |
9
|
17 |
'echo' => false, |
|
18 |
'taxonomy' => $attributes['taxonomy'], |
|
19 |
'show_count' => $attributes['showTagCounts'], |
|
20 |
); |
|
21 |
$tag_cloud = wp_tag_cloud( $args ); |
|
22 |
|
|
23 |
if ( ! $tag_cloud ) { |
16
|
24 |
$labels = get_taxonomy_labels( get_taxonomy( $attributes['taxonomy'] ) ); |
|
25 |
$tag_cloud = esc_html( |
|
26 |
sprintf( |
|
27 |
/* translators: %s: taxonomy name */ |
|
28 |
__( 'Your site doesn’t have any %s, so there’s nothing to display here at the moment.' ), |
|
29 |
strtolower( $labels->name ) |
|
30 |
) |
|
31 |
); |
9
|
32 |
} |
|
33 |
|
18
|
34 |
$wrapper_attributes = get_block_wrapper_attributes(); |
|
35 |
|
9
|
36 |
return sprintf( |
18
|
37 |
'<p %1$s>%2$s</p>', |
|
38 |
$wrapper_attributes, |
9
|
39 |
$tag_cloud |
|
40 |
); |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* Registers the `core/tag-cloud` block on server. |
|
45 |
*/ |
|
46 |
function register_block_core_tag_cloud() { |
16
|
47 |
register_block_type_from_metadata( |
|
48 |
__DIR__ . '/tag-cloud', |
9
|
49 |
array( |
|
50 |
'render_callback' => 'render_block_core_tag_cloud', |
|
51 |
) |
|
52 |
); |
|
53 |
} |
|
54 |
add_action( 'init', 'register_block_core_tag_cloud' ); |