From 974ca8d18a65c9f73ab28b22f99e2f1232664bdf Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Mon, 6 Jul 2026 17:30:23 +0530 Subject: [PATCH 1/3] Themes: Don't return anchor tag if link is empty in get_the_author_posts_link(). --- src/wp-includes/author-template.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 4c715a62b51f1..08dbaca00e6b3 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -323,7 +323,7 @@ function the_author_posts() { * * @global WP_User $authordata The current author's data. * - * @return string An HTML link to the author page, or an empty string if $authordata is not set. + * @return string An HTML link to the author page, or just the author's display name if the URL is empty, or an empty string if $authordata is not set. */ function get_the_author_posts_link() { global $authordata; @@ -336,11 +336,17 @@ function get_the_author_posts_link() { /* translators: %s: Author's display name. */ $title = sprintf( __( 'Posts by %s' ), $author ); - $link = sprintf( - '', - esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ), - $author - ); + $url = get_author_posts_url( $authordata->ID, $authordata->user_nicename ); + + if ( empty( $url ) || 'http://' === $url ) { + $link = $author; + } else { + $link = sprintf( + '', + esc_url( $url ), + $author + ); + } /** * Filters the link to the author page of the author of the current post. From 77ae71aa62e4583ff758657b398af97158155540 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Mon, 6 Jul 2026 17:37:04 +0530 Subject: [PATCH 2/3] Themes: Tests for get_the_author_posts_link() --- .../tests/user/getTheAuthorPostsLink.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/tests/phpunit/tests/user/getTheAuthorPostsLink.php b/tests/phpunit/tests/user/getTheAuthorPostsLink.php index fdef10d12a445..ea5f7fba97467 100644 --- a/tests/phpunit/tests/user/getTheAuthorPostsLink.php +++ b/tests/phpunit/tests/user/getTheAuthorPostsLink.php @@ -86,4 +86,40 @@ public function test_get_the_author_posts_link_should_return_empty_string_if_aut $this->assertSame( '', get_the_author_posts_link() ); } + + /** + * @ticket 39844 + */ + public function test_get_the_author_posts_link_returns_author_name_when_url_is_empty() { + $author = get_userdata( self::$author_id ); + + $GLOBALS['authordata'] = $author; + + add_filter( 'author_link', '__return_empty_string' ); + $link = get_the_author_posts_link(); + remove_filter( 'author_link', '__return_empty_string' ); + + unset( $GLOBALS['authordata'] ); + + $this->assertSame( 'Test Author', $link ); + } + + /** + * @ticket 39844 + */ + public function test_get_the_author_posts_link_returns_author_name_when_url_is_http_placeholder() { + $author = get_userdata( self::$author_id ); + + $GLOBALS['authordata'] = $author; + + add_filter( 'author_link', static function () { + return 'http://'; + } ); + $link = get_the_author_posts_link(); + remove_all_filters( 'author_link' ); + + unset( $GLOBALS['authordata'] ); + + $this->assertSame( 'Test Author', $link ); + } } From 2677c13e2adcc97cedc1e1208ec9702f7ffd2c17 Mon Sep 17 00:00:00 2001 From: Sainath Poojary Date: Wed, 8 Jul 2026 07:38:58 +0530 Subject: [PATCH 3/3] Themes: Fixed PHPCS error --- tests/phpunit/tests/user/getTheAuthorPostsLink.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/user/getTheAuthorPostsLink.php b/tests/phpunit/tests/user/getTheAuthorPostsLink.php index ea5f7fba97467..9e88fd96cc8c1 100644 --- a/tests/phpunit/tests/user/getTheAuthorPostsLink.php +++ b/tests/phpunit/tests/user/getTheAuthorPostsLink.php @@ -112,9 +112,12 @@ public function test_get_the_author_posts_link_returns_author_name_when_url_is_h $GLOBALS['authordata'] = $author; - add_filter( 'author_link', static function () { - return 'http://'; - } ); + add_filter( + 'author_link', + static function () { + return 'http://'; + } + ); $link = get_the_author_posts_link(); remove_all_filters( 'author_link' );