1 | <?php
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | function render_block_core_tag_cloud( $attributes ) {
|
16 | $class = isset( $attributes['align'] ) ?
|
17 | "wp-block-tag-cloud align{$attributes['align']}" :
|
18 | 'wp-block-tag-cloud';
|
19 |
|
20 | if ( isset( $attributes['className'] ) ) {
|
21 | $class .= ' ' . $attributes['className'];
|
22 | }
|
23 |
|
24 | $args = array(
|
25 | 'echo' => false,
|
26 | 'taxonomy' => $attributes['taxonomy'],
|
27 | 'show_count' => $attributes['showTagCounts'],
|
28 | );
|
29 |
|
30 | $tag_cloud = wp_tag_cloud( $args );
|
31 |
|
32 | if ( ! $tag_cloud ) {
|
33 | $tag_cloud = esc_html( __( 'No terms to show.' ) );
|
34 | }
|
35 |
|
36 | return sprintf(
|
37 | '<p class="%1$s">%2$s</p>',
|
38 | esc_attr( $class ),
|
39 | $tag_cloud
|
40 | );
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 | function register_block_core_tag_cloud() {
|
47 | register_block_type(
|
48 | 'core/tag-cloud',
|
49 | array(
|
50 | 'attributes' => array(
|
51 | 'taxonomy' => array(
|
52 | 'type' => 'string',
|
53 | 'default' => 'post_tag',
|
54 | ),
|
55 | 'className' => array(
|
56 | 'type' => 'string',
|
57 | ),
|
58 | 'showTagCounts' => array(
|
59 | 'type' => 'boolean',
|
60 | 'default' => false,
|
61 | ),
|
62 | 'align' => array(
|
63 | 'type' => 'string',
|
64 | ),
|
65 | ),
|
66 | 'render_callback' => 'render_block_core_tag_cloud',
|
67 | )
|
68 | );
|
69 | }
|
70 |
|
71 | add_action( 'init', 'register_block_core_tag_cloud' );
|