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
This commit is contained in:
ryan 2012-04-11 20:39:09 +00:00
parent 5e6d499889
commit 28f8e7a63d
2 changed files with 6 additions and 4 deletions

View File

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

View File

@ -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
}
/**