API / Minn\Rest / PostsWriteController

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.

Constants and properties

privateLIVE = 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.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Content\PostWriter $writer

Promoted from the constructor.

privatereadonly Minn\Content\Site $site

Promoted from the constructor.

privatereadonly Minn\Rest\PostObject $object

Promoted from the constructor.

privatereadonly Minn\Rest\RestUrl $url

Promoted from the constructor.

privatereadonly 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)#
methodcreate(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).

methodserveCreate(Minn\Http\Request $request, string $type, string $base): Minn\Http\Response#

Creates a post of any type from the body.

methodupdate(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.

methodserveUpdate(Minn\Http\Request $request, string $type, string $id): Minn\Http\Response#

Updates a post of any type from the body.

methoddelete(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.

methodserveDelete(Minn\Http\Request $request, string $type, string $id): Minn\Http\Response#

Trashes a post of any type, or deletes it with force.

staticcheckMeta(array $body): void#

A body's meta must be an object of keys (probe rest-meta). @param array<string, mixed> $body

$bodyarray<string, mixed>
staticfield(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.

privatehasParent(string $type): bool#

Whether a type's posts take a parent: pages, and a plugin's hierarchical type.

privatehasOrder(string $type): bool#

Whether a type's posts take an order: pages, and a plugin's type with page attributes.

privateevents(): Minn\Runtime\PostEvents#

Tells plugins about the writes, through the runtime's lifecycle.

privatenewColumns(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.

$bodyarray<string, mixed>
@return array<string, mixed>
privatewriteNewPost(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.

$columnsarray<string, mixed>
privatecheckAssignTerms(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.

$bodyarray<string, mixed>
privaterememberOld(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'.

privatefloatingDate(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>
privatescheduledIfFuture(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).

privateaskedDate(array $body): ?array#

The dates a write asks for, as [local, gmt, timestamp]: date (site local) before date_gmt; null when neither is sent.

$bodyarray<string, mixed>
@return array{0: string, 1: string, 2: int}|null
privateupdatedDate(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).

$bodyarray<string, mixed>
@return array{0: string, 1: string, 2: int}|null
privatefieldColumns(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>
privatestatusColumns(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>
privatecheckStickyChange(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.

$bodyarray<string, mixed>
privatecheckStickyPasswordConflict(array $body, ?Minn\Content\PostRecord $post): void#

The reference refuses a sticky and password combination outright.

privatevalidStatus(string $status): string#
privateclean(string $markup): string#

Markup from a caller without unfiltered_html goes through the allowlist filter.