Make WordPress Core

Ticket #17019: 17019.2.diff

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

    diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php
    index 67fd187..afd4839 100644
    a b class WP_Media_List_Table extends WP_List_Table { 
    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 )
  • wp-admin/includes/media.php

    diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
    index 4b6417f..28d9eb8 100644
    a b function media_upload_tabs() { 
    3333 * @return array $tabs with gallery if post has image attachment
    3434 */
    3535function update_gallery_tab($tabs) {
    36         global $wpdb;
    37 
    38         if ( !isset($_REQUEST['post_id']) ) {
    39                 unset($tabs['gallery']);
     36        if ( ! isset( $_REQUEST['post_id'] ) ) {
     37                unset( $tabs['gallery'] );
    4038                return $tabs;
    4139        }
    4240
    43         $post_id = intval($_REQUEST['post_id']);
    44 
    45         if ( $post_id )
    46                 $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 ) ) );
    47 
    48         if ( empty($attachments) ) {
    49                 unset($tabs['gallery']);
     41        $post_id = intval( $_REQUEST['post_id'] );
     42
     43        if ( $post_id ) {
     44                $args = array( 
     45                        'fields' => 'count',
     46                        'post_type' => 'attachment',
     47                        'post_status' => 'any',
     48                        'post_parent' => $post_id,
     49                        'suppress_filters' => false,
     50                        'query_context' => 'gallery_attachment_count',
     51                );
     52                $attachments = (int) get_posts( $args );
     53        }
     54       
     55        if ( empty( $attachments ) ) {
     56                unset( $tabs['gallery'] );
    5057                return $tabs;
    5158        }
    5259
  • wp-includes/query.php

    diff --git a/wp-includes/query.php b/wp-includes/query.php
    index 04286aa..cf35ef8 100644
    a b class WP_Query { 
    13991399                        , 'sentence'
    14001400                        , 'fields'
    14011401                        , 'menu_order'
     1402                        , 'query_context'
    14021403                );
    14031404
    14041405                foreach ( $keys as $key ) {
    class WP_Query { 
    20382039                        case 'id=>parent':
    20392040                                $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent";
    20402041                                break;
     2042                        case 'count':
     2043                                $fields = "COUNT(*)";
     2044                                break;
    20412045                        default:
    20422046                                $fields = "$wpdb->posts.*";
    20432047                }
    class WP_Query { 
    26672671                        return $r;
    26682672                }
    26692673
     2674                if ( 'count' == $q['fields'] ) {
     2675                        $this->posts = $wpdb->get_var( $this->request );
     2676                        return $this->posts;
     2677                }
     2678               
    26702679                $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 );
    26712680                $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this );
    26722681