term-description.php 1.1 KB

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