WordPress.org

Make WordPress Core

Ticket #11442: 11442.2.diff

File 11442.2.diff, 1.4 KB (added by nacin, 4 years ago)

Garbage collector added to wp_scheduled_delete()

  • wp-includes/functions.php

     
    35113511 
    35123512        $delete_timestamp = time() - (60*60*24*EMPTY_TRASH_DAYS); 
    35133513 
     3514        $posts_in_trash = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE post_status = 'trash'", ARRAY_A); 
     3515 
     3516        foreach ( (array) $posts_in_trash as $post ) { 
     3517                $in_trash[] = $post['ID']; 
     3518        } 
     3519 
     3520        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->postmeta WHERE post_id NOT IN (%s)", implode( ',', $in_trash ) ) ); 
    35143521        $posts_to_delete = $wpdb->get_results($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); 
    35153522 
    35163523        foreach ( (array) $posts_to_delete as $post ) { 
    35173524                wp_delete_post($post['post_id']); 
    35183525        } 
    35193526 
     3527        $comments_in_trash = $wpdb->get_results("SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = 'trash'", ARRAY_A); 
     3528        foreach ( (array) $comments_in_trash as $comment ) { 
     3529                $in_trash[] = $comment['comment_ID']; 
     3530        } 
     3531 
     3532        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->commentmeta WHERE comment_id NOT IN (%s)", implode( ',', $in_trash ) ) ); 
    35203533        $comments_to_delete = $wpdb->get_results($wpdb->prepare("SELECT comment_id FROM $wpdb->commentmeta WHERE meta_key = '_wp_trash_meta_time' AND meta_value < '%d'", $delete_timestamp), ARRAY_A); 
    35213534 
    35223535        foreach ( (array) $comments_to_delete as $comment ) {