Formatting: Make `get_the_author_link` pluggable.

Adds a new filter to alter the output of `get_the_author_link`.  This change also adds unit tests for the new filter.

Props dshanske, donmhico, audrasjb, peterwilsoncc, SergeyBiryukov.
Fixes #51859.
Built from https://develop.svn.wordpress.org/trunk@53147


git-svn-id: http://core.svn.wordpress.org/trunk@52736 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
davidbaumwald 2022-04-11 23:38:08 +00:00
parent fcb19b1c42
commit ce4a2a11de
2 changed files with 23 additions and 5 deletions

View File

@ -224,18 +224,36 @@ function the_author_meta( $field = '', $user_id = false ) {
*
* @since 3.0.0
*
* @global WP_User $authordata The current author's data.
*
* @return string|null An HTML link if the author's url exist in user meta,
* else the result of get_the_author().
*/
function get_the_author_link() {
if ( get_the_author_meta( 'url' ) ) {
return sprintf(
global $authordata;
$author_url = get_the_author_meta( 'url' );
$author_display_name = get_the_author();
$link = sprintf(
'<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
esc_url( get_the_author_meta( 'url' ) ),
esc_url( $author_url ),
/* translators: %s: Author's display name. */
esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), get_the_author() ) ),
get_the_author()
esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), $author_display_name ) ),
$author_display_name
);
/**
* Filters the author URL link HTML.
*
* @since 6.0.0
*
* @param string $link The default rendered author HTML link.
* @param string $author_url Author's URL.
* @param WP_User $authordata Author user data.
*/
return apply_filters( 'the_author_link', $link, $author_url, $authordata );
} else {
return get_the_author();
}

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.0-alpha-53146';
$wp_version = '6.0-alpha-53147';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.