WordPress.org

Make WordPress Core

Opened 19 months ago

Last modified 13 months ago

#38899 accepted defect (bug)

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

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

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 19 months ago.
38899.1.diff (2.4 KB) - added by westonruter 19 months ago.

Download all attachments as: .zip

Change History (12)

#1 @westonruter
19 months ago

  • Owner set to westonruter
  • Status changed from new to accepted

#2 @westonruter
19 months ago

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

#3 @westonruter
19 months 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
19 months ago

  • Keywords 2nd-opinion added

#5 @joehoyle
19 months 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.


19 months ago

#7 @joehoyle
19 months ago

  • Milestone changed from 4.7 to 4.8

#8 @rmccue
17 months ago

  • Component changed from REST API to Administration
  • Focuses rest-api added

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


13 months ago

#10 @flixos90
13 months ago

  • Milestone changed from 4.8 to Future Release
Note: See TracTickets for help on using tickets.