diff --git a/packages/block-library/src/avatar/index.php b/packages/block-library/src/avatar/index.php index d404fb81ca357..303b35458eb1a 100644 --- a/packages/block-library/src/avatar/index.php +++ b/packages/block-library/src/avatar/index.php @@ -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 ); diff --git a/packages/block-library/src/post-author-biography/index.php b/packages/block-library/src/post-author-biography/index.php index 3ea6ecbd9b46a..7381e7a5d229b 100644 --- a/packages/block-library/src/post-author-biography/index.php +++ b/packages/block-library/src/post-author-biography/index.php @@ -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 ''; } diff --git a/packages/block-library/src/post-author-name/index.php b/packages/block-library/src/post-author-name/index.php index c5c6d142e06dd..8f2c035b093b6 100644 --- a/packages/block-library/src/post-author-name/index.php +++ b/packages/block-library/src/post-author-name/index.php @@ -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 ''; }