diff --git a/src/wp-includes/author-template.php b/src/wp-includes/author-template.php index 184d7d0f38954..f838753d40a1a 100644 --- a/src/wp-includes/author-template.php +++ b/src/wp-includes/author-template.php @@ -224,24 +224,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 ); @@ -269,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 ); } /** @@ -305,23 +313,27 @@ function the_author_posts() { * Returns an HTML-formatted link using get_author_posts_url(). * * @since 4.4.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 to the author page, or an empty string if $authordata is not set. */ -function get_the_author_posts_link() { +function get_the_author_posts_link( $use_title_attr = true ) { global $authordata; if ( ! is_object( $authordata ) ) { return ''; } + /* translators: %s: Author's display name. */ + $author_title = sprintf( __( 'Posts by %s' ), get_the_author() ); + $link = sprintf( - '%3$s', + '%3$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() ) ), + $use_title_attr ? ' title="' . esc_attr( $author_title ) . '"' : '', get_the_author() ); @@ -339,15 +351,18 @@ function get_the_author_posts_link() { * Displays an HTML link to the author page of the current post's author. * * @since 1.2.0 - * @since 4.4.0 Converted into a wrapper for get_the_author_posts_link() + * @since 4.4.0 Converted into a wrapper for get_the_author_posts_link(). + * @since 6.8.0 Added `$use_title_attr` parameter. * - * @param string $deprecated Unused. + * @param bool $use_title_attr Optional. Whether to add a title attribute. Default true. */ -function the_author_posts_link( $deprecated = '' ) { - if ( ! empty( $deprecated ) ) { - _deprecated_argument( __FUNCTION__, '2.1.0' ); +function the_author_posts_link( $use_title_attr = true ) { + // Avoid conflict from deprecated `$idmode` string parameter. + if ( false !== $use_title_attr ) { + $use_title_attr = true; } - echo get_the_author_posts_link(); + + echo get_the_author_posts_link( $use_title_attr ); } /** @@ -407,27 +422,28 @@ function get_author_posts_url( $author_id, $author_nicename = '' ) { * @param string|array $args { * Optional. Array or string of default arguments. * - * @type string $orderby How to sort the authors. Accepts 'nicename', 'email', 'url', 'registered', - * 'user_nicename', 'user_email', 'user_url', 'user_registered', 'name', - * 'display_name', 'post_count', 'ID', 'meta_value', 'user_login'. Default 'name'. - * @type string $order Sorting direction for $orderby. Accepts 'ASC', 'DESC'. Default 'ASC'. - * @type int $number Maximum authors to return or display. Default empty (all authors). - * @type bool $optioncount Show the count in parenthesis next to the author's name. Default false. - * @type bool $exclude_admin Whether to exclude the 'admin' account, if it exists. Default true. - * @type bool $show_fullname Whether to show the author's full name. Default false. - * @type bool $hide_empty Whether to hide any authors with no posts. Default true. - * @type string $feed If not empty, show a link to the author's feed and use this text as the alt - * parameter of the link. Default empty. - * @type string $feed_image If not empty, show a link to the author's feed and use this image URL as - * clickable anchor. Default empty. - * @type string $feed_type The feed type to link to. Possible values include 'rss2', 'atom'. - * Default is the value of get_default_feed(). - * @type bool $echo Whether to output the result or instead return it. Default true. - * @type string $style If 'list', each author is wrapped in an `