[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/ -> tag-cloud.php (source)

   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 ) {
  16      $smallest_font_size = $attributes['smallestFontSize'];
  17      $unit               = ( preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt' );
  18  
  19      $args      = array(
  20          'echo'       => false,
  21          'unit'       => $unit,
  22          'taxonomy'   => $attributes['taxonomy'],
  23          'show_count' => $attributes['showTagCounts'],
  24          'number'     => $attributes['numberOfTags'],
  25          'smallest'   => floatVal( $attributes['smallestFontSize'] ),
  26          'largest'    => floatVal( $attributes['largestFontSize'] ),
  27      );
  28      $tag_cloud = wp_tag_cloud( $args );
  29  
  30      if ( ! $tag_cloud ) {
  31          $tag_cloud = __( 'There&#8217;s no content to show here yet.' );
  32      }
  33  
  34      $wrapper_attributes = get_block_wrapper_attributes();
  35  
  36      return sprintf(
  37          '<p %1$s>%2$s</p>',
  38          $wrapper_attributes,
  39          $tag_cloud
  40      );
  41  }
  42  
  43  /**
  44   * Registers the `core/tag-cloud` block on server.
  45   */
  46  function register_block_core_tag_cloud() {
  47      register_block_type_from_metadata(
  48          __DIR__ . '/tag-cloud',
  49          array(
  50              'render_callback' => 'render_block_core_tag_cloud',
  51          )
  52      );
  53  }
  54  add_action( 'init', 'register_block_core_tag_cloud' );


Generated : Thu May 9 08:20:02 2024 Cross-referenced by PHPXref