Skip to content

Commit 189e23b

Browse files
Author, Author Bio, Author Name: Add a fallback for Author Archive Template (#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 <wildworks@git.wordpress.org> Co-authored-by: aaronrobertshaw <aaronrobertshaw@git.wordpress.org>
1 parent 0dc55a8 commit 189e23b

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

packages/block-library/src/avatar/index.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,18 @@ function render_block_core_avatar( $attributes, $content, $block ) {
3131
: '';
3232

3333
if ( ! isset( $block->context['commentId'] ) ) {
34-
$author_id = isset( $attributes['userId'] ) ? $attributes['userId'] : get_post_field( 'post_author', $block->context['postId'] );
34+
if ( isset( $attributes['userId'] ) ) {
35+
$author_id = $attributes['userId'];
36+
} elseif ( isset( $block->context['postId'] ) ) {
37+
$author_id = get_post_field( 'post_author', $block->context['postId'] );
38+
} else {
39+
$author_id = get_query_var( 'author' );
40+
}
41+
42+
if ( empty( $author_id ) ) {
43+
return '';
44+
}
45+
3546
$author_name = get_the_author_meta( 'display_name', $author_id );
3647
// translators: %s is the Author name.
3748
$alt = sprintf( __( '%s Avatar' ), $author_name );

packages/block-library/src/post-author-biography/index.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* @return string Returns the rendered post author biography block.
1515
*/
1616
function render_block_core_post_author_biography( $attributes, $content, $block ) {
17-
if ( ! isset( $block->context['postId'] ) ) {
18-
return '';
17+
if ( isset( $block->context['postId'] ) ) {
18+
$author_id = get_post_field( 'post_author', $block->context['postId'] );
19+
} else {
20+
$author_id = get_query_var( 'author' );
1921
}
2022

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

packages/block-library/src/post-author-name/index.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
* @return string Returns the rendered post author name block.
1515
*/
1616
function render_block_core_post_author_name( $attributes, $content, $block ) {
17-
if ( ! isset( $block->context['postId'] ) ) {
18-
return '';
17+
if ( isset( $block->context['postId'] ) ) {
18+
$author_id = get_post_field( 'post_author', $block->context['postId'] );
19+
} else {
20+
$author_id = get_query_var( 'author' );
1921
}
2022

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

0 commit comments

Comments
 (0)