Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5fa4d60
Comments: Make REST comment moderation comment-type aware.
adamsilverstein Jun 25, 2026
04c12ec
Comments: Add REST tests for comment-type-aware moderation.
adamsilverstein Jun 25, 2026
882de64
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Jul 11, 2026
bb3cec6
REST API: Route the remaining per-comment moderation gate through com…
adamsilverstein Jul 11, 2026
ad90fde
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 8, 2026
d37f667
REST API: Tighten comment type moderation inline docs.
adamsilverstein Nov 8, 2026
bfeae3d
Tests: Pin note and reaction gates in REST comment type moderation.
adamsilverstein Nov 8, 2026
a69dc75
Tests: Pin the destination check when type moderators move comments.
adamsilverstein Nov 8, 2026
f9bf9fb
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 8, 2026
b4f9139
Docs: Mark the new comment type APIs as @since 7.3.0.
adamsilverstein Nov 8, 2026
09c6503
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 18, 2026
c366c84
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 18, 2026
cd4e6ed
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 18, 2026
7a20064
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 18, 2026
2993254
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 18, 2026
ef75749
Merge branch 'feature/comment-type-cap-enforcement' into feature/comm…
adamsilverstein Nov 19, 2026
34dd3ed
Merge commit 'c78be63f5f' into HEAD
adamsilverstein Nov 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public function get_items_permissions_check( $request ) {
array( 'status' => rest_authorization_required_code() )
);
} elseif ( 0 === $post_id && ! current_user_can( 'moderate_comments' ) ) {
/*
* The global primitive gates the ?post=0 collection, which can mix
* comment types. Orphans of an independent type are filtered out
* per comment, so a type's own moderators are rejected here.
*/
return new WP_Error(
'rest_cannot_read',
__( 'Sorry, you are not allowed to read comments without a post.' ),
Expand Down Expand Up @@ -218,6 +223,7 @@ public function get_items_permissions_check( $request ) {
}
}
} elseif ( $is_edit_context && ! current_user_can( 'moderate_comments' ) ) {
// The global primitive gates an edit-context collection that can mix comment types.
return new WP_Error(
'rest_forbidden_context',
__( 'Sorry, you are not allowed to edit comments.' ),
Expand Down Expand Up @@ -473,6 +479,7 @@ protected function get_comment( $id ) {
* Checks if a given request has access to read the comment.
*
* @since 4.7.0
* @since 7.3.0 The edit context is gated by the `moderate_comment` meta capability.
*
* @param WP_REST_Request $request Full details about the request.
* @return true|WP_Error True if the request has read access for the item, error object otherwise.
Expand All @@ -483,8 +490,8 @@ public function get_item_permissions_check( $request ) {
return $comment;
}

// Re-map edit context capabilities when requesting `note` or `reaction` type.
$edit_cap = in_array( $comment->comment_type, array( 'note', 'reaction' ), true ) ? array( 'edit_comment', $comment->comment_ID ) : array( 'moderate_comments' );
// Match check_edit_permission(): notes and reactions need `edit_comment`, other types `moderate_comment`.
$edit_cap = in_array( $comment->comment_type, array( 'note', 'reaction' ), true ) ? array( 'edit_comment', $comment->comment_ID ) : array( 'moderate_comment', $comment->comment_ID );
if ( ! empty( $request['context'] ) && 'edit' === $request['context'] && ! current_user_can( ...$edit_cap ) ) {
return new WP_Error(
'rest_forbidden_context',
Expand Down Expand Up @@ -2428,6 +2435,7 @@ protected function prefetch_reaction_summaries( $note_ids ) {
* Checks if the comment can be read.
*
* @since 4.7.0
* @since 7.3.0 Orphaned comments are gated by the `moderate_comment` meta capability.
*
* @param WP_Comment $comment Comment object.
* @param WP_REST_Request $request Request data to check.
Expand All @@ -2447,7 +2455,7 @@ protected function check_read_permission( $comment, $request ) {
return false;
}

if ( empty( $comment->comment_post_ID ) && ! current_user_can( 'moderate_comments' ) ) {
if ( empty( $comment->comment_post_ID ) && ! current_user_can( 'moderate_comment', $comment->comment_ID ) ) {
return false;
}

Expand All @@ -2462,6 +2470,7 @@ protected function check_read_permission( $comment, $request ) {
* Checks if a comment can be edited or deleted.
*
* @since 4.7.0
* @since 7.3.0 Moderators are checked with the `moderate_comment` meta capability.
*
* @param WP_Comment $comment Comment object.
* @return bool Whether the comment can be edited or deleted.
Expand All @@ -2479,7 +2488,8 @@ protected function check_edit_permission( $comment ) {
return current_user_can( 'edit_comment', $comment->comment_ID );
}

if ( current_user_can( 'moderate_comments' ) ) {
// Resolves to the type's own moderation primitive, or `moderate_comments` for the default model.
if ( current_user_can( 'moderate_comment', $comment->comment_ID ) ) {
return true;
}

Expand Down
Loading