API / Minn\Runtime / CommentEvents

CommentEvents final readonly class

Minn\Runtime\CommentEvents · public/minn/src/Minn/Runtime/CommentEvents.php · 254 lines

What the reference's REST comments controller tells plugins, for the engine's own: with plugins loaded every change goes through the runtime's comment functions (wp_insert_comment, wp_update_comment, wp_set_comment_status, wp_trash_comment, wp_delete_comment), which fire the reference's actions in its order, and the REST actions follow. Without a booted runtime the rows are written as before and nothing is told.

Constants and properties

privatereadonly Minn\Content\Comments $comments

Promoted from the constructor.

Public

new__construct(Minn\Content\Comments $comments)#
methodlive(): bool#

Whether plugins are loaded to be told anything.

methodallow(string $address, string $email, string $dateGmt): void#

The check a new comment passes on the reference before it is written: check_comment_flood, with the address, the email and the GMT date.

methodrestCreate(array $prepared, Minn\Http\Request $request): int#

A comment created over REST with plugins loaded, as the reference's controller creates one (probe rest-comment-save): the request's fields through rest_preprocess_comment, the signed-in author filled in, the content check (allow_empty_comment), the date, the length check, wp_allow_comment (a duplicate is a 409, a flood a 400), rest_pre_insert_comment, then wp_insert_comment over wp_filter_comment; a refusal is its REST error.

$preparedarray<string, mixed>the request's fields as the controller prepares them
methodrestUpdate(Minn\Content\CommentRecord $comment, array $prepared, ?string $status, Minn\Http\Request $request): void#

A comment changed over REST with plugins loaded: the request's fields through rest_preprocess_comment, the content and length checks, wp_update_comment, then the status, as the reference's controller changes one.

$preparedarray<string, mixed>
staticchangeStatus(int $id, string $asked): void#

A REST status asked for, as the reference's controller changes it: nothing when it is already so; approve and hold through wp_set_comment_status with that word, spam, unspam, trash and untrash through their own functions.

methodinsert(array $columns): int#

Writes a new comment and returns its id; an approved one is counted on its post. @param array<string, mixed> $columns

$columnsarray<string, mixed>
methodupdate(Minn\Content\CommentRecord $comment, array $columns, ?string $status): void#

An edit through REST: the fields, as wp_update_comment writes them (which tells plugins even when nothing changed), then the status through wp_set_comment_status when it moves.

$columnsarray<string, string>
methodtrash(Minn\Content\CommentRecord $comment): void#

Moves a comment to the trash, keeping its status and the time for the way back.

methoddelete(Minn\Content\CommentRecord $comment): void#

Removes a comment for good.

methodrestSaved(int $id, Minn\Http\Request $request, ?Minn\Content\CommentRecord $before): void#

rest_insert_comment, then rest_after_insert_comment, with the comment as it stands and the request; no $before is a new comment.

methodrestDeleted(Minn\Content\CommentRecord $comment, array $data, Minn\Http\Request $request): void#

rest_delete_comment, after a trash or a delete, with the comment as it was and the response. @param array<string, mixed> $data

$dataarray<string, mixed>

Internals 5

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

privatepreprocessed(array $prepared, Minn\Objects\RestRequest $request): array#

rest_preprocess_comment over the prepared comment.

$preparedarray<string, mixed>
@return array<string, mixed>
privaterequireContent(array $prepared): void#

The reference's content check: allow_empty_comment, handed the comment with the author, parent, post and user filled in; empty content is a 400.

$preparedarray<string, mixed>
privatefield(array $row, string $key): mixed#
$rowarray<string, mixed>
privaterequireLengths(array $prepared): void#
$preparedarray<string, mixed>
privaterefusal(Minn\Objects\Errors $error): Minn\RestError#

A plugin's error as REST serves it: its own status, or 500.