API / Minn\Rest / CommentsController

CommentsController final readonly class

Minn\Rest\CommentsController · public/minn/src/Minn/Rest/CommentsController.php · 294 lines

wp/v2/comments: the status tabs with pagination headers, single, signed-in replies, moderation updates, trash, and force delete.

Used by 1

Constants and properties

privatereadonly Minn\Content\Comments $comments

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Rest\CommentObject $object

Promoted from the constructor.

privatereadonly Minn\Rest\Caller $caller

Promoted from the constructor.

Public

new__construct(Minn\Content\Comments $comments, Minn\Content\Posts $posts, Minn\Rest\CommentObject $object, Minn\Rest\Caller $caller)#
methodlist(Minn\Http\Request $request): Minn\Http\ResponseGET /wp/v2/comments (public)#

The comments list as the reference serves it: the request's WP_Comment_Query through rest_comment_query, its totals (counted again when a page comes back empty), and the comments the caller may read.

methodsingle(Minn\Http\Request $request, string $id): Minn\Http\ResponseGET /wp/v2/comments/{id:[\d]+} (public; comment {id} must exist)#

One comment, if the caller may read it.

methodcreate(Minn\Http\Request $request): Minn\Http\ResponsePOST /wp/v2/comments (signed in)#

A signed-in reply; the author fields come from the user.

methodupdate(Minn\Http\Request $request, string $id): Minn\Http\ResponsePOST /wp/v2/comments/{id:[\d]+} (cap moderate_comments; comment {id} must exist)PUT /wp/v2/comments/{id:[\d]+} (cap moderate_comments; comment {id} must exist)PATCH /wp/v2/comments/{id:[\d]+} (cap moderate_comments; comment {id} must exist)#

Status flips and content or author edits, for moderators.

methoddelete(Minn\Http\Request $request, string $id): Minn\Http\ResponseDELETE /wp/v2/comments/{id:[\d]+} (cap moderate_comments; comment {id} must exist)#

Trash remembers where the comment came from; force removes it outright.

Internals 7

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatetotals(WP_Comment_Query $query, array $args, int $perPage): array#

The total and the page count: the query's own, or, when it found nothing (a page past the end), a count without the page.

$argsarray<string, mixed>
@return array{0: int, 1: int}
privateevents(): Minn\Runtime\CommentEvents#

Tells plugins about the writes, through the runtime's comment functions.

privateallowed(WP_REST_Request $wp, Minn\Rest\Context $context, string $email): void#

What this caller may ask the list for: the edit context and other statuses are for moderators and editors; comments without a post belong to moderators, an unreadable post's to those who may read it (or who give its password); type, author, author_exclude and author_email to anyone who can edit posts (the email judged as sent, before sanitizing empties a bad one).

privatereadablePost(Minn\Content\PostRecord $post, string $password): bool#

A post whose comments this caller may read: a protected one only with its password or for someone who may edit it, as the reference reads it; otherwise one it may read, or any published one.

privatereadable(WP_Comment $comment, string $password): bool#

A listed comment this caller may read: a moderator any, its author their own, anyone an approved one on a post they may read.

privateplainComment(int $id): Minn\Content\CommentRecord#

A comment row of the plain kind, or the reference's invalid-id error.

privateprepared(array $body, Minn\Http\Request $request): array#

The fields a request sends, as the reference's controller prepares them for the runtime: the content, the author fields, the address (a moderator may name one) and the browser.

$bodyarray<string, mixed>
@return array<string, mixed>