API / Minn\Runtime / PostInsert

PostInsert final readonly class

Minn\Runtime\PostInsert · public/minn/src/Minn/Runtime/PostInsert.php · 213 lines

The decisions behind wp_insert_post: which columns a postarr fills, when the post counts as empty, the status a publish request lands in, the dates and the slug, the categories a new post gets. The rows are written by Content\PostWriter; the facade fires the hooks around each step.

Used by 1

Constants and properties

privateCOLUMNS = array ( 0 => 'post_author', 1 => 'post_date', 2 => 'post_date_gmt', 3 => 'post_content', 4 => 'post_title', 5 => 'post_excerpt', 6 => 'post_status', 7 => 'comment_status', 8 => 'ping_status', 9 => 'post_password', 10 => 'post_name', 11 => 'to_ping', 12 => 'pinged', 13 => 'post_modified', 14 => 'post_modified_gmt', 15 => 'post_content_filtered', 16 => 'post_parent', 17 => 'guid', 18 => 'menu_order', 19 => 'post_type', 20 => 'post_mime_type', )
privatereadonly Minn\Content\PostWriter $writer

Promoted from the constructor.

privatereadonly int $userId

Promoted from the constructor.

privatereadonly Closure $discussion

Promoted from the constructor.

privatereadonly Closure $supports

Promoted from the constructor.

privatereadonly Closure $canPublish

Promoted from the constructor.

privatereadonly Closure $gmtFromDate

Promoted from the constructor.

privatereadonly Closure $now

Promoted from the constructor.

Public

new__construct(Minn\Content\PostWriter $writer, int $userId, Closure $discussion, Closure $supports, Closure $canPublish, Closure $gmtFromDate, Closure $now)#
$discussionClosure(string, string): stringa new post's comment or ping status by type, as get_default_comment_status has it
$supportsClosure(string, string): boolwhether a post type supports a feature
$canPublishClosure(string): boolwhether the current user may publish the type
$gmtFromDateClosure(string): stringthe site-local date as GMT
$nowClosure(bool): stringthe current local (or GMT) MySQL time
methodcolumns(array $postarr, ?array $existing): array#

The columns the posts table takes, filled from a postarr, with a new post's defaults. @param array<string, mixed>|null $existing @return array<string, string>

$existingarray<string, mixed>|null@return array<string, string>
methodisEmpty(array $columns, ?array $existing): bool#

A post with nothing in title, content, and excerpt is empty when its type supports all three. @param array<string, mixed>|null $existing

$existingarray<string, mixed>|null
methodresolve(array $columns, ?array $existing): array#

The columns as they will be written: the status a request lands in (attachments inherit, unprivileged publishes pend, a future date schedules), the dates, the slug (sanitized; not yet free), and the integer columns.

$existingarray<string, mixed>|null
@return array<string, string>
methodpersist(array $columns, ?int $existingId): int#

Writes the resolved columns. @return int the post id

staticunwritten(array $columns, ?int $existingId): Minn\Objects\Errors#

The error for a post the database door would not write, its text not what the table holds (probe refused-writes): an insert's or an update's (a post that already has an id), naming the first such column.

$columnsarray<string, mixed>
methodfillGuid(int $id, array $columns, Closure $guid): void#

Gives a new post written without a guid its permalink as one, once its slug, terms and meta are in.

staticcategories(array $postarr, int $id, string $type, string $status, bool $update, array $taxonomies): ?array#

The categories a saved post hands wp_set_post_categories: none when its type has no categories (null); an update that names none keeps the ones it has; otherwise the ones given, each empty value dropped. None left is the default category for a post that is not an auto-draft, else an empty list (which wp_set_post_categories decides).

$postarrarray<string, mixed>
$taxonomieslist<string>the type's taxonomies
@return array<mixed>|null
staticcategoryIds(mixed $categories, mixed $status, mixed $type, mixed $append): array#

The category ids wp_set_post_categories sets, and whether they add to the post's: none given (null or an empty list) is the default category in place of the post's, for a post of a type that takes one (posts and the types default_category_post_types adds) that is not an auto-draft; a lone blank string is nothing to set (null ids); else each value as an id, any that is none dropped.

@return array{0: list<int>|null, 1: bool}

Internals 1

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

privatetype(array $columns, ?array $existing): string#