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