# gutenberg/12.7.1/build/block-library/blocks/post-author-name.php

Gutenberg, version 12.7.1. 50 lines.

- Page: https://pluginprobe.com/plugins/gutenberg/12.7.1/code/build/block-library/blocks/post-author-name.php
- Raw: https://pluginprobe.com/plugins/gutenberg/12.7.1/raw/build/block-library/blocks/post-author-name.php
- Modified: 2022-02-02T16:18:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenberg/12.7.1/code/build/block-library/blocks/post-author-name.php#L10-L20`.

```php
<?php
/**
 * Server-side rendering of the `core/post-author-name` block.
 *
 * @package WordPress
 */

/**
 * Renders the `core/post-author-name` block on the server.
 *
 * @param  array    $attributes Block attributes.
 * @param  string   $content    Block default content.
 * @param  WP_Block $block      Block instance.
 * @return string Returns the rendered post author name block.
 */
function gutenberg_render_block_core_post_author_name( $attributes, $content, $block ) {
	if ( ! isset( $block->context['postId'] ) ) {
		return '';
	}

	$author_id = get_post_field( 'post_author', $block->context['postId'] );
	if ( empty( $author_id ) ) {
		return '';
	}

	$author_name      = get_the_author_meta( 'display_name', $author_id );
	$align_class_name = empty( $attributes['textAlign'] ) ? '' : "has-text-align-{$attributes['textAlign']}";

	if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
		$author_name = sprintf( '<a href="%1$s" target="%2$s" class="wp-block-author-name__link">%3$s</a>', get_author_posts_url( $author_id ), esc_attr( $attributes['linkTarget'] ), $author_name );
	}

	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $align_class_name ) );

	return sprintf( '<div %1$s>', $wrapper_attributes ) . $author_name . '</div>';
}

/**
 * Registers the `core/post-author-name` block on the server.
 */
function gutenberg_register_block_core_post_author_name() {
	register_block_type_from_metadata(
		__DIR__ . '/post-author-name',
		array(
			'render_callback' => 'gutenberg_render_block_core_post_author_name',
		)
	);
}
add_action( 'init', 'gutenberg_register_block_core_post_author_name', 20 );

```
