Make WordPress Core

Changeset 60032


Ignore:
Timestamp:
03/17/2025 06:52:12 PM (5 weeks ago)
Author:
joedolson
Message:

Administration: A11y: Prevent empty author link in list tables.

If the author display name is unknown, show an emdash and screen reader text (no author), consistent with other cases where information is unknown. Fix an issue where an unknown author name displayed as an invisible link with no text.

Props kkmuffme, hdkothari81, shailu25, snehapatil02, sabernhardt, faisal03, rishavdutta, sumitbagthariya16, joedolson.
Fixes #62913.

Location:
trunk/src/wp-admin/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r58745 r60032  
    504504     *
    505505     * @since 4.3.0
     506     * @since 6.8.0 Added fallback text when author's name is unknown.
    506507     *
    507508     * @param WP_Post $post The current WP_Post object.
    508509     */
    509510    public function column_author( $post ) {
    510         printf(
    511             '<a href="%s">%s</a>',
    512             esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
    513             get_the_author()
    514         );
     511        $author = get_the_author();
     512
     513        if ( ! empty( $author ) ) {
     514            printf(
     515                '<a href="%s">%s</a>',
     516                esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
     517                esc_html( $author )
     518            );
     519        } else {
     520            echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( '(no author)' ) . '</span>';
     521        }
    515522    }
    516523
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r59000 r60032  
    12781278     *
    12791279     * @since 4.3.0
     1280     * @since 6.8.0 Added fallback text when author's name is unknown.
    12801281     *
    12811282     * @param WP_Post $post The current WP_Post object.
    12821283     */
    12831284    public function column_author( $post ) {
    1284         $args = array(
    1285             'post_type' => $post->post_type,
    1286             'author'    => get_the_author_meta( 'ID' ),
    1287         );
    1288         echo $this->get_edit_link( $args, get_the_author() );
     1285        $author = get_the_author();
     1286
     1287        if ( ! empty( $author ) ) {
     1288            $args = array(
     1289                'post_type' => $post->post_type,
     1290                'author'    => get_the_author_meta( 'ID' ),
     1291            );
     1292            echo $this->get_edit_link( $args, esc_html( $author ) );
     1293        } else {
     1294            echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( '(no author)' ) . '</span>';
     1295        }
    12891296    }
    12901297
Note: See TracChangeset for help on using the changeset viewer.