Make WordPress Core

Opened 7 years ago

Last modified 5 years ago

#43760 new enhancement

Create a revision when autosaving if the content has changed significantly

Reported by: azaozz's profile azaozz Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Autosave Keywords: has-patch needs-testing has-unit-tests 2nd-opinion
Focuses: Cc:

Description

Sometimes a user may edit a post for hours without saving it. We have autosaves to prevent any data loss. However in some cases there may be an user or a server error and the content may not be submitted or the post may be "empty". This doesn't happen often, but is usually devastating for the users. They just lost hours of work!

To safeguard against these cases, we can create post revisions when the autosave data is significantly different than the existing post.

Attachments (2)

43760.patch (3.0 KB) - added by azaozz 7 years ago.
43760.1.diff (5.0 KB) - added by soulseekah 7 years ago.
diff-based implementation

Download all attachments as: .zip

Change History (8)

@azaozz
7 years ago

#1 @azaozz
7 years ago

  • Keywords has-patch needs-testing added

@soulseekah
7 years ago

diff-based implementation

#2 @soulseekah
7 years ago

  • Keywords has-unit-tests added

Interesting.

43760.1.diff is my version for a diff-based implementation instead. Just as an idea with some tests that can also be repurposed for your patch.

Also, a suggestion on the wp_create_revision_for_autosave filter: I think should send in the $post_data and $autosave_data, the count probably useless as users would be using their own heuristics.

Thoughts?

#3 @azaozz
5 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Future Release to 5.3

@soulseekah thanks for the alternate patch. Yeah, using text diff will be more precise but slower, and since this will always run in the background, making it a bit slower wouldn't matter.

However counting lines may be somehow problematic. It is possible to have all of post_content on one line which would mean lots of revisions with minimal changes. Thinking we should be counting something else, perhaps number of changed places + size of changes, or just added + deleted characters.

Also thinking it would be good to keep the "sliding scale" based on string length of post_content. So for longer posts the percentage of changes would be less. That will catch vases like having a post with 10 paragraphs and adding another one, vs. having a post with 3 paragraphs and editing few words in one of them.

Also perhaps the wp_create_revision_for_autosave_threshold that filters the percentage of changes needed to trigger a revision may be a bit of overkill? Plugins that would want to look there will be able to do everything they need by using the wp_create_revision_for_autosave filter.

Lets try to add that in 5.3 :)

Version 0, edited 5 years ago by azaozz (next)

This ticket was mentioned in Slack in #core by david.baumwald. View the logs.


5 years ago

#5 @desrosj
5 years ago

@azaozz Any objection to punting this one? It seems to still need work.

#6 @azaozz
5 years ago

  • Milestone changed from 5.3 to Future Release

Yeah, needs more work, and more unit tests to get this right. It can mask other autosave errors, will need to think a bit more about how to prevent that.

Note: See TracTickets for help on using tickets.