PluginProbe
Gutenberg / 18.9.0
Gutenberg v18.9.0
24.0.0 23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 All 403 releases
gutenberg / build / block-library / blocks / tag-cloud.php

tag-cloud.php in Gutenberg 18.9.0, at build/block-library/blocks/tag-cloud.php

59 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 * @since 5.2.0
12 *
13 * @param array $attributes The block attributes.
14 *
15 * @return string Returns the tag cloud for selected taxonomy.
16 */
17 function gutenberg_render_block_core_tag_cloud( $attributes ) {
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
21 $args = array(
22 'echo' => false,
23 'unit' => $unit,
24 'taxonomy' => $attributes['taxonomy'],
25 'show_count' => $attributes['showTagCounts'],
26 'number' => $attributes['numberOfTags'],
27 'smallest' => floatVal( $attributes['smallestFontSize'] ),
28 'largest' => floatVal( $attributes['largestFontSize'] ),
29 );
30 $tag_cloud = wp_tag_cloud( $args );
31
32 if ( ! $tag_cloud ) {
33 $tag_cloud = __( 'There&#8217;s no content to show here yet.' );
34 }
35
36 $wrapper_attributes = get_block_wrapper_attributes();
37
38 return sprintf(
39 '<p %1$s>%2$s</p>',
40 $wrapper_attributes,
41 $tag_cloud
42 );
43 }
44
45 /**
46 * Registers the `core/tag-cloud` block on server.
47 *
48 * @since 5.2.0
49 */
50 function gutenberg_register_block_core_tag_cloud() {
51 register_block_type_from_metadata(
52 __DIR__ . '/tag-cloud',
53 array(
54 'render_callback' => 'gutenberg_render_block_core_tag_cloud',
55 )
56 );
57 }
58 add_action( 'init', 'gutenberg_register_block_core_tag_cloud', 20 );
59