Make WordPress Core

Opened 7 years ago

Closed 3 years ago

#40145 closed defect (bug) (worksforme)

Revisions sent to trash never get deleted by WordPress

Reported by: programmin's profile programmin Owned by: adamsilverstein's profile adamsilverstein
Milestone: 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 4 years ago.
First patch
Image 2019-08-01 at 8.20.18 AM.png (27.1 KB) - added by adamsilverstein 4 years ago.
Image 2019-08-01 at 8.21.20 AM.png (44.7 KB) - added by adamsilverstein 4 years ago.
Image 2019-08-01 at 8.21.40 AM.png (17.1 KB) - added by adamsilverstein 4 years ago.

Download all attachments as: .zip

Change History (11)

#1 @swissspidy
7 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

4 years ago

First patch

#2 @Mista-Flo
4 years 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
4 years 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
4 years 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
4 years ago

@programmin or @Mista-Flo can you add any steps to reproduce this issue? See comment above

#6 @Mista-Flo
4 years ago

Hello Adam,

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

#7 @adamsilverstein
3 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from assigned to closed

@Mista-Flo I'm going to go ahead and close this as it "Works for me" - I was unable to reproduce the issue. Perhaps you had some temporary issue that caused this to happen?

If you feel that I have missed something and are able to reproduce, please feel free to re-open this ticket.

Note: See TracTickets for help on using tickets.