API / Minn\Runtime / Autosaves

Autosaves final class

Minn\Runtime\Autosaves · public/minn/src/Minn/Runtime/Autosaves.php · 71 lines

An autosave as the reference's REST autosave makes it (probes rest-autosaves, hook-inputs-2; tests/tools/side-effects.php): the author's own draft is saved in place through wp_update_post; anyone else's post gets the author's one autosave slot, made through wp_insert_post and _wp_put_post_revision, or updated through wp_update_post after wp_creating_autosave. A slot already there is left alone when every field given matches the post. An autosave request (save) defines DOING_AUTOSAVE for the rest of the request, so plugins' save hooks can tell, and no revision is saved while it is; a slot saved on its own (create_post_autosave) defines nothing.

Public

staticsave(Minn\Objects\Post $post, int $userId, array $fields): Minn\Objects\Errors|int#

Saves the given revision fields (post_title, post_content, post_excerpt) as the user's autosave of the post: the post's own id when the draft itself was saved, the slot's otherwise, or the save's refusal.

$fieldsarray<string, string>
staticsaveSlot(Minn\Objects\Post $post, int $userId, array $fields): Minn\Objects\Errors|int#

Saves the given revision fields in the user's autosave slot of the post (create_post_autosave): the slot's id, or the save's refusal.

$fieldsarray<string, string>
staticinPlace(Minn\Objects\Post $post, int $userId): bool#

Whether an autosave saves the post itself: the author's own draft (or auto-draft), while no one else holds its lock.

Internals 2

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

privateslot(int $postId, int $userId): ?int#

The id of the user's autosave of a post, or null.

privatematchesPost(Minn\Objects\Post $post, array $fields): bool#

Whether every field given matches the post's own, whitespace evened out. @param array<string, string> $fields

$fieldsarray<string, string>