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
This commit is contained in:
ryan 2012-04-12 18:49:48 +00:00
parent 7e8ba69143
commit 27630a4286
4 changed files with 19 additions and 6 deletions

View File

@ -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.

View File

@ -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' );

View File

@ -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 File

@ -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.
*