Skip to content

Commit d6e3b8a

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60032 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4a12552 commit d6e3b8a

2 files changed

Lines changed: 24 additions & 10 deletions

File tree

src/wp-admin/includes/class-wp-media-list-table.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,22 @@ public function column_title( $post ) {
503503
* Handles the author column output.
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

517524
/**

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,15 +1277,22 @@ public function column_comments( $post ) {
12771277
* Handles the post author column output.
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

12911298
/**

0 commit comments

Comments
 (0)