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 (#55451)

* Author, Author Bio, Author Name: Add a fallback for Author Archive Template

* Use ternary operators

* Use positive conditionals

* Fix typo

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: aaronrobertshaw <[email protected]>
  • Loading branch information
3 people authored Feb 20, 2024
1 parent 0dc55a8 commit 189e23b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 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
7 changes: 4 additions & 3 deletions packages/block-library/src/post-author-biography/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
* @return string Returns the rendered post author biography block.
*/
function render_block_core_post_author_biography( $attributes, $content, $block ) {
if ( ! isset( $block->context['postId'] ) ) {
return '';
if ( isset( $block->context['postId'] ) ) {
$author_id = get_post_field( 'post_author', $block->context['postId'] );
} else {
$author_id = get_query_var( 'author' );
}

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

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

1 comment on commit 189e23b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 189e23b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7968698322
📝 Reported issues:

Please sign in to comment.