Comments: Add a capabilities object to comment types#52
Comments: Add a capabilities object to comment types#52adamsilverstein wants to merge 3 commits into
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the 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. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Follow-up: capability enforcement via This PR intentionally keeps the cap object advisory. Proposing the lowest-risk path to actual enforcement, mirroring
One question to settle before coding: do custom comment types keep deriving edit permission from the parent post, or get a permission boundary independent of it? That is the substantive design fork (the comment:19 concern). Happy to write this up on Trac #35214 if the direction looks right. |
Give `WP_Comment_Type` a `cap` object built from new `capability_type` and `capabilities` registration arguments, modeled on `WP_Post_Type` and `get_post_type_capabilities()`. A new `get_comment_type_capabilities()` helper builds the capability strings from the `capability_type` base (default 'comment'), so a registered type can describe its own read, edit, delete, and moderate capabilities. This is advisory metadata only: `map_meta_cap()` is intentionally not changed, so there is no behavior change. The built-in `comment` type resolves to the existing `edit_comment` and `moderate_comments` capabilities, preserving current behavior. Enforcing per-type capabilities through `map_meta_cap()` is left to a follow-up so the capability model can be agreed on first. See #35214.
Cover the new `capability_type`/`capabilities` arguments and the `get_comment_type_capabilities()` helper: default and custom capability types, array capability types with explicit plurals, the `capabilities` override, that the input `capabilities` array is not retained as a property, and that the built-in `comment` type stays backward compatible with the existing core capabilities. See #35214.
The existing tests spot-checked individual generated capabilities; read_comment, moderate_comment, and delete_comments were never asserted. Add a test pinning the complete meta and primitive capability set built by get_comment_type_capabilities() from a string base, plus a direct test of the array capability_type form (explicit plural). See #35214.
d2ee949 to
c4978f3
Compare
Description
Adds a capabilities object to comment types, modeled on
WP_Post_Typeandget_post_type_capabilities(). Registered comment types can now describe their own read/edit/delete/moderate capabilities, which is a prerequisite for per-type permission handling on the #35214 tracking ticket (and for exposing capabilities through the REST endpoint).What it adds
capability_typeregistration argument (default'comment'; may be an array likearray( 'story', 'stories' )for an explicit plural).capabilitiesregistration argument to override individual generated capabilities.WP_Comment_Type::$capobject, built by the newget_comment_type_capabilities()helper.Non-breaking by design
This is advisory metadata only.
map_meta_cap()is intentionally left unchanged, so there is no behavior change to comment moderation or editing. The built-incommenttype resolves to the existingedit_comment(meta) andmoderate_comments(primitive) capabilities, so current behavior is preserved exactly.Wiring these capabilities into
map_meta_cap()enforcement is deliberately left to a follow-up, so the capability model can be reviewed and agreed on before touching the live permission path.Scope / boundary
Stacked on WordPress#12311 (the
register_comment_type()API) and targets that branch; it will be retargeted totrunkonce WordPress#12311 lands. Complements the REST endpoint (#51, also stacked on WordPress#12311) and thedefault_excluded_comment_typesquery filter (WordPress#12310 / #65537).Testing
Capability/meta-cap suites also pass unchanged (
753 tests), confirming no enforcement-path regression. PHPCS and PHPStan are clean on the changed files.See #35214.