Skip to content

Commit

Permalink
Author, Author Bio, Author Name: Add a fallback for Author Archive Te…
Browse files Browse the repository at this point in the history
…mplate
  • Loading branch information
t-hamano committed Oct 18, 2023
1 parent a8f3aca commit 536351c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
13 changes: 12 additions & 1 deletion packages/block-library/src/avatar/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,18 @@ function render_block_core_avatar( $attributes, $content, $block ) {
: '';

if ( ! isset( $block->context['commentId'] ) ) {
$author_id = isset( $attributes['userId'] ) ? $attributes['userId'] : get_post_field( 'post_author', $block->context['postId'] );
if ( isset( $attributes['userId'] ) ) {
$author_id = $attributes['userId'];
} elseif ( isset( $block->context['postId'] ) ) {
$author_id = get_post_field( 'post_author', $block->context['postId'] );
} else {
$author_id = get_query_var( 'author' );
}

if ( empty( $author_id ) ) {
return '';
}

$author_name = get_the_author_meta( 'display_name', $author_id );
// translators: %s is the Author name.
$alt = sprintf( __( '%s Avatar' ), $author_name );
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/post-author-biography/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
function render_block_core_post_author_biography( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
$author_id = get_query_var( 'author' );
} else {
$author_id = get_post_field( 'post_author', $block->context['postId'] );
}

$author_id = get_post_field( 'post_author', $block->context['postId'] );
if ( empty( $author_id ) ) {
return '';
}
Expand Down
5 changes: 3 additions & 2 deletions packages/block-library/src/post-author-name/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
function render_block_core_post_author_name( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
$author_id = get_query_var( 'author' );
} else {
$author_id = get_post_field( 'post_author', $block->context['postId'] );
}

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

0 comments on commit 536351c

Please sign in to comment.