WordPress.org

Make WordPress Core

Opened 3 years ago

Last modified 2 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:
PR Number:

Description

If you remove an autosave of a page like so:

<?php
$autosave = wp_get_post_autosave( id )
wp_trash_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 6 months ago.
First patch
Image 2019-08-01 at 8.20.18 AM.png (27.1 KB) - added by adamsilverstein 3 months ago.
Image 2019-08-01 at 8.21.20 AM.png (44.7 KB) - added by adamsilverstein 3 months ago.
Image 2019-08-01 at 8.21.40 AM.png (17.1 KB) - added by adamsilverstein 3 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

@Mista-Flo
6 months ago

First patch

#2 @Mista-Flo
6 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
3 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
3 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

ahttps://core.trac.wordpress.org/raw-attachment/ticket/40145/Image%202019-08-01%20at%208.20.18%20AM.png

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

Checking the database I see that the autosave record was removed:
https://core.trac.wordpress.org/raw-attachment/ticket/40145/Image%202019-08-01%20at%208.21.20%20AM.png

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

https://core.trac.wordpress.org/raw-attachment/ticket/40145/Image%202019-08-01%20at%208.21.40%20AM.png

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
2 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
2 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.