API / Minn\Runtime / PostInsert

PostInsert final readonly class

Minn\Runtime\PostInsert · public/minn/src/Minn/Runtime/PostInsert.php · 168 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.

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, Closure $guid): int#

Writes the resolved columns; a new post without a guid gets the ?p= form. @return int the post id

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

The categories a saved post should carry: the ones given, or the default for a new post of a type that has categories; null when nothing should change.

$taxonomieslist<string>the type's taxonomies
@return list<int>|null

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#