Make WordPress Core

Opened 10 years ago

Closed 16 months ago

#38899 closed defect (bug) (maybelater)

Deletion of auto-drafts and trashed posts never gets scheduled unless user accesses admin pages

Reported by: westonruter Owned by: westonruter
Priority: normal Milestone:
Component: Administration Version:
Severity: normal Keywords: has-patch 2nd-opinion
Cc: Focuses: rest-api

Description (last modified by westonruter)

As noted in #38615:

It turns out that the cron event that does wp_delete_auto_drafts() is only scheduled when a user lands on post-new.php:

<?php
// Schedule auto-draft cleanup
if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) )
        wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' );

This logic should be added to WP_Customize_Manager as well so that these starter content auto-draft posts will get garbage collected (as well as the unpublished customize_changeset posts themselves) will get garbage-collected in the rare case where a user never goes to post-new.php on a given install. A user never visiting post-new.php is entirely possible if the user does all of their site management in the customizer or via the REST API.

What's more is that the scheduling of trash deletion is also dependent on the user first accessing the admin, as wp-admin/admin.php contains:

<?php
// Schedule trash collection
if ( ! wp_next_scheduled( 'wp_scheduled_delete' ) && ! wp_installing() )
        wp_schedule_event(time(), 'daily', 'wp_scheduled_delete');

So as such, this is also a concern for purely headless WP installs that make use of the REST API exclusively. If a site gets installed headlessly (e.g. via WP-CLI) and the admin is never accessed, then neither trashed posts nor auto-draft posts will never get deleted because they are never scheduled.

Attachments (2)

38899.0.diff (616 bytes ) - added by westonruter 10 years ago.
38899.1.diff (2.4 KB ) - added by westonruter 10 years ago.

Download all attachments as: .zip

Change History (13)

#1 @westonruter
10 years ago

  • Owner set to westonruter
  • Status newaccepted

@westonruter
10 years ago

#2 @westonruter
10 years ago

  • Component CustomizeREST API
  • Description modified (diff)
  • Summary Customize: Ensure auto-draft deletion gets scheduledDeletion of auto-drafts and trashed posts never gets scheduled unless user accesses admin pages

@westonruter
10 years ago

#3 @westonruter
10 years ago

  • Keywords has-patch added

38899.1.diff moves the scheduling of trashed post deletion and auto-draft deletion to a new wp_schedule_garbage_collection() function which gets called at init. I suppose this could instead be done once during the wp_install action, but since wp_install() is pluggable I'd be nervous that some installs could happen to not get these events scheduled.

#4 @westonruter
10 years ago

  • Keywords 2nd-opinion added

#5 @joehoyle
10 years ago

I'm +1 on this, I think the patch looks good. I don't know if this needs to happen in 4.7, but I think it makes sense to do at some point.

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


10 years ago

#7 @joehoyle
10 years ago

  • Milestone 4.74.8

#8 @rmccue
10 years ago

  • Component REST APIAdministration
  • Focuses rest-api added

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


9 years ago

#10 @flixos90
9 years ago

  • Milestone 4.8Future Release

#11 @westonruter
16 months ago

  • Milestone Future Release
  • Resolutionmaybelater
  • Status acceptedclosed
Note: See TracTickets for help on using tickets.