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
| private | readonly Minn\Content\Comments $comments | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Comments $comments)# | ||||
| method | live(): bool# | Whether plugins are loaded to be told anything. | |||
| method | allow(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. | |||
| method | restCreate(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.
| |||
| method | restUpdate(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.
| |||
| static | changeStatus(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. | |||
| method | insert(array $columns): int# | Writes a new comment and returns its id; an approved one is counted on its post. @param array<string, mixed> $columns
| |||
| method | update(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.
| |||
| method | trash(Minn\Content\CommentRecord $comment): void# | Moves a comment to the trash, keeping its status and the time for the way back. | |||
| method | delete(Minn\Content\CommentRecord $comment): void# | Removes a comment for good. | |||
| method | restSaved(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. | |||
| method | restDeleted(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
|
Internals 5
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | preprocessed(array $prepared, Minn\Objects\RestRequest $request): array# | rest_preprocess_comment over the prepared comment.
@return array<string, mixed> | |||
| private | requireContent(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.
| |||
| private | field(array $row, string $key): mixed# |
| |||
| private | requireLengths(array $prepared): void# |
| |||
| private | refusal(Minn\Objects\Errors $error): Minn\RestError# | A plugin's error as REST serves it: its own status, or 500. |
Nothing matches.