Make WordPress Core

Ticket #17019: 17019.4.diff

File 17019.4.diff, 3.1 KB (added by wonderboymusic, 11 years ago)
  • src/wp-admin/includes/class-wp-media-list-table.php

     
    4242        }
    4343
    4444        function get_views() {
    45                 global $wpdb, $post_mime_types, $avail_post_mime_types;
     45                global $post_mime_types, $avail_post_mime_types;
    4646
    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
     51                $args = array(
     52                        'fields' => 'count',
     53                        'post_type' => 'attachment',
     54                        'post_status' => 'any',
     55                        'post_parent' => 0,
     56                        'suppress_filters' => false,
     57                        'query_context' => 'attachment_orphans_count',
     58                );
     59                $total_orphans = (int) get_posts( $args );
     60
    5161                $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
    5262                foreach ( $matches as $type => $reals )
    5363                        foreach ( $reals as $real )
  • src/wp-admin/includes/media.php

     
    4040 * @return array $tabs with gallery if post has image attachment
    4141 */
    4242function update_gallery_tab($tabs) {
    43         global $wpdb;
    44 
    4543        if ( !isset($_REQUEST['post_id']) ) {
    4644                unset($tabs['gallery']);
    4745                return $tabs;
     
    4947
    5048        $post_id = intval($_REQUEST['post_id']);
    5149
    52         if ( $post_id )
    53                 $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
     50        if ( $post_id ) {
     51                $args = array(
     52                        'fields' => 'count',
     53                        'post_type' => 'attachment',
     54                        'post_status' => 'any',
     55                        'post_parent' => $post_id,
     56                        'suppress_filters' => false,
     57                        'query_context' => 'gallery_attachment_count',
     58                );
     59                $attachments = (int) get_posts( $args );
     60        }
    5461
    5562        if ( empty($attachments) ) {
    5663                unset($tabs['gallery']);
  • src/wp-includes/query.php

     
    14231423                        , 'sentence'
    14241424                        , 'fields'
    14251425                        , 'menu_order'
     1426                        , 'query_context'
    14261427                );
    14271428
    14281429                foreach ( $keys as $key ) {
     
    22712272                        case 'id=>parent':
    22722273                                $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent";
    22732274                                break;
     2275                        case 'count':
     2276                                $fields = "COUNT(*)";
     2277                                break;
    22742278                        default:
    22752279                                $fields = "$wpdb->posts.*";
    22762280                }
     
    29242928                        return $r;
    29252929                }
    29262930
     2931                if ( 'count' == $q['fields'] ) {
     2932                        $this->posts = $wpdb->get_var( $this->request );
     2933                        return $this->posts;
     2934                }
     2935               
    29272936                $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
    29282937                $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
    29292938