Nenhuma Descrição

post-author.php 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Server-side rendering of the `core/post-author` block.
  4. *
  5. * @package WordPress
  6. */
  7. /**
  8. * Renders the `core/post-author` block on the server.
  9. *
  10. * @param array $attributes Block attributes.
  11. * @param string $content Block default content.
  12. * @param WP_Block $block Block instance.
  13. * @return string Returns the rendered author block.
  14. */
  15. function render_block_core_post_author( $attributes, $content, $block ) {
  16. if ( ! isset( $block->context['postId'] ) ) {
  17. return '';
  18. }
  19. $author_id = get_post_field( 'post_author', $block->context['postId'] );
  20. if ( empty( $author_id ) ) {
  21. return '';
  22. }
  23. $avatar = ! empty( $attributes['avatarSize'] ) ? get_avatar(
  24. $author_id,
  25. $attributes['avatarSize']
  26. ) : null;
  27. $byline = ! empty( $attributes['byline'] ) ? $attributes['byline'] : false;
  28. $classes = array_merge(
  29. isset( $attributes['itemsJustification'] ) ? array( 'items-justified-' . $attributes['itemsJustification'] ) : array(),
  30. isset( $attributes['textAlign'] ) ? array( 'has-text-align-' . $attributes['textAlign'] ) : array()
  31. );
  32. $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
  33. return sprintf( '<div %1$s>', $wrapper_attributes ) .
  34. ( ! empty( $attributes['showAvatar'] ) ? '<div class="wp-block-post-author__avatar">' . $avatar . '</div>' : '' ) .
  35. '<div class="wp-block-post-author__content">' .
  36. ( ! empty( $byline ) ? '<p class="wp-block-post-author__byline">' . wp_kses_post( $byline ) . '</p>' : '' ) .
  37. '<p class="wp-block-post-author__name">' . get_the_author_meta( 'display_name', $author_id ) . '</p>' .
  38. ( ! empty( $attributes['showBio'] ) ? '<p class="wp-block-post-author__bio">' . get_the_author_meta( 'user_description', $author_id ) . '</p>' : '' ) .
  39. '</div>' .
  40. '</div>';
  41. }
  42. /**
  43. * Registers the `core/post-author` block on the server.
  44. */
  45. function register_block_core_post_author() {
  46. register_block_type_from_metadata(
  47. __DIR__ . '/post-author',
  48. array(
  49. 'render_callback' => 'render_block_core_post_author',
  50. )
  51. );
  52. }
  53. add_action( 'init', 'register_block_core_post_author' );