Repository navigation
Comments: Make REST comment moderation comment-type aware (Trac #35214, Stage 3) - #56
adamsilverstein wants to merge 10 commits into
Conversation
`WP_REST_Comments_Controller::check_edit_permission()` short-circuited on the global `moderate_comments` primitive, so a moderator of a custom comment type could not edit or delete comments of that type via REST, while a global moderator could act on every type regardless of its capability model. Route the moderator shortcut through the `moderate_comment` meta capability instead. For comment types using the default capability model this resolves to `moderate_comments` (behavior unchanged), while a type with its own capabilities is gated by its own moderation primitive. Apply the same change to the orphaned-comment branch of `check_read_permission()`. This consumes the meta capabilities added in the previous commit; it makes no change for the built-in comment, pingback, trackback, or note types. See #35214.
Dispatch real update and delete requests through the comments controller to prove `check_edit_permission()` honors per-type capabilities: a moderator (or editor) of an independent `review` type can edit and delete review comments, a global `moderate_comments` moderator cannot touch them, and the default and built-in ping types behave exactly as before. See #35214.
|
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:
|
|
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
|
…ent-type-moderation-rest
…ment types. get_item_permissions_check() still gated edit-context reads of non-note comments on the global 'moderate_comments' primitive. After the update and delete paths moved to the per-comment 'moderate_comment' meta capability, a type moderator could update or delete a comment (with the response already returning edit-context data) yet receive 403 reading the same comment with ?context=edit. Route the non-note branch through array( 'moderate_comment', $comment->comment_ID ) to match. Also mark every comment gate that intentionally stays on the global primitive (collection-level and creation-time gates, including the documented ?post=0 divergence), add the missing @SInCE entries on check_edit_permission() and check_read_permission(), and expand the tests: the unregistered-type back-compat pin (a global moderator keeps full control of never-registered types), legacy empty-string types, single-item edit-context reads per model, orphaned-comment reads under both models, and the ?post=0 collection matrix. Denials now assert error codes via assertErrorResponse().
…ent-type-moderation-rest # Conflicts: # src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
The moderation gates landed with `@since 7.1.0` tags, but this ships in 7.2.0, and the inline comments narrated design history that belongs in the PR. Shortens them, corrects the version tags, documents the edit-context change on get_item_permissions_check(), and restores the unrelated note comment trunk wording. No behavior change. See #35214.
Trunk added the `reaction` type, gated like `note` by `edit_comment` rather than moderation. The merge kept that, but nothing failed if reactions were routed through `moderate_comment`, which would let a bare global moderator delete or read reactions in the edit context. Adds note and reaction cases for both paths, and native types so the file passes PHPStan level 10. See #35214.
check_edit_permission() now admits a type's own moderators, but moving a comment to another post still runs check_target_post_permission(), where only the site-wide `moderate_comments` primitive skips the `edit_post` check on the destination. That keeps a type-scoped moderator from placing comments on posts they cannot edit, such as another user's private post. Pins both sides of that rule plus the unchanged global moderator behavior. See #35214.
…ent-type-moderation-rest
Trunk is in the 7.2 beta, so these additions can no longer ship in 7.2.0.
Stack: Custom Comment Types (#35214)
register_comment_type()registration API/wp/v2/comment-typesendpointmap_meta_cap()render_callbackdisplay callbackis_pingping groupingdefault_excluded_comment_typesfilterwp_update_comment_counts()recount helperWordPress#12311 and WordPress#12310 are on WordPress/wordpress-develop; the rest are fork PRs targeting their parent branch and will retarget to trunk as their base lands.
I pointed Claude at this PR again, and this came back:
Trac ticket: https://core.trac.wordpress.org/ticket/35214
AI Use
Written with 🤖 Claude Code, code and description. I will review and test.