PostsWriteController final readonly class
Minn\Rest\PostsWriteController · public/minn/src/Minn/Rest/PostsWriteController.php · 518 lines
wp/v2 posts and pages, write side: create, update, trash, and force delete, each gated by the capability engine and answering with the edit-context object the reference returns.
Uses 25 (show)
Constants and properties
| private | LIVE = array ( 0 => 'publish', 1 => 'future', 2 => 'private', ) | The statuses that make a post live: they need the publish capability and give the post its slug. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Content\PostWriter $writer | Promoted from the constructor. |
| private | readonly Minn\Content\Site $site | Promoted from the constructor. |
| private | readonly Minn\Rest\PostObject $object | Promoted from the constructor. |
| private | readonly Minn\Rest\RestUrl $url | Promoted from the constructor. |
| private | readonly Minn\Rest\Caller $caller | Promoted from the constructor. |
Public
| new | __construct(Minn\Content\Posts $posts, Minn\Content\PostWriter $writer, Minn\Content\Site $site, Minn\Rest\PostObject $object, Minn\Rest\RestUrl $url, Minn\Rest\Caller $caller)# | ||||
| method | create(Minn\Http\Request $request, string $base): Minn\Http\ResponsePOST /wp/v2/{base:posts} (cap edit_posts)POST /wp/v2/{base:pages} (cap edit_pages)# | Creates a post or page; one asked for with an id is refused before the caller is judged (patch-security). | |||
| method | serveCreate(Minn\Http\Request $request, string $type, string $base): Minn\Http\Response# | Creates a post of any type from the body. | |||
| method | update(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponsePOST /wp/v2/{base:posts|pages}/{id:[\d]+} (cap edit_post on {id}; post {id} must exist)PUT /wp/v2/{base:posts|pages}/{id:[\d]+} (cap edit_post on {id}; post {id} must exist)PATCH /wp/v2/{base:posts|pages}/{id:[\d]+} (cap edit_post on {id}; post {id} must exist)# | Updates a post or page. | |||
| method | serveUpdate(Minn\Http\Request $request, string $type, string $id): Minn\Http\Response# | Updates a post of any type from the body. | |||
| method | delete(Minn\Http\Request $request, string $base, string $id): Minn\Http\ResponseDELETE /wp/v2/{base:posts|pages}/{id:[\d]+} (cap delete_post on {id}; post {id} must exist)# | Trashes or deletes a post or page. | |||
| method | serveDelete(Minn\Http\Request $request, string $type, string $id): Minn\Http\Response# | Trashes a post of any type, or deletes it with force. | |||
| static | checkMeta(array $body): void# | A body's meta must be an object of keys (probe rest-meta). @param array<string, mixed> $body
| |||
| static | field(mixed $value): string# | A field that may arrive as a scalar or as {raw: ...}. |
Internals 17
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | hasParent(string $type): bool# | Whether a type's posts take a parent: pages, and a plugin's hierarchical type. | |||
| private | hasOrder(string $type): bool# | Whether a type's posts take an order: pages, and a plugin's type with page attributes. | |||
| private | events(): Minn\Runtime\PostEvents# | Tells plugins about the writes, through the runtime's lifecycle. | |||
| private | newColumns(array $body, string $type, int $author, string $status, string $slug, string $date, string $dateGmt, string $modified, string $modifiedGmt, string $title): array# | The row of a new post, from the body and what the create settled.
@return array<string, mixed> | |||
| private | writeNewPost(array $columns): int# | Writes a new post's row as the insert does: its guid becomes the permalink as of now (pretty only when live). The default category follows, and the body's own terms come after rest_insert_{type}, so categories: [] leaves none.
| |||
| private | checkAssignTerms(array $body, string $type): void# | Every existing term the body names must be one the caller may assign (assign_term, through map_meta_cap), as the reference's permission check asks before anything is written (audit Low); an id that names no term is left to the save to report.
| |||
| private | rememberOld(Minn\Content\PostRecord $before, ?Minn\Content\PostRecord $after): void# | After a save: a post brought back from the trash under a new slug has its wanted slug back and stops waiting for it. The old slug and date a published post keeps are the reference's post_updated hooks'. | |||
| private | floatingDate(array $body, Minn\Content\PostRecord $post): array# | A draft that was never given a date (its GMT date is zero) has a floating one: every save moves it to now, and the GMT date stays zero until the post leaves draft or pending, as on the reference. @return array<string, string> | |||
| private | scheduledIfFuture(array $body, Minn\Content\PostRecord $post): array# | A date in the future turns a publish into a schedule, whether the status was sent or kept; a schedule given a date that has come (or reset to now) is published (probe hook-inputs-2). | |||
| private | askedDate(array $body): ?array# | The dates a write asks for, as [local, gmt, timestamp]: date (site local) before date_gmt; null when neither is sent.
@return array{0: string, 1: string, 2: int}|null | |||
| private | updatedDate(array $body): ?array# | The dates an update asks for: as askedDate(), or now when either date is sent as null, which resets the post's date (probe hook-inputs-2).
@return array{0: string, 1: string, 2: int}|null | |||
| private | fieldColumns(array $body, Minn\Content\PostRecord $post, string $type): array# | The columns the body's fields change, minus the status: author (gated by edit_others_*), the two flags, password, the page attributes, the date, the three markup fields through the caller's filter, the slug. @return array<string, mixed> | |||
| private | statusColumns(array $body, Minn\Content\PostRecord $post, string $type): array# | The status change and what rides with it: going live needs the publish cap and gives a slugless post one from its title; the first move to publish stamps the publish date. @return array<string, mixed> | |||
| private | checkStickyChange(array $body, ?Minn\Content\PostRecord $post, string $type): void# | Making a post sticky, or no longer sticky, takes the type's edit_others_posts since 7.1.3; asking for what it already is does not (rest-sticky). Only posts are sticky.
| |||
| private | checkStickyPasswordConflict(array $body, ?Minn\Content\PostRecord $post): void# | The reference refuses a sticky and password combination outright. | |||
| private | validStatus(string $status): string# | ||||
| private | clean(string $markup): string# | Markup from a caller without unfiltered_html goes through the allowlist filter. |
Nothing matches.