PostWriter final readonly class
Minn\Content\PostWriter · public/minn/src/Minn/Content/PostWriter.php · 503 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
| const | FLOATING = array ( 0 => 'draft', 1 => 'pending', 2 => 'auto-draft', ) | The statuses whose post may have a floating date (no GMT date yet). |
| const | ZERO_DATE = '0000-00-00 00:00:00' | |
| private | LENGTHS = 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. |
| private | readonly Minn\Db $db | Promoted from the constructor. |
| private | readonly Minn\Content\Posts $posts | Promoted from the constructor. |
| private | readonly Minn\Content\Site $site | Promoted from the constructor. |
Public
| new | __construct(Minn\Db $db, Minn\Content\Posts $posts, Minn\Content\Site $site)# | |||||||
| method | hasTerm(string $taxonomy, int $termId): bool# | Whether a term of the taxonomy has the id. | ||||||
| method | insert(array $columns): int# | Inserts a posts row from column => value pairs and returns the new id.
| ||||||
| method | update(int $id, array $columns): void# | Sets the given columns on one post; nothing happens for none.
| ||||||
| method | setStatus(int $id, string $status): void# | Changes one post's status. | ||||||
| method | setType(int $id, string $type): bool# | Moves a post to another type, leaving it alone when it is already there. | ||||||
| method | setMeta(int $id, string $key, string $value): void# | Sets one meta value, inserting the row when the key is new. | ||||||
| static | floating(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. | ||||||
| method | addMeta(int $id, string $key, string $value): void# | Adds a meta row even when the key already has one (a non-unique key). | ||||||
| method | rememberOld(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. | ||||||
| method | ensureCategory(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. | ||||||
| method | trash(Minn\Content\PostRecord $post): void# | The row of a post moving to the trash, as the reference writes it: the slug gains __trashed, the modified time moves, a floating draft's date settles, 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. | ||||||
| method | deleteMeta(int $id, string $key): void# | Removes every meta row with this key from a post. | ||||||
| method | uniqueSlug(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). | ||||||
| method | slugs(): Minn\Content\PostSlugs# | The rules a live post's slug is settled by. | ||||||
| method | setTerms(int $id, string $taxonomy, array $termIds): void# | Replaces a post's links in one taxonomy and refreshes that taxonomy's counts. | ||||||
| method | taxonomiesOf(int $id): array# | The taxonomies a post has terms in. @return list<string> the distinct taxonomies a post has links in | ||||||
| method | recountTaxonomiesOf(int $id): void# | Recounts every term the post is in, after a status change. | ||||||
| method | recount(string $taxonomy): void# | term_taxonomy.count is stored and trusted on read, so every status change refreshes it. | ||||||
| method | isSticky(int $id): bool# | Whether the post is in the sticky_posts option. | ||||||
| method | stick(int $id): void# | Puts a post on the sticky list, then post_stuck when it was not on it (probe rest-sticky). | ||||||
| method | unstick(int $id): void# | Takes a post off the sticky list, then post_unstuck when it was on it (probe rest-sticky). | ||||||
| method | setFormat(int $id, string $format): void# | Assigns (or clears) the post-format term, creating it on first use. | ||||||
| method | applyExtendedFields(int $id, array $body, string $type): void# | The side effects shared by create and update: sticky, format, featured media. | ||||||
| method | applyCoreMeta(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. | ||||||
| method | applyTerms(int $id, array $body): void# | Assigns categories, tags, and pattern categories from a write body, replacing existing links. | ||||||
| static | requestedTerms(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.
@return array<string, list<int>> | ||||||
| method | maybeSaveRevision(int $id, int $userId): void# | Snapshots the post's NEW state as a revision exactly when the reference would: compared against the latest revision, identical content-bearing fields add nothing, and the first update always snapshots. | ||||||
| method | revisionColumns(int $id, int $userId): ?array# | The row of the revision a post's current state calls for, or null when it calls for none (an unrevisioned type, or nothing changed since the latest revision). @return array<string, mixed>|null | ||||||
| method | insertRevision(array $columns): int# | Writes a revision row and gives it its guid; returns its id. @param array<string, mixed> $columns
| ||||||
| method | reparentChildren(int $id, int $parent, array $types): void# | 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
| ||||||
| method | reassignAuthor(int $from, int $to): void# | Moves every post of one author to another. | ||||||
| method | db(): Minn\Db# | The database door this writer writes through, for a caller wrapping several of its verbs in one transaction. | ||||||
| method | destroy(int $id): void# | Hard-deletes a post with its revisions and its meta. |
Internals 5
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | fit(array $columns): array# |
| |||
| private | announceSticky(string $hook, int $id): void# | Inside a request: fires post_stuck or post_unstuck. | |||
| private | saveSticky(array $ids): void# |
| |||
| private | revisionsToKeep(): int# | How many revisions a post keeps without plugins: WP_POST_REVISIONS, all (-1) when unset or true. | |||
| private | pruneRevisions(int $id, int $keep): void# | The oldest revisions past the limit removed, with their meta; autosaves stay. |
Nothing matches.