Make WordPress Core

Opened 3 years ago

Last modified 11 months ago

#40145 assigned defect (bug)

Revisions sent to trash never get deleted by WordPress

Reported by: programmin Owned by: adamsilverstein
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Revisions Keywords: has-patch reporter-feedback
Focuses: Cc:


If you remove an autosave of a page like so:

$autosave = wp_get_post_autosave( id )

it actually gets in the database such that it will never be removed, even if you empty trash of posts and pages later.

You can see all the revisions it wants to leave forever with:

SELECT * FROM wordpress.wp_posts where post_status = 'trash' and post_type = 'revision' order by id desc;

Attachments (4)

40145.patch (490 bytes) - added by Mista-Flo 15 months ago.
First patch
Image 2019-08-01 at 8.20.18 AM.png (27.1 KB) - added by adamsilverstein 12 months ago.
Image 2019-08-01 at 8.21.20 AM.png (44.7 KB) - added by adamsilverstein 12 months ago.
Image 2019-08-01 at 8.21.40 AM.png (17.1 KB) - added by adamsilverstein 12 months ago.

Download all attachments as: .zip

Change History (10)

#1 @swissspidy
3 years ago

  • Keywords needs-patch added
  • Summary changed from Revisions sent to trash never get deleted by Wordpress. to Revisions sent to trash never get deleted by WordPress
  • Version trunk deleted

15 months ago

First patch

#2 @Mista-Flo
15 months ago

  • Keywords has-patch added; needs-patch removed

The patch is quite simple, just check if the given post is a revision, if so, we remove it in the database

#3 @Mista-Flo
12 months ago

@adamsilverstein @karmatosed Hello, if you could have a look since you are component maintainers for post revisions, it would be highly appreciated :)

#4 @adamsilverstein
12 months ago

  • Component changed from Posts, Post Types to Revisions
  • Keywords reporter-feedback added
  • Owner set to adamsilverstein
  • Severity changed from normal to minor
  • Status changed from new to assigned

Hello @Mista-Flo - thanks for the ping and the bug report.

I attempted to reproduce this and was unable to.

Here is what I tried (I am testing against trunk):

  • Empty database and create a new post.
  • Publish post, make some changes to trigger an autosave and exit the post exit screen.

At this point I have three records in the database post table: one for the post itself, one for a revision created of the initial save, and one autosave


The I opened wp-cli shell and issued the commands from the ticket description:
$autosave = wp_get_post_autosave( [post id] );

Checking the database I see that the autosave record was removed:

I tried again with the ID of one of the revisions and again the record was correctly deleted:


Perhaps I have missed some step to reproduce? What version of WordPress are you using when you see this issue?

Can you please try again on your end first disabling all plugins and also switching to a default theme like twentynineteen if possible to eliminate the possibility that a plugin or theme code is affecting autosaves.

#5 @adamsilverstein
11 months ago

@programmin or @Mista-Flo can you add any steps to reproduce this issue? See comment above https://core.trac.wordpress.org/ticket/40145#comment:4

#6 @Mista-Flo
11 months ago

Hello Adam,

Sorry did not have time to dig into it. Will try to find out soon.

Note: See TracTickets for help on using tickets.