diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 2f1bbeeab..deb41907e 100644 --- a/wp-admin/post-new.php +++ b/wp-admin/post-new.php @@ -39,6 +39,10 @@ $editing = true; if ( ! current_user_can( $post_type_object->cap->edit_posts ) ) wp_die( __( 'Cheatin’ uh?' ) ); +// Schedule auto-draft cleanup +if ( ! wp_next_scheduled( 'wp_scheduled_auto_draft_delete' ) ) + wp_schedule_event( time(), 'daily', 'wp_scheduled_auto_draft_delete' ); + wp_enqueue_script('autosave'); // Show post form. diff --git a/wp-includes/default-filters.php b/wp-includes/default-filters.php index 96b2635cb..35ee681bc 100644 --- a/wp-includes/default-filters.php +++ b/wp-includes/default-filters.php @@ -253,6 +253,7 @@ add_action( 'transition_post_status', '_transition_post_status', add_action( 'transition_post_status', '_update_term_count_on_transition_post_status', 10, 3 ); add_action( 'comment_form', 'wp_comment_form_unfiltered_html_nonce' ); add_action( 'wp_scheduled_delete', 'wp_scheduled_delete' ); +add_action( 'wp_scheduled_auto_draft_delete', 'wp_delete_auto_drafts' ); add_action( 'admin_init', 'send_frame_options_header', 10, 0 ); add_action( 'importer_scheduled_cleanup', 'wp_delete_attachment' ); add_action( 'upgrader_scheduled_cleanup', 'wp_delete_attachment' ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index d138c6aca..dc00f1119 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3308,7 +3308,6 @@ function _cleanup_header_comment($str) { /** * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. - * Deletes auto-drafts for new posts that are > 7 days old * * @since 2.9.0 */ @@ -3350,11 +3349,6 @@ function wp_scheduled_delete() { wp_delete_comment($comment_id); } } - - // Cleanup old auto-drafts more than 7 days old - $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); - foreach ( (array) $old_posts as $delete ) - wp_delete_post( $delete, true ); // Force delete } /** diff --git a/wp-includes/post.php b/wp-includes/post.php index 80f6bbe39..aaf8bda4d 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -5163,6 +5163,20 @@ function get_post_format_link( $format ) { return get_term_link( $term ); } +/** + * Deletes auto-drafts for new posts that are > 7 days old + * + * @since 3.4.0 + */ +function wp_delete_auto_drafts() { + global $wpdb; + + // Cleanup old auto-drafts more than 7 days old + $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); + foreach ( (array) $old_posts as $delete ) + wp_delete_post( $delete, true ); // Force delete +} + /** * Filters the request to allow for the format prefix. *