Make WordPress Core


Ignore:
Timestamp:
04/11/2022 11:36:56 PM (18 months ago)
Author:
davidbaumwald
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/author-template.php

    r52568 r53147  
    225225 * @since 3.0.0
    226226 *
     227 * @global WP_User $authordata The current author's data.
     228 *
    227229 * @return string|null An HTML link if the author's url exist in user meta,
    228230 *                     else the result of get_the_author().
     
    230232function get_the_author_link() {
    231233    if ( get_the_author_meta( 'url' ) ) {
    232         return sprintf(
     234        global $authordata;
     235
     236        $author_url          = get_the_author_meta( 'url' );
     237        $author_display_name = get_the_author();
     238
     239        $link = sprintf(
    233240            '<a href="%1$s" title="%2$s" rel="author external">%3$s</a>',
    234             esc_url( get_the_author_meta( 'url' ) ),
     241            esc_url( $author_url ),
    235242            /* translators: %s: Author's display name. */
    236             esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), get_the_author() ) ),
    237             get_the_author()
     243            esc_attr( sprintf( __( 'Visit %s&#8217;s website' ), $author_display_name ) ),
     244            $author_display_name
    238245        );
     246
     247        /**
     248         * Filters the author URL link HTML.
     249         *
     250         * @since 6.0.0
     251         *
     252         * @param string  $link       The default rendered author HTML link.
     253         * @param string  $author_url Author's URL.
     254         * @param WP_User $authordata Author user data.
     255         */
     256        return apply_filters( 'the_author_link', $link, $author_url, $authordata );
    239257    } else {
    240258        return get_the_author();
Note: See TracChangeset for help on using the changeset viewer.