PostSave final class
Minn\Runtime\PostSave · public/minn/src/Minn/Runtime/PostSave.php · 253 lines
A REST save's columns through the filters the reference's save runs before it writes, in its order (probe post-insert-filters, contracts/runtime.md "Saves plugins can change"): rest_pre_insert_{type} over the prepared post; every column through its db context (pre_post_* and *_save_pre, where kses and the custom-CSS strip sit) on slashed text; wp_insert_post_empty_content, which refuses a post with no content, title or excerpt; wp_insert_post_parent; for a post that is live, the slug, made again from the filtered title when the request gave none, through pre_wp_unique_post_slug, the bad-slug check and wp_unique_post_slug; and wp_insert_post_data over the row. What a filter changes is written. Without plugins loaded the columns are as given.
Constants and properties
| private | DATA = array ( 0 => 'post_author', 1 => 'post_date', 2 => 'post_date_gmt', 3 => 'post_content', 4 => 'post_content_filtered', 5 => 'post_title', 6 => 'post_excerpt', 7 => 'post_status', 8 => 'post_type', 9 => 'comment_status', 10 => 'ping_status', 11 => 'post_password', 12 => 'post_name', 13 => 'to_ping', 14 => 'pinged', 15 => 'post_modified', 16 => 'post_modified_gmt', 17 => 'post_parent', 18 => 'menu_order', 19 => 'post_mime_type', 20 => 'guid', ) | The row wp_insert_post_data is handed, in its keys. |
| private | FIELDS = array ( 'title' => 'post_title', 'content' => 'post_content', 'excerpt' => 'post_excerpt', 'status' => 'post_status', 'date' => 'post_date', 'date_gmt' => 'post_date_gmt', 'slug' => 'post_name', 'password' => 'post_password', 'author' => 'post_author', 'parent' => 'post_parent', 'menu_order' => 'menu_order', 'comment_status' => 'comment_status', 'ping_status' => 'ping_status', ) | A REST field and the column it fills in the prepared post. |
| private | PREPARED = array ( 'post_title' => 'title', 'post_content' => 'content', 'post_excerpt' => 'excerpt', 'post_type' => NULL, 'post_status' => 'status', 'post_date' => 'date', 'post_date_gmt' => 'date', 'edit_date' => 'date', 'post_name' => 'slug', 'post_author' => 'author', 'post_password' => 'password', 'post_parent' => 'parent', 'menu_order' => 'menu_order', 'comment_status' => 'comment_status', 'ping_status' => 'ping_status', ) | The prepared post's columns in the reference's order, each with the REST field that sends it (null: always there). |
| private | UNSLUGGED = array ( 0 => 'draft', 1 => 'pending', 2 => 'auto-draft', ) | |
| private | PARENT = 'post_parent' | |
| private | NEW_POSTARR = array ( 0 => 'ID', 1 => 'post_author', 2 => 'post_date', 3 => 'post_date_gmt', 4 => 'post_content', 5 => 'post_content_filtered', 6 => 'post_title', 7 => 'post_excerpt', 8 => 'post_status', 9 => 'post_type', 10 => 'comment_status', 11 => 'ping_status', 12 => 'post_password', 13 => 'to_ping', 14 => 'pinged', 15 => 'post_parent', 16 => 'menu_order', 17 => 'guid', 18 => 'import_id', ) | The new post array wp_insert_post_parent is handed beside the whole one. |
| private | DEFAULTS = array ( 'post_author' => 0, 'post_content' => '', 'post_content_filtered' => '', 'post_title' => '', 'post_excerpt' => '', 'post_status' => 'draft', 'post_type' => 'post', 'comment_status' => '', 'ping_status' => '', 'post_password' => '', 'to_ping' => '', 'pinged' => '', 'post_parent' => 0, 'menu_order' => 0, 'guid' => '', 'import_id' => 0, 'context' => '', 'post_date' => '', 'post_date_gmt' => '', ) | wp_insert_post's defaults, in its order (the order its filters run in). |
Public
| static | filter(array $columns, ?Minn\Content\PostRecord $before, array $body, Minn\Http\Request $request, string $type, Minn\Content\PostSlugs $slugs): array# | The columns to write after the filters.
@return array<string, mixed> | ||||||||||||
| static | throughSaveFilters(int $id, array $changes): array# | A direct save's changed columns through every column's db context, as an update runs them over the whole post (pre_post_* and *_save_pre, where kses and the global styles strip sit): a global styles save writes its post this way (probe global-styles-unfiltered). Without a booted runtime the changes are as given.
@return array<string, string> | ||||||||||||
| static | sanitized(array $postarr): array# | wp_insert_post's array with its defaults filled in (ID 0 for a new post), through sanitize_post's db context: slashed in, slashed out.
@return array<string, mixed> | ||||||||||||
| static | refusesEmpty(array $sanitized, string $type): bool# | wp_insert_post_empty_content over whether a type with an editor, a title and an excerpt has none of them. @param array<string, mixed> $sanitized
| ||||||||||||
| static | parent(array $sanitized, int $id): int# | The parent through wp_insert_post_parent (whose default refuses a loop). @param array<string, mixed> $sanitized
| ||||||||||||
| static | slugFilters(string $slug, int $id, string $status, string $type, int $parent, Minn\Content\PostSlugs $slugs): string# | A live post's slug through the reference's three filters: pre_wp_unique_post_slug may settle it; otherwise it is made free in its type's scope, the bad-slug filter judging the slug asked for when nothing else has taken it; and wp_unique_post_slug has the last word. | ||||||||||||
| static | guidAndSlug(array $columns, int $postId, string $type, Minn\Content\PostSlugs $slugs): array# | The row's guid and slug as wp_insert_post settles them (probe insert-defaults): an update keeps the guid it had, in its display form, ignoring a new one asked for; a live post's slug goes through the slug filters.
@return array<string, string> | ||||||||||||
| static | keepsSlug(string $status, string $type): bool# | Whether a save leaves the slug as it is: a draft, a pending post, an auto-draft, a revision, a personal data request. | ||||||||||||
| static | data(array $row, array $sanitized, array $unsanitized, int $postId): array# | The row through wp_insert_post_data (wp_insert_attachment_data for an attachment), handed slashed as the reference hands it and unslashed back.
@return array<string, mixed> |
Internals 3
Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.
| private | stored(int $id): array# | The post as stored, its columns by name. @return array<string, mixed> @return array<string, mixed> | ||||||
| private | prepared(array $columns, ?Minn\Content\PostRecord $before, array $body, Minn\Http\Request $request, string $type): array# | rest_pre_insert_{type} over the prepared post, built as the reference's controller builds it: its id when it edits, the fields the request named in the reference's order, the type always, both dates and edit_date when either date was sent, page_template null. rest_block_hooks_post_types sees it first. What the filter changes or adds is kept; an error refuses the save.
@return array<string, mixed> | ||||||
| private | changed(array $columns, array $data, ?Minn\Content\PostRecord $before): array# | The columns to write: a new post's whole row as the filters left it; an update's own changes plus whatever a filter changed from the row.
@return array<string, mixed> |
Nothing matches.