Repository navigation
Abilities API: Name the author of a core/content-query post only to users who may see them - #14654
jorgefilipecosta wants to merge 1 commit into
Conversation
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
0705f0e to
82cdce2
Compare
| * @param int $user_id The author's user ID. | ||
| * @return WP_User|null The author, or null when they no longer exist or may not be seen. | ||
| */ | ||
| private function get_visible_author( int $user_id ): ?WP_User { |
There was a problem hiding this comment.
Thanks for working on this! Hiding the name and slug of authors the user may not see makes sense.
I have one concern. This rule depends on show_in_rest, but this ability should not depend on REST API settings. A post type can be exposed to abilities without being exposed to REST.
This class also already has a visibility rule in get_author_by_slug(), which the author_slug filter uses. The two rules give different results. For example, an Editor gets null for the author of a Contributor's pending post. But the same Editor can filter with where[author_slug]=hidden-contributor and get that post back. So the slug is still exposed.
Could we move the rule from get_author_by_slug() into one shared helper and use it in both places? Then the filter and the output always agree, with no link to REST.
There was a problem hiding this comment.
Hi @gziolo, thank you, the feedback was applied. get_author_by_slug() was already replaced by the author object filter in https://core.trac.wordpress.org/changeset/64680, so the shared rule now lives in get_visible_author(), used by both the author field and the author slug filter. The rule counts published posts in the post types exposed to abilities (show_in_abilities) instead of the REST ones, since the ability already returns those posts with their author. Tests cover the filter agreeing with the field for each role, and a post type exposed to abilities only against one exposed to the REST API only.
82cdce2 to
7a8f585
Compare
… users who may see them. The `core/content-query` ability returned the author's display name and slug for every post the current user can read, and its `author` slug filter named any user of the site. Return them only to users who may see the author: the author themselves, users who can edit them or list users, and otherwise users who can read a published post of theirs in a post type exposed to abilities, where the ability already returns the author. `author.name` and `author.slug` are null for other users, as they already are for an author who no longer exists, and the `author` slug filter matches no post for them, as it already does for a slug that names no user, so the filter cannot confirm a slug the field withholds. The author ID is still returned, and the `author` ID filter still matches the stored author. The lookup runs once per author and query, and only when the name or slug is requested or the slug filter is given. Follow-up to [64388], [64680]. See #66268.
7a8f585 to
79a8d16
Compare
core/content-query postcore/content-query post only to users who may see them
gziolo
left a comment
There was a problem hiding this comment.
Thank you for addressing all feedback.
|
Committed at 38a613a. |
Follow up to https://core.trac.wordpress.org/changeset/64388 and https://core.trac.wordpress.org/changeset/64680.
What
author.nameandauthor.slugof acore/content-querypost are now null for an author the current user may not see, as they already are for an author who no longer exists. The author ID is still returned.authorslug filter matches no post for such a user, as it already does for a slug that names no user, so the filter cannot confirm a slug the field withholds. TheauthorID filter still matches the stored author.Why
show_in_abilities), where the ability already returns the author. Which post types the REST API exposes plays no part.How
get_visible_author()holds the rule and is used by theauthorfield and by theauthorslug filter. The post count is kept per author for the query, sincecount_user_posts()is not cached, and only runs when the name or slug is requested or the slug filter is given.author.idalone.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: