Make WordPress Core

Opened 6 weeks ago

Closed 4 days ago

Last modified 4 days ago

#62913 closed defect (bug) (fixed)

Prevent empty author links in list tables

Reported by: kkmuffme's profile kkmuffme Owned by: joedolson's profile joedolson
Milestone: 6.8 Priority: normal
Severity: normal Version:
Component: Administration Keywords: has-patch has-testing-info commit
Focuses: accessibility, administration Cc:

Description (last modified by sabernhardt)

/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?

Attachments (3)

empty-author.png (93.3 KB) - added by hdkothari81 10 days ago.
After deleting the test user related post are not being empty.
before-patch.png (57.9 KB) - added by shailu25 9 days ago.
Before Patch
after-patch.png (52.9 KB) - added by shailu25 9 days ago.
After Patch

Download all attachments as: .zip

Change History (22)

#1 @sabernhardt
6 weeks ago

  • Component changed from Upload to Administration
  • Description modified (diff)
  • Focuses accessibility administration added
  • Keywords needs-patch added
  • Summary changed from "a" without text in uploads to Prevent empty author links in list tables

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 media list tables
  2. around $args and the echo line in 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">&#8212;</span><span class="screen-reader-text">' . __( '(no author)' ) . '</span>';
		}
	}

This ticket was mentioned in PR #8271 on WordPress/wordpress-develop by @snehapatil02.


6 weeks ago
#2

  • Keywords has-patch has-unit-tests added; needs-patch removed

Trac ticket: https://core.trac.wordpress.org/ticket/62913

## Description
This PR fixes the issue where empty author links appear in the media list table when no author is assigned. Currently, an empty <a> element is rendered which causes issues with keyboard navigation and accessibility tools.

## Changes proposed in this Pull Request:

  • Added empty author check before rendering author links
  • Added fallback display with em dash (—) for visual indication
  • Added screen reader text "(no author)" for better accessibility
  • Added unit tests to verify both empty and valid author scenarios
  • Maintains consistency with how empty values are handled in other columns

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


5 weeks ago

#4 @joedolson
5 weeks ago

  • Milestone changed from Awaiting Review to 6.8
  • Owner set to joedolson
  • Status changed from new to accepted

#5 @joedolson
5 weeks ago

This is good, and I think it's generally ready to go - but if we're going to do it for media tables, we should also extend the same logic to the other list tables, which all have the same issue if there's no author string returned.

It may be a rare circumstance to occur, but it certainly can occur. Given that get_the_author() returns an empty string if there's no valid author object and is filterable, the use case is reasonable in all the similar contexts.

@snehapatil02 If you can extend your PR to cover the other list tables, I think this will be in good shape.

This ticket was mentioned in Slack in #accessibility by joedolson. View the logs.


2 weeks ago

This ticket was mentioned in PR #8488 on WordPress/wordpress-develop by @faisal03.


10 days ago
#7

Trac ticket: https://core.trac.wordpress.org/ticket/62913

## Description:

This PR addresses an issue in the Posts List Table where posts without an assigned author display an empty author column. A similar fix is already applied to the Media List Table (https://github.com/WordPress/wordpress-develop/pull/8271), but the issue also affects other list tables.

Changes Made

  • Added a fallback text (— no author) when get_the_author() returns an empty string.
  • Ensured get_the_author_meta( 'ID' ) is only used when get_the_author() is not empty, preventing invalid author links.
  • Mirrors the approach taken in the Media List Table fix for consistency.

## Testing Instructions

  1. Create a post and assign it an author.
  2. Delete the author or change the post’s author field to an invalid value in the database.
  3. Visit the Posts List Table.
  4. The author column should now show — no author instead of being blank.

This aligns with feedback from @joedolson on https://core.trac.wordpress.org/ticket/62913#comment:5, where he suggested extending the fix to all list tables, not just the Media List Table.

@faisal03 commented on PR #8488:


10 days ago
#8

## Testing Instructions

  1. Log in to the WordPress admin panel.
  2. Navigate to Posts → Add New and create a new post.
  3. Assign an existing user as the post’s author.
  4. Publish the post.
  5. Go to Posts → All Posts.
  6. Verify that the Author column displays the correct author name.
  7. Click on the author name and ensure it links to the correct author archive.
  8. Create a new post and assign it to a test user.
  9. Navigate to Users → All Users and delete the test user.
  10. Choose the option that removes the user but keeps their posts.
  11. Go to Posts → All Posts.
  12. Verify that the Author column shows — no author instead of being empty.

#9 @hdkothari81
10 days ago

Test Report
Patch Tested: https://github.com/WordPress/wordpress-develop/pull/8488

Environment:


WordPress - 6.8-beta1
OS - Linux
Browser - Chrome
Theme: Twenty Twenty-Five (1.1)
PHP - 8.1.23
Active Plugin: None

Actual Results:


Issues resolved with this patch

Screenshot:


Added Attachment

@hdkothari81
10 days ago

After deleting the test user related post are not being empty.

#10 @rishavdutta
10 days ago

Test Report

PR tested: https://github.com/WordPress/wordpress-develop/pull/8488

Test Environment [Playground]

  • WordPress Version: 6.8beta1
  • OS: macOS
  • Browser Google Chrome
  • WordPress Active Theme: Twenty Twenty-Five
  • Active Plugin: None
  • PHP version: 7.4.31-dev
  • Database Client Version: 3.40.1
  • Database Server Version: 5.5

Observed Test Results:-

  • After deleting the specific author, the author section of related content is not empty and the reference gets changed to the particular user to which we have specified while deleting the particular WP site user.

Reference Screen Recording: https://drive.google.com/file/d/1QIkwtKqU3Ie_4n_DRawRaErilq1vlltr/view?usp=sharing

@sumitbagthariya16 commented on PR #8488:


10 days ago
#11

QA Test Report
---

I tested this PR using the following query to reset the author:

UPDATE wp_posts SET post_author = 0 WHERE post_type = 'post' LIMIT 1;

After running the query and removing the author from the post, I noticed that a dash (-) sign appears in place of the author name.

Before
https://github.com/user-attachments/assets/cb158987-695f-4099-9714-ad3729dfc3e5

After
https://github.com/user-attachments/assets/1e8fe522-d48f-4e6c-9564-cec86fa19d00

Testing Environment

<Details>

  • WordPress: WordPress 6.8-beta1
  • PHP: 8.2.
  • Web Server: Nginx 1.20.2
  • Browser: Chrome
  • OS: macOS 15.2

</Details>

#12 @rishavdutta
10 days ago

  • Keywords has-testing-info added

#13 @shailu25
9 days ago

Test Report

Patch Tested: https://github.com/WordPress/wordpress-develop/pull/8488

Environment:
WordPress - 6.8-beta2
OS - Windows
Browser - Firefox
Theme: Twenty Twenty Five
PHP - 8.2.12
Active Plugin: Beta Tester

Actual Results:

  • Issue Resolved With Patch.✅

Screenshots:

  • Added Attachment

@shailu25
9 days ago

Before Patch

@shailu25
9 days ago

After Patch

This ticket was mentioned in PR #8523 on WordPress/wordpress-develop by @sabernhardt.


4 days ago
#14

Combines list table changes from pull requests by snehapatil02 and faisal03 (but removes the new unit tests, which were failing).

Both those PRs

  • Added esc_html() for author display names when they are known and linked.
  • Added fallback of a visible em dash and the visually hidden "(no author)" text when the post author's name is unknown.

Additional changes in this PR:

  • Consistently uses the existing '(no author)' text string, which is already translated.
  • Updates the since notes to reflect that the author's name is _unknown_, as the documentation in get_the_author() says.

Trac 62913

#15 @sabernhardt
4 days ago

  • Keywords has-unit-tests removed

I was unable to fix the test_column_author_with_valid_author() unit tests, so I removed the tests from the combined PR. If someone else can solve that, the unit tests could be added later on another ticket.

#16 @joedolson
4 days ago

Yeah, I couldn't solve it either. I feel like it must have something to do with a cache, because I tested the generated $post array and it definitely has an author that matches.

I think that this is fine to go in without the tests; they are nice thing, but ultimately this isn't a behavior that crucially requires testing, in my opinion.

Will test the updated PR and, most likely, commit.

#17 @joedolson
4 days ago

  • Keywords commit added

Code looks good, tests well. The only change from the above screenshots is the consistent usage of the (no author) text string; I'm not going to generate new screenshots for that.

Can't help but feel that we all spent way more time on those tests than was really justified, but ah well!

#18 @joedolson
4 days ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 60032:

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.

Note: See TracTickets for help on using tickets.