[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/blocks/ -> post-author-biography.php (source)

   1  <?php
   2  /**
   3   * Server-side rendering of the `core/post-author-biography` block.
   4   *
   5   * @package WordPress
   6   */
   7  
   8  /**
   9   * Renders the `core/post-author-biography` block on the server.
  10   *
  11   * @param  array    $attributes Block attributes.
  12   * @param  string   $content    Block default content.
  13   * @param  WP_Block $block      Block instance.
  14   * @return string Returns the rendered post author biography block.
  15   */
  16  function render_block_core_post_author_biography( $attributes, $content, $block ) {
  17      if ( ! isset( $block->context['postId'] ) ) {
  18          return '';
  19      }
  20  
  21      $author_id = get_post_field( 'post_author', $block->context['postId'] );
  22      if ( empty( $author_id ) ) {
  23          return '';
  24      }
  25  
  26      $author_biography = get_the_author_meta( 'description', $author_id );
  27      if ( empty( $author_biography ) ) {
  28          return '';
  29      }
  30  
  31      $align_class_name   = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";
  32      $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );
  33  
  34      return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_biography . '</div>';
  35  }
  36  
  37  /**
  38   * Registers the `core/post-author-biography` block on the server.
  39   */
  40  function register_block_core_post_author_biography() {
  41      register_block_type_from_metadata(
  42          __DIR__ . '/post-author-biography',
  43          array(
  44              'render_callback' => 'render_block_core_post_author_biography',
  45          )
  46      );
  47  }
  48  add_action( 'init', 'register_block_core_post_author_biography' );


Generated: Sun Dec 22 01:00:02 2024 Cross-referenced by PHPXref 0.7.1