WordPress.org

Make WordPress Core

Ticket #28381: unattached_attachments_patch.patch

File unattached_attachments_patch.patch, 1.6 KB (added by khromov, 7 years ago)
  • wp-admin/includes/class-wp-media-list-table.php

     
    4747                $type_links = array();
    4848                $_num_posts = (array) wp_count_attachments();
    4949                $_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
    50                 $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
     50                $total_orphans = wp_count_unattached_attachments();
    5151                $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    5252                foreach ( $matches as $type => $reals )
    5353                        foreach ( $reals as $real )
  • wp-includes/post.php

     
    22922292}
    22932293
    22942294/**
     2295 * Count number of unattached attachments
     2296 *
     2297 * @since 4.0
     2298 *
     2299 * @return int The number of unattached attachments
     2300 */
     2301function wp_count_unattached_attachments()
     2302{
     2303        global $wpdb;
     2304        $unattached_attachments = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" );
     2305
     2306        /**
     2307         * Modify returned unattached attachment count
     2308         *
     2309         * @since 4.0
     2310         *
     2311         * @param int $unattached_attachments   Number of unattached attachments
     2312         */
     2313        return apply_filters( 'wp_count_unattached_attachments', (int) $unattached_attachments);
     2314}
     2315
     2316/**
    22952317 * Get default post mime types
    22962318 *
    22972319 * @since 2.9.0