From 56ea718a2d7e726e0fa645e5bde98be1f17bd0bd Mon Sep 17 00:00:00 2001 From: "Stephen A. Bernhardt" Date: Wed, 6 Dec 2023 09:24:31 -0600 Subject: [PATCH 1/5] Simply remove title attributes from the links --- src/wp-includes/author-template.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 184d7d0f38954..db7f814a56be4 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -238,10 +238,8 @@ function get_the_author_link() { $author_display_name = get_the_author(); $link = sprintf( - '%3$s', + '%2$s', esc_url( $author_url ), - /* translators: %s: Author's display name. */ - esc_attr( sprintf( __( 'Visit %s’s website' ), $author_display_name ) ), $author_display_name ); @@ -318,10 +316,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() ); @@ -531,10 +527,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 ); From d35da72678c0bb64bccac3e5119f8ba3daa68d12 Mon Sep 17 00:00:00 2001 From: "Stephen A. Bernhardt" Date: Wed, 6 Dec 2023 10:30:50 -0600 Subject: [PATCH 2/5] Update unit tests for `wp_list_authors()` --- tests/phpunit/tests/user/wpListAuthors.php | 76 +++++++++++----------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/tests/phpunit/tests/user/wpListAuthors.php b/tests/phpunit/tests/user/wpListAuthors.php index 90a22e39d9edf..8b8a91d06722b 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'], From 3cc8474a6ae9351484391c725c96257c1c73ac3b Mon Sep 17 00:00:00 2001 From: "Stephen A. Bernhardt" Date: Wed, 6 Dec 2023 12:44:50 -0600 Subject: [PATCH 3/5] Update author posts link tests --- tests/phpunit/tests/user/getTheAuthorPostsLink.php | 2 -- 1 file changed, 2 deletions(-) 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'] ); From dd96342c032d164662a35a51e007232ad237c8ea Mon Sep 17 00:00:00 2001 From: "Stephen A. Bernhardt" Date: Tue, 21 Jan 2025 00:41:26 -0600 Subject: [PATCH 4/5] Remove `$author_display_name` variable --- src/wp-includes/author-template.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index db7f814a56be4..b747667e6697d 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -234,13 +234,12 @@ function get_the_author_link() { if ( get_the_author_meta( 'url' ) ) { global $authordata; - $author_url = get_the_author_meta( 'url' ); - $author_display_name = get_the_author(); + $author_url = get_the_author_meta( 'url' ); $link = sprintf( '%2$s', esc_url( $author_url ), - $author_display_name + get_the_author() ); /** From f9759fcc3b20d39458f89c20d81e30aba61b1d78 Mon Sep 17 00:00:00 2001 From: "Stephen A. Bernhardt" Date: Wed, 22 Jan 2025 13:05:56 -0600 Subject: [PATCH 5/5] Add `$use_title_attr` parameter for website link --- src/wp-includes/author-template.php | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index b747667e6697d..4a8775d92e2cc 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -224,22 +224,29 @@ 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_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( - '%2$s', + '%3$s', esc_url( $author_url ), - get_the_author() + $use_title_attr ? ' title="' . esc_attr( $author_title ) . '"' : '', + $author_display_name ); /** @@ -266,9 +273,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 ); } /**