WordPress.org

Make WordPress Core

Ticket #16785: 16785.diff

File 16785.diff, 1.7 KB (added by solarissmoke, 4 years ago)

Delete old auto-drafts in wp_scheduled_delete instead of get_default_post_to_edit

  • wp-includes/functions.php

     
    42554255 
    42564256/** 
    42574257 * Permanently deletes posts, pages, attachments, and comments which have been in the trash for EMPTY_TRASH_DAYS. 
     4258 * Also removes auto-drafts which are more than 7 days old 
    42584259 * 
    42594260 * @since 2.9.0 
    42604261 */ 
     
    42964297                        wp_delete_comment($comment_id); 
    42974298                } 
    42984299        } 
     4300         
     4301        // Cleanup old auto-drafts 
     4302        $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); 
     4303        foreach ( (array) $old_posts as $delete ) 
     4304                wp_delete_post( $delete, true ); // Force delete 
    42994305} 
    43004306 
    43014307/** 
  • wp-admin/includes/post.php

     
    397397                $post_excerpt = esc_html( stripslashes( $_REQUEST['excerpt'] )); 
    398398 
    399399        if ( $create_in_db ) { 
    400                 // Cleanup old auto-drafts more than 7 days old 
    401                 $old_posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'auto-draft' AND DATE_SUB( NOW(), INTERVAL 7 DAY ) > post_date" ); 
    402                 foreach ( (array) $old_posts as $delete ) 
    403                         wp_delete_post( $delete, true ); // Force delete 
    404400                $post_id = wp_insert_post( array( 'post_title' => __( 'Auto Draft' ), 'post_type' => $post_type, 'post_status' => 'auto-draft' ) ); 
    405401                $post = get_post( $post_id ); 
    406402                if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) && get_option( 'default_post_format' ) )