Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/wp-includes/author-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -336,11 +336,17 @@ function get_the_author_posts_link() {
/* translators: %s: Author's display name. */
$title = sprintf( __( 'Posts by %s' ), $author );

$link = sprintf(
'<a href="%1$s" rel="author">%2$s</a>',
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(
'<a href="%1$s" rel="author">%2$s</a>',
esc_url( $url ),
$author
);
}

/**
* Filters the link to the author page of the author of the current post.
Expand Down
39 changes: 39 additions & 0 deletions tests/phpunit/tests/user/getTheAuthorPostsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,43 @@ 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 );
}
}
Loading