diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 3cd21248b70df..417bd2ab5ceb2 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -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( - '%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 +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 ); } /** @@ -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. * @@ -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( - '%3$s', + '%2$s', 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 ); } /** @@ -536,10 +551,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'] = - '





