From 27630a4286087d6417f784335dd43741b46b26de Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 12 Apr 2012 18:49:48 +0000 Subject: [PATCH] Schedule auto-draft deletion from post-new.php instead of from admin.php. This provides better throttling for large multisite installs and reduces the risk of a delete avalanche. fixes #19663 git-svn-id: http://svn.automattic.com/wordpress/trunk@20453 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/post-new.php | 4 ++++ wp-includes/default-filters.php | 1 + wp-includes/functions.php | 6 ------ wp-includes/post.php | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/wp-admin/post-new.php b/wp-admin/post-new.php index 2f1bbeeab4..deb41907e2 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 96b2635cb3..35ee681bc4 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 d138c6acaa..dc00f1119b 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 80f6bbe392..aaf8bda4d8 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. *