2

I'm actually quite surprised WP hasn't already implemented this. I want to add a Cancel button to the edit post screen which will do some cleanup when pressed. After a little playing while watching my tables, here's some things I've noticed.

  1. A new post is created with a post_status of auto-draft. This is changed to draft by the autosave.js script. I'm assuming it's safe to just delete this post on cancel. How can you distinguish between a previously saved draft and a "promoted" autodraft?
  2. Post's with a post_status of draft don't produce a revision. Rather, these posts are updated without any way of reverting back. Is there a way to circumvent this behavior? Possibly by working on a copy of the original and merging on submit?
  3. Once a draft is published, a revision is also created. This leads to all posts taking up at least two rows. Wasteful in my opinion since it's impossible for the two to be different. This revision should be created the next time the post is to be edited. Is it best to just let WP handle the revisions?
  4. Post's with a post_status of publish produce an autosave at a set interval during its editing. This autosave is not removed when submitting the post, instead the post_modified date of the original is updated. Is it safe to delete this autosave on cancel? Thus, preventing the "A more recent version exists" message. Does WP have an auto clean of these or can/should I delete on submit?

Basically what I want is a way for the user to gracefully undo all changes they made during an editing session. Is there anything I have overlooked or am I safe to implement this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.