WordPress.org

Make WordPress Core

Ticket #10911: 10911.2.diff

File 10911.2.diff, 871 bytes (added by Denis-de-Bernardy, 4 years ago)
  • wp-admin/upload.php

     
    2020        if ( !current_user_can('edit_posts') ) 
    2121                wp_die( __('You are not allowed to scan for lost attachments.') ); 
    2222 
    23         $all_posts = implode(',', $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type IN ('post', 'page')")); 
    24         $lost = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent > '0' and post_parent NOT IN ($all_posts)"); 
    25  
     23        $lost = $wpdb->get_col("SELECT att.ID FROM $wpdb->posts as att LEFT JOIN $wpdb->posts as post ON att.post_parent = post.ID WHERE att.post_parent > 0 AND att.post_type = 'attachment' and post.ID IS NULL"); 
    2624        $_GET['detached'] = 1; 
    2725 
    2826} elseif ( isset($_GET['found_post_id']) && isset($_GET['media']) ) {