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.
Built from https://develop.svn.wordpress.org/trunk@60032


git-svn-id: http://core.svn.wordpress.org/trunk@59368 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
joedolson
2025-03-17 18:54:27 +00:00
parent f640e6c7a8
commit 9f51d473ef
3 changed files with 25 additions and 11 deletions

View File

@@ -503,15 +503,22 @@ class WP_Media_List_Table extends WP_List_Table {
* Handles the author column output.
*
* @since 4.3.0
* @since 6.8.0 Added fallback text when author's name is unknown.
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_author( $post ) {
printf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
get_the_author()
);
$author = get_the_author();
if ( ! empty( $author ) ) {
printf(
'<a href="%s">%s</a>',
esc_url( add_query_arg( array( 'author' => get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
esc_html( $author )
);
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( '(no author)' ) . '</span>';
}
}
/**

View File

@@ -1277,15 +1277,22 @@ class WP_Posts_List_Table extends WP_List_Table {
* Handles the post author column output.
*
* @since 4.3.0
* @since 6.8.0 Added fallback text when author's name is unknown.
*
* @param WP_Post $post The current WP_Post object.
*/
public function column_author( $post ) {
$args = array(
'post_type' => $post->post_type,
'author' => get_the_author_meta( 'ID' ),
);
echo $this->get_edit_link( $args, get_the_author() );
$author = get_the_author();
if ( ! empty( $author ) ) {
$args = array(
'post_type' => $post->post_type,
'author' => get_the_author_meta( 'ID' ),
);
echo $this->get_edit_link( $args, esc_html( $author ) );
} else {
echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . __( '(no author)' ) . '</span>';
}
}
/**

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.8-beta2-60031';
$wp_version = '6.8-beta2-60032';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.