[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/blocks/ -> term-description.php (source)

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/term-description` block.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Renders the `core/term-description` block on the server.
  10   *
  11   * @since 5.9.0
  12   *
  13   * @param array $attributes Block attributes.
  14   *
  15   * @return string Returns the description of the current taxonomy term, if available
  16   */
  17  function render_block_core_term_description( $attributes ) {
  18      $term_description = '';
  19  
  20      if ( is_category() || is_tag() || is_tax() ) {
  21          $term_description = term_description();
  22      }
  23  
  24      if ( empty( $term_description ) ) {
  25          return '';
  26      }
  27  
  28      $classes = array();
  29      if ( isset( $attributes['textAlign'] ) ) {
  30          $classes[] = 'has-text-align-' . $attributes['textAlign'];
  31      }
  32      if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
  33          $classes[] = 'has-link-color';
  34      }
  35      $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
  36  
  37      return '<div ' . $wrapper_attributes . '>' . $term_description . '</div>';
  38  }
  39  
  40  /**
  41   * Registers the `core/term-description` block on the server.
  42   *
  43   * @since 5.9.0
  44   */
  45  function register_block_core_term_description() {
  46      register_block_type_from_metadata(
  47          __DIR__ . '/term-description',
  48          array(
  49              'render_callback' => 'render_block_core_term_description',
  50          )
  51      );
  52  }
  53  add_action( 'init', 'register_block_core_term_description' );


Generated : Sat Nov 23 08:20:01 2024 Cross-referenced by PHPXref