Opened 8 years ago
Last modified 4 years 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 )
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)
Change History (12)
#2
@
8 years 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
#5
@
8 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.
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 atinit
. I suppose this could instead be done once during thewp_install
action, but sincewp_install()
is pluggable I'd be nervous that some installs could happen to not get these events scheduled.