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..23f5f16cbcf45 100644 --- a/packages/block-library/src/post-author-biography/index.php +++ b/packages/block-library/src/post-author-biography/index.php @@ -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 ''; } diff --git a/packages/block-library/src/post-author-name/index.php b/packages/block-library/src/post-author-name/index.php index c5c6d142e06dd..a5fadfcbf33c1 100644 --- a/packages/block-library/src/post-author-name/index.php +++ b/packages/block-library/src/post-author-name/index.php @@ -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 ''; }