WordPress.org

Make WordPress Core

Opened 17 months ago

Last modified 17 hours ago

#43760 new enhancement

Create a revision when autosaving if the content has changed significantly

Reported by: azaozz Owned by:
Milestone: 5.3 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 17 months ago.
43760.1.diff (5.0 KB) - added by soulseekah 17 months ago.
diff-based implementation

Download all attachments as: .zip

Change History (6)

@azaozz
17 months ago

#1 @azaozz
17 months ago

  • Keywords has-patch needs-testing added

@soulseekah
17 months ago

diff-based implementation

#2 @soulseekah
17 months 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
3 months 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 cases like having a post with 10 paragraphs and adding another one (we want a revision), vs. having a post with 3 paragraphs and editing few words in one of them (we don't want a revision).

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 :)

Last edited 3 months ago by azaozz (previous) (diff)

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


17 hours ago

Note: See TracTickets for help on using tickets.