Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
  • Loading branch information...
commit 27630a4286087d6417f784335dd43741b46b26de 1 parent 7e8ba69
ryan authored
View
4 wp-admin/post-new.php
@@ -39,6 +39,10 @@
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.
View
1  wp-includes/default-filters.php
@@ -253,6 +253,7 @@
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' );
View
6 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
}
/**
View
14 wp-includes/post.php
@@ -5164,6 +5164,20 @@ function get_post_format_link( $format ) {
}
/**
+ * 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.
*
* @access private
Please sign in to comment.
Something went wrong with that request. Please try again.