From 28f8e7a63def74d0b1c6a7d65d1fefc052cd662c Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 11 Apr 2012 20:39:09 +0000 Subject: [PATCH] Move deletion of auto-draft posts to the wp_scheduled_delete cron function. Props mgolawala. fixes #19663 git-svn-id: http://svn.automattic.com/wordpress/trunk@20440 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 4 ---- wp-includes/functions.php | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 9df362d2f..72ba517cf 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -417,10 +417,6 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false ) $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] )); if ( $create_in_db ) { - // 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 $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); $post = get_post( $post_id ); if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) ) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 453a83c00..c31d52d6b 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -3308,6 +3308,7 @@ 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 */ @@ -3349,6 +3350,11 @@ 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 } /**