Skip to content

Abilities API: Return the empty result for an author_slug that names no user - #14643

Closed
jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:update/content-query-author-slug-empty-result
Closed

jorgefilipecosta wants to merge 1 commit into
WordPress:trunkfrom
jorgefilipecosta:update/content-query-author-slug-empty-result

Conversation

@jorgefilipecosta

@jorgefilipecosta jorgefilipecosta commented Oct 21, 2026 •

Copy link
Copy Markdown
Member

Follow up to https://core.trac.wordpress.org/changeset/64388.

What

  • An author_slug filter of core/content-query that names no user now matches no post and gives the empty result, like the ids and slugs filters when nothing matches their value. A user without posts the current user may read gives the same empty result.
  • A value that is not a string is still rejected as an invalid filter, like the other malformed filters.

Why

  • The ability rejected an unknown slug as an invalid filter, and looked the slug up against the users the current user may see, with a rule of its own. Treating it like the other filters fixes possible inconsistencies and removes the lookup.

How

  • get_author_by_slug() and its visibility rules are removed; the ability looks the user up with get_user_by() and returns the empty result when there is none.
  • The author_slug input description says so.
  • Tests: the unknown-slug case now expects the empty result, a value that is not a string keeps its own rejection test, the visibility tests are replaced by one that expects the same empty result for a user without readable posts and for a slug that names no user, and the multisite test expects the empty result for a user of another site.

The change was drafted with AI assistance and reviewed by me.

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

Testing

Verify unit tests are passing:

npm run test:php -- --filter author_slug

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jorgefilipecosta, gziolo.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

…s no user.

The `core/content-query` ability rejected an `author_slug` filter that
names no user as an invalid filter, and looked the slug up against the
users the current user may see, with a rule of its own. The other
filters, such as `ids` and `slugs`, give the empty result when nothing
matches their value.

Treat `author_slug` the same way, to fix possible inconsistencies: a slug
that names no user now matches no post, like a user without posts the
current user may read, and the lookup of visible users is removed. A
value that is not a string is still rejected.

Follow-up to [64388].

See #66268.
@jorgefilipecosta
jorgefilipecosta force-pushed the update/content-query-author-slug-empty-result branch from 8d15a19 to 72e77ad Compare October 21, 2026 16:50
@jorgefilipecosta jorgefilipecosta changed the title Abilities API: Match the REST posts controller for an author_slug that names no user Abilities API: Return the empty result for an author_slug that names no user Oct 21, 2026
@gziolo

gziolo commented Oct 21, 2026

Copy link
Copy Markdown
Member

One question before I start reviewing it: should we make author an object in the input schema with slug as a property? This way, we would mirror the shape that the output uses:

https://github.com/jorgefilipecosta/wordpress-develop/blob/72e77ad381bf8c58768450d5e11e72bc9b1d978b/src/wp-includes/abilities/class-wp-abilities-content.php#L1026-L1044

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

One question before I start reviewing it: should we make author an object in the input schema with slug as a property? This way, we would mirror the shape that the output uses:

jorgefilipecosta/wordpress-develop@72e77ad/src/wp-includes/abilities/class-wp-abilities-content.php#L1026-L1044

Good point I'm doing the shape change at #14673.

@gziolo

gziolo commented Oct 22, 2026

Copy link
Copy Markdown
Member

Does #14673 contain also changes from this PR?

@jorgefilipecosta

Copy link
Copy Markdown
Member Author

Hi @gziolo yes #14673 also fixed this issue and included tests, closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants