API / Minn\Content / PostWriter

PostWriter final readonly class

Minn\Content\PostWriter · public/minn/src/Minn/Content/PostWriter.php · 433 lines

Every write to the posts table and its satellites: rows, meta, term links with the published counts the reference trusts on read, sticky and format side effects, and revision snapshots.

Constants and properties

constFLOATING = array ( 0 => 'draft', 1 => 'pending', 2 => 'auto-draft', )

The statuses whose post may have a floating date (no GMT date yet).

constZERO_DATE = '0000-00-00 00:00:00'
privateLENGTHS = array ( 'post_status' => 20, 'comment_status' => 20, 'ping_status' => 20, 'post_password' => 255, 'post_name' => 200, 'guid' => 255, 'post_type' => 20, 'post_mime_type' => 100, )

The posts table's short text columns, cut to fit as the reference's database layer cuts them.

privatereadonly Minn\Db $db

Promoted from the constructor.

privatereadonly Minn\Content\Posts $posts

Promoted from the constructor.

privatereadonly Minn\Content\Site $site

Promoted from the constructor.

Public

new__construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Content\Site $site)#
methodhasTerm(string $taxonomy, int $termId): bool#

Whether a term of the taxonomy has the id.

methodinsert(array $columns): int#

Inserts a posts row from column => value pairs and returns the new id.

$columnsarray<string, mixed>
methodupdate(int $id, array $columns): bool#

Sets the given columns on one post; nothing happens for none.

$columnsarray<string, mixed>
methodsetStatus(int $id, string $status): void#

Changes one post's status.

methodsetType(int $id, string $type): bool#

Moves a post to another type, leaving it alone when it is already there.

methodsetMeta(int $id, string $key, string $value): void#

Sets one meta value, inserting the row when the key is new.

staticfloating(Minn\Content\PostRecord $post): bool#

Whether a post's date floats: never given one, it is still a draft or pending with no GMT date.

methodaddMeta(int $id, string $key, string $value): void#

Adds a meta row even when the key already has one (a non-unique key).

methodrememberOld(int $id, string $key, string $was, string $now): void#

Keeps a published post's previous slug or date on record (_wp_old_slug, _wp_old_date) so its old address still finds it: the value it moves to stops being an old one, the value it leaves becomes one, once.

methodensureCategory(int $id): void#

Gives a post the site's default category when it has none, as every save of a post does in the reference.

methodtrash(Minn\Content\PostRecord $post): void#

The row of a post moving to the trash, as the reference writes it: the slug gains __trashed (unless it has it already) and is made unique, as a trashed post's slug is (a second __trashed becomes __trashed-2; tests/tools/side-effects.php), the modified time moves, a floating draft's date settles (any other post's missing GMT date is its own date's), a post keeps a category, and the published counts follow. What the trash keeps for the way back (the status, the time, the slug it had) is meta the caller adds, and the revision comes from the save.

methoddeleteMeta(int $id, string $key): void#

Removes every meta row with this key from a post.

methodtrashedSlug(Minn\Content\PostRecord $post): string#

The slug a post takes in the trash: its own with __trashed (once), made unique.

methoduniqueSlug(string $desired, int $excludeId, string $type = 'post', int $parent = 0): string#

A free slug for the desired text, sanitized first, in the type's scope (see PostSlugs).

methodslugs(): Minn\Content\PostSlugs#

The rules a live post's slug is settled by.

methodsetTerms(int $id, string $taxonomy, array $termIds): void#

Replaces a post's links in one taxonomy and refreshes the counts of the terms it left and joined.

methodrecountTaxonomiesOf(int $id): void#

Recounts every term the post is in, after a status change.

methodtermTaxonomyIdsOf(int $id): array#

The term_taxonomy ids a post is linked to. @return list<int>

@return list<int>
methodrecountTerms(array $ttIds): void#

term_taxonomy.count is stored and trusted on read, so a write that touched terms (term_taxonomy ids) refreshes theirs. @param list<int> $ttIds

$ttIdslist<int>
methodisSticky(int $id): bool#

Whether the post is in the sticky_posts option.

methodstick(int $id): void#

Puts a post on the sticky list, then post_stuck when it was not on it (probe rest-sticky).

methodunstick(int $id): void#

Takes a post off the sticky list, then post_unstuck when it was on it (probe rest-sticky).

methodsetFormat(int $id, string $format): void#

Assigns (or clears) the post-format term, creating it on first use.

methodapplyExtendedFields(int $id, array $body, string $type): void#

The side effects shared by create and update: sticky, format, featured media.

methodapplyCoreMeta(int $id, array $body, string $type): void#

The meta core registers, written directly when no plugins are loaded: footnotes, and a pattern's sync status.

methodapplyTerms(int $id, array $body): void#

Assigns categories, tags, and pattern categories from a write body, replacing existing links.

staticrequestedTerms(array $body, ?array $map = NULL): array#

The terms a REST body names, by taxonomy: categories, tags, and pattern categories, each only when the body has the field.

$bodyarray<string, mixed>
$maparray<string, string>|nullREST field => taxonomy; the core taxonomies when null
@return array<string, list<int>>
methodreparentChildren(int $id, int $parent, array $types): array#

Moves a deleted post's children of the given types to another parent, the way the reference keeps pages and attachments attached. @param list<string> $types @return list<int> the children moved

$typeslist<string>@return list<int> the children moved
methodreassignAuthor(int $from, int $to): void#

Moves every post of one author to another.

methoddb(): Minn\Db#

The database door this writer writes through, for a caller wrapping several of its verbs in one transaction.

methoddeleteRow(int $id): void#

Deletes a post's row and nothing else: wp_delete_post has taken away what goes with it first, and a link in a taxonomy its type does not have stays, as on the reference (tests/tools/side-effects.php, plugin-symbols2).

methoddestroy(int $id): void#

Hard-deletes a post with its revisions and its meta.

Internals 4

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

privatefit(array $columns): array#
$columnsarray<string, mixed>@return array<string, mixed>
privatecountSql(): string#

The update that sets each term's count to its published posts.

privateannounceSticky(string $hook, int $id): void#

Inside a request: fires post_stuck or post_unstuck.

privatesaveSticky(array $ids): void#
$idslist<int>