diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 3cd21248b70df..b0279f749e944 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -229,24 +229,28 @@ function the_author_meta( $field = '', $user_id = false ) { * the author's name. * * @since 3.0.0 + * @since 6.8.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( - '%3$s', + '%3$s', esc_url( $author_url ), - /* translators: %s: Author's display name. */ - esc_attr( sprintf( __( 'Visit %s’s website' ), $author_display_name ) ), + $use_title_attr ? ' title="' . esc_attr( $author_title ) . '"' : '', $author_display_name ); @@ -274,9 +278,13 @@ function get_the_author_link() { * @link https://developer.wordpress.org/reference/functions/the_author_link/ * * @since 2.1.0 + * @since 6.8.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 ); } /** @@ -323,10 +331,8 @@ function get_the_author_posts_link() { } $link = sprintf( - '', + '', 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() ); @@ -536,10 +542,8 @@ function wp_list_authors( $args = '' ) { } $link = sprintf( - '%3$s', + '%2$s', 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 ); diff --git a/tests/phpunit/tests/user/getTheAuthorPostsLink.php b/tests/phpunit/tests/user/getTheAuthorPostsLink.php index 3fd96774df57e..fdef10d12a445 100644 --- a/tests/phpunit/tests/user/getTheAuthorPostsLink.php +++ b/tests/phpunit/tests/user/getTheAuthorPostsLink.php @@ -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', $link ); unset( $GLOBALS['authordata'] ); @@ -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', $link ); unset( $GLOBALS['authordata'] ); diff --git a/tests/phpunit/tests/user/wpListAuthors.php b/tests/phpunit/tests/user/wpListAuthors.php index f05e534b551cc..3c79f8fee3a6c 100644 --- a/tests/phpunit/tests/user/wpListAuthors.php +++ b/tests/phpunit/tests/user/wpListAuthors.php @@ -87,18 +87,18 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { public function test_wp_list_authors_default() { $expected['default'] = - '
  • bob
  • ' . - '
  • paul
  • ' . - '
  • zack
  • '; + '
  • bob
  • ' . + '
  • paul
  • ' . + '
  • zack
  • '; $this->assertSame( $expected['default'], wp_list_authors( array( 'echo' => false ) ) ); } public function test_wp_list_authors_orderby() { $expected['post_count'] = - '
  • zack
  • ' . - '
  • bob
  • ' . - '
  • paul
  • '; + '
  • zack
  • ' . + '
  • bob
  • ' . + '
  • paul
  • '; $this->assertSame( $expected['post_count'], @@ -113,9 +113,9 @@ public function test_wp_list_authors_orderby() { public function test_wp_list_authors_order() { $expected['id'] = - '
  • paul
  • ' . - '
  • bob
  • ' . - '
  • zack
  • '; + '
  • paul
  • ' . + '
  • bob
  • ' . + '
  • zack
  • '; $this->assertSame( $expected['id'], @@ -131,9 +131,9 @@ public function test_wp_list_authors_order() { public function test_wp_list_authors_optioncount() { $expected['optioncount'] = - '
  • bob (2)
  • ' . - '
  • paul (3)
  • ' . - '
  • zack (1)
  • '; + '
  • bob (2)
  • ' . + '
  • paul (3)
  • ' . + '
  • zack (1)
  • '; $this->assertSame( $expected['optioncount'], @@ -180,10 +180,10 @@ public function test_wp_list_authors_exclude_admin() { ); $expected['exclude_admin'] = - '
  • admin
  • ' . - '
  • bob
  • ' . - '
  • paul
  • ' . - '
  • zack
  • '; + '
  • admin
  • ' . + '
  • bob
  • ' . + '
  • paul
  • ' . + '
  • zack
  • '; $this->assertSame( $expected['exclude_admin'], @@ -198,9 +198,9 @@ public function test_wp_list_authors_exclude_admin() { public function test_wp_list_authors_show_fullname() { $expected['show_fullname'] = - '
  • bob reno
  • ' . - '
  • paul norris
  • ' . - '
  • zack moon
  • '; + '
  • bob reno
  • ' . + '
  • paul norris
  • ' . + '
  • zack moon
  • '; $this->assertSame( $expected['show_fullname'], @@ -217,10 +217,10 @@ public function test_wp_list_authors_hide_empty() { $fred_id = self::$fred_id; $expected['hide_empty'] = - '
  • bob
  • ' . - '
  • fred
  • ' . - '
  • paul
  • ' . - '
  • zack
  • '; + '
  • bob
  • ' . + '
  • fred
  • ' . + '
  • paul
  • ' . + '
  • zack
  • '; $this->assertSame( $expected['hide_empty'], @@ -235,9 +235,9 @@ public function test_wp_list_authors_hide_empty() { public function test_wp_list_authors_echo() { $expected['echo'] = - '
  • bob
  • ' . - '
  • paul
  • ' . - '
  • zack
  • '; + '
  • bob
  • ' . + '
  • paul
  • ' . + '
  • zack
  • '; $this->expectOutputString( $expected['echo'] ); wp_list_authors( array( 'echo' => true ) ); @@ -249,9 +249,9 @@ public function test_wp_list_authors_feed() { $url2 = get_author_feed_link( self::$user_ids[2] ); $expected['feed'] = - '
  • bob (link to feed)
  • ' . - '
  • paul (link to feed)
  • ' . - '
  • zack (link to feed)
  • '; + '
  • bob (link to feed)
  • ' . + '
  • paul (link to feed)
  • ' . + '
  • zack (link to feed)
  • '; $this->assertSame( $expected['feed'], @@ -270,9 +270,9 @@ public function test_wp_list_authors_feed_image() { $url2 = get_author_feed_link( self::$user_ids[2] ); $expected['feed_image'] = - '
  • bob
  • ' . - '
  • paul
  • ' . - '
  • zack
  • '; + '
  • bob
  • ' . + '
  • paul
  • ' . + '
  • zack
  • '; $this->assertSame( $expected['feed_image'], @@ -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'] = - '
  • bob (link to feed)
  • ' . - '
  • paul (link to feed)
  • ' . - '
  • zack (link to feed)
  • '; + '
  • bob (link to feed)
  • ' . + '
  • paul (link to feed)
  • ' . + '
  • zack (link to feed)
  • '; $this->assertSame( $expected['feed_type'], @@ -312,9 +312,9 @@ public function test_wp_list_authors_feed_type() { public function test_wp_list_authors_style() { $expected['style'] = - 'bob, ' . - 'paul, ' . - 'zack'; + 'bob, ' . + 'paul, ' . + 'zack'; $this->assertSame( $expected['style'],