[wp-trac] [WordPress Trac] #38899: Deletion of auto-drafts and trashed posts never gets scheduled unless user accesses admin pages (was: Customize: Ensure auto-draft deletion gets scheduled)
WordPress Trac
noreply at wordpress.org
Tue Nov 22 04:06:11 UTC 2016
#38899: Deletion of auto-drafts and trashed posts never gets scheduled unless user
accesses admin pages
--------------------------+--------------------------
Reporter: westonruter | Owner: westonruter
Type: defect (bug) | Status: accepted
Priority: normal | Milestone: 4.7
Component: REST API | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------+--------------------------
Changes (by westonruter):
* component: Customize => REST API
Old description:
> As [https://core.trac.wordpress.org/ticket/38615#comment:37 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
> <?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.
New description:
As [https://core.trac.wordpress.org/ticket/38615#comment:37 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
<?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
<?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.
--
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38899#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list