[wp-trac] [WordPress Trac] #62913: Prevent empty author links in list tables (was: "a" without text in uploads)

WordPress Trac noreply at wordpress.org
Thu Feb 6 17:09:37 UTC 2025


#62913: Prevent empty author links in list tables
----------------------------+--------------------------------------------
 Reporter:  kkmuffme        |       Owner:  (none)
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:
 Severity:  normal          |  Resolution:
 Keywords:  needs-patch     |     Focuses:  accessibility, administration
----------------------------+--------------------------------------------
Changes (by sabernhardt):

 * keywords:   => needs-patch
 * focuses:   => accessibility, administration
 * component:  Upload => Administration


Old description:

> /wp-admin/upload.php?mode=list
>
> In some cases when there is no image author for whatever reason
> (unrelated), there is an empty "a" element, which causes unexpected
> behavior in e.g. keyboard navigation or for accessibility tools
>

> {{{
> <td class="author column-author" data-colname="Author"><a
> href="upload.php?author"></a></td>
> }}}
>
> In that case the "a" should not be output either?

New description:

 `/wp-admin/upload.php?mode=list`

 In some cases when there is no image author for whatever reason
 (unrelated), there is an empty "a" element, which causes unexpected
 behavior in e.g. keyboard navigation or for accessibility tools


 {{{
 <td class="author column-author" data-colname="Author"><a
 href="upload.php?author"></a></td>
 }}}

 In that case the "a" should not be output either?

--

Comment:

 I'm curious how an attachment would have no author, but both
 `wp_prepare_attachment_for_js()` and `attachment_submitbox_metadata()`
 have a "(no author)" text string for that possibility.

 A quick way to reproduce an empty link in the list table would be to add a
 filter:
 {{{
 add_filter( 'the_author', '__return_empty_string' );
 }}}

 `if ( ! empty( get_the_author() ) ) {  }` could wrap the code in
 `column_author()` methods:
 1. around `printf()` function in [https://github.com/WordPress/wordpress-
 develop/blob/d5c9ae5bd56bf86259af25c29a19511d4bf1969f/src/wp-
 admin/includes/class-wp-media-list-table.php#L509-L515 media list tables]
 2. around `$args` and the `echo` line in [https://github.com/WordPress
 /wordpress-develop/blob/d5c9ae5bd56bf86259af25c29a19511d4bf1969f/src/wp-
 admin/includes/class-wp-posts-list-table.php#L1283-L1289 general post
 tables]

 The methods could also have an `else` condition to print "(no author)"
 instead of an empty cell, either as visible text or by showing an em dash
 (as it does for posts with no comments or no tags):
 {{{
         public function column_author( $post ) {
                 if ( ! empty( get_the_author() ) ) {
                         printf(
                                 '<a href="%s">%s</a>',
                                 esc_url( add_query_arg( array( 'author' =>
 get_the_author_meta( 'ID' ) ), 'upload.php' ) ),
                                 get_the_author()
                         );
                 } else {
                         echo '<span aria-hidden="true">—</span><span
 class="screen-reader-text">' . __( '(no author)' ) . '</span>';
                 }
         }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/62913#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list