Skip to content
Closed
43 changes: 28 additions & 15 deletions src/wp-includes/author-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,29 @@ function the_author_meta( $field = '', $user_id = false ) {
* the author's name.
*
* @since 3.0.0
* @since 7.0.0 Added `$use_title_attr` parameter.
*
* @global WP_User $authordata The current author's data.
*
* @param bool $use_title_attr Optional. Whether to add a title attribute.
* Default true.
* @return string An HTML link if the author's URL exists in user meta,
* otherwise the result of get_the_author().
*/
function get_the_author_link() {
function get_the_author_link( $use_title_attr = true ) {
if ( get_the_author_meta( 'url' ) ) {
global $authordata;

$author_url = get_the_author_meta( 'url' );
$author_display_name = get_the_author();

/* translators: %s: Author's display name. */
$author_title = sprintf( __( 'Visit %s’s website' ), $author_display_name );

$link = sprintf(
'<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
'<a href="%1$s"%2$s rel="author external">%3$s</a>',
esc_url( $author_url ),
/* translators: %s: Author's display name. */
esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), $author_display_name ) ),
$use_title_attr ? ' title="' . esc_attr( $author_title ) . '"' : '',
$author_display_name
);

Expand Down Expand Up @@ -274,9 +279,13 @@ function get_the_author_link() {
* @link https://developer.wordpress.org/reference/functions/the_author_link/
*
* @since 2.1.0
* @since 7.0.0 Added `$use_title_attr` parameter.
*
* @param bool $use_title_attr Optional. Whether to add a title attribute.
* Default true.
*/
function the_author_link() {
echo get_the_author_link();
function the_author_link( $use_title_attr = true ) {
echo get_the_author_link( $use_title_attr );
}

/**
Expand Down Expand Up @@ -310,6 +319,7 @@ function the_author_posts() {
* Returns an HTML-formatted link using get_author_posts_url().
*
* @since 4.4.0
* @since 7.0.0 Removed title attribute.
*
* @global WP_User $authordata The current author's data.
*
Expand All @@ -322,22 +332,27 @@ function get_the_author_posts_link() {
return '';
}

$author = get_the_author();
/* translators: %s: Author's display name. */
$title = sprintf( __( 'Posts by %s' ), $author );

$link = sprintf(
'<a href="%1$s" title="%2$s" rel="author">%3$s</a>',
'<a href="%1$s" rel="author">%2$s</a>',
esc_url( get_author_posts_url( $authordata->ID, $authordata->user_nicename ) ),
/* translators: %s: Author's display name. */
esc_attr( sprintf( __( 'Posts by %s' ), get_the_author() ) ),
get_the_author()
$author
);

/**
* Filters the link to the author page of the author of the current post.
*
* @since 2.9.0
* @since 7.0.0 Added `$author` and `$title` parameters.
*
* @param string $link HTML link.
* @param string $link HTML link.
* @param string $author Author's display name.
* @param string $title Text originally used for a title attribute.
*/
return apply_filters( 'the_author_posts_link', $link );
return apply_filters( 'the_author_posts_link', $link, $author, $title );
}

/**
Expand Down Expand Up @@ -536,10 +551,8 @@ function wp_list_authors( $args = '' ) {
}

$link = sprintf(
'<a href="%1$s" title="%2$s">%3$s</a>',
'<a href="%1$s">%2$s</a>',
esc_url( get_author_posts_url( $author->ID, $author->user_nicename ) ),
/* translators: %s: Author's display name. */
esc_attr( sprintf( __( 'Posts by %s' ), $author->display_name ) ),
$name
);

Expand Down
2 changes: 0 additions & 2 deletions tests/phpunit/tests/user/getTheAuthorPostsLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public function test_get_the_author_posts_link_no_permalinks() {
$url = sprintf( 'http://%1$s/?author=%2$s', WP_TESTS_DOMAIN, $author->ID );

$this->assertStringContainsString( $url, $link );
$this->assertStringContainsString( 'Posts by Test Author', $link );
$this->assertStringContainsString( '>Test Author</a>', $link );

unset( $GLOBALS['authordata'] );
Expand All @@ -74,7 +73,6 @@ public function test_get_the_author_posts_link_with_permalinks() {
$this->set_permalink_structure( '' );

$this->assertStringContainsString( $url, $link );
$this->assertStringContainsString( 'Posts by Test Author', $link );
$this->assertStringContainsString( '>Test Author</a>', $link );

unset( $GLOBALS['authordata'] );
Expand Down
76 changes: 38 additions & 38 deletions tests/phpunit/tests/user/wpListAuthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {

public function test_wp_list_authors_default() {
$expected['default'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>';

$this->assertSame( $expected['default'], wp_list_authors( array( 'echo' => false ) ) );
}

public function test_wp_list_authors_orderby() {
$expected['post_count'] =
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>' .
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>';
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>' .
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>';

$this->assertSame(
$expected['post_count'],
Expand All @@ -113,9 +113,9 @@ public function test_wp_list_authors_orderby() {

public function test_wp_list_authors_order() {
$expected['id'] =
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>' .
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>';

$this->assertSame(
$expected['id'],
Expand All @@ -131,9 +131,9 @@ public function test_wp_list_authors_order() {

public function test_wp_list_authors_optioncount() {
$expected['optioncount'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (2)</li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (3)</li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (1)</li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a> (2)</li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a> (3)</li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a> (1)</li>';

$this->assertSame(
$expected['optioncount'],
Expand Down Expand Up @@ -180,10 +180,10 @@ public function test_wp_list_authors_exclude_admin() {
);

$expected['exclude_admin'] =
'<li><a href="' . get_author_posts_url( 1 ) . '" title="Posts by admin">admin</a></li>' .
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
'<li><a href="' . get_author_posts_url( 1 ) . '">admin</a></li>' .
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>';

$this->assertSame(
$expected['exclude_admin'],
Expand All @@ -198,9 +198,9 @@ public function test_wp_list_authors_exclude_admin() {

public function test_wp_list_authors_show_fullname() {
$expected['show_fullname'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob reno</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul norris</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack moon</a></li>';
'<li><a href="' . self::$user_urls[1] . '">bob reno</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul norris</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack moon</a></li>';

$this->assertSame(
$expected['show_fullname'],
Expand All @@ -217,10 +217,10 @@ public function test_wp_list_authors_hide_empty() {
$fred_id = self::$fred_id;

$expected['hide_empty'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . get_author_posts_url( $fred_id ) . '" title="Posts by fred">fred</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . get_author_posts_url( $fred_id ) . '">fred</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>';

$this->assertSame(
$expected['hide_empty'],
Expand All @@ -235,9 +235,9 @@ public function test_wp_list_authors_hide_empty() {

public function test_wp_list_authors_echo() {
$expected['echo'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a></li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a></li>';

$this->expectOutputString( $expected['echo'] );
wp_list_authors( array( 'echo' => true ) );
Expand All @@ -249,9 +249,9 @@ public function test_wp_list_authors_feed() {
$url2 = get_author_feed_link( self::$user_ids[2] );

$expected['feed'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';

$this->assertSame(
$expected['feed'],
Expand All @@ -270,9 +270,9 @@ public function test_wp_list_authors_feed_image() {
$url2 = get_author_feed_link( self::$user_ids[2] );

$expected['feed_image'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> <a href="' . $url1 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> <a href="' . $url2 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> <a href="' . $url0 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a> <a href="' . $url1 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a> <a href="' . $url2 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a> <a href="' . $url0 . '"><img src="http://' . WP_TESTS_DOMAIN . '/path/to/a/graphic.png" style="border: none;" /></a></li>';

$this->assertSame(
$expected['feed_image'],
Expand All @@ -294,9 +294,9 @@ public function test_wp_list_authors_feed_type() {
$url2 = get_author_feed_link( self::$user_ids[2], 'atom' );

$expected['feed_type'] =
'<li><a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';
'<li><a href="' . self::$user_urls[1] . '">bob</a> (<a href="' . $url1 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[2] . '">paul</a> (<a href="' . $url2 . '">link to feed</a>)</li>' .
'<li><a href="' . self::$user_urls[0] . '">zack</a> (<a href="' . $url0 . '">link to feed</a>)</li>';

$this->assertSame(
$expected['feed_type'],
Expand All @@ -312,9 +312,9 @@ public function test_wp_list_authors_feed_type() {

public function test_wp_list_authors_style() {
$expected['style'] =
'<a href="' . self::$user_urls[1] . '" title="Posts by bob">bob</a>, ' .
'<a href="' . self::$user_urls[2] . '" title="Posts by paul">paul</a>, ' .
'<a href="' . self::$user_urls[0] . '" title="Posts by zack">zack</a>';
'<a href="' . self::$user_urls[1] . '">bob</a>, ' .
'<a href="' . self::$user_urls[2] . '">paul</a>, ' .
'<a href="' . self::$user_urls[0] . '">zack</a>';

$this->assertSame(
$expected['style'],
Expand Down
Loading