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 { |
42 | 42 | } |
43 | 43 | |
44 | 44 | function get_views() { |
45 | | global $wpdb, $post_mime_types, $avail_post_mime_types; |
| 45 | global $post_mime_types, $avail_post_mime_types; |
46 | 46 | |
47 | 47 | $type_links = array(); |
48 | 48 | $_num_posts = (array) wp_count_attachments(); |
49 | 49 | $_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 | |
51 | 61 | $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); |
52 | 62 | foreach ( $matches as $type => $reals ) |
53 | 63 | foreach ( $reals as $real ) |
diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index 4b6417f..28d9eb8 100644
a
|
b
|
function media_upload_tabs() { |
33 | 33 | * @return array $tabs with gallery if post has image attachment |
34 | 34 | */ |
35 | 35 | function 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'] ); |
40 | 38 | return $tabs; |
41 | 39 | } |
42 | 40 | |
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'] ); |
50 | 57 | return $tabs; |
51 | 58 | } |
52 | 59 | |
diff --git a/wp-includes/query.php b/wp-includes/query.php
index 04286aa..cf35ef8 100644
a
|
b
|
class WP_Query { |
1399 | 1399 | , 'sentence' |
1400 | 1400 | , 'fields' |
1401 | 1401 | , 'menu_order' |
| 1402 | , 'query_context' |
1402 | 1403 | ); |
1403 | 1404 | |
1404 | 1405 | foreach ( $keys as $key ) { |
… |
… |
class WP_Query { |
2038 | 2039 | case 'id=>parent': |
2039 | 2040 | $fields = "$wpdb->posts.ID, $wpdb->posts.post_parent"; |
2040 | 2041 | break; |
| 2042 | case 'count': |
| 2043 | $fields = "COUNT(*)"; |
| 2044 | break; |
2041 | 2045 | default: |
2042 | 2046 | $fields = "$wpdb->posts.*"; |
2043 | 2047 | } |
… |
… |
class WP_Query { |
2667 | 2671 | return $r; |
2668 | 2672 | } |
2669 | 2673 | |
| 2674 | if ( 'count' == $q['fields'] ) { |
| 2675 | $this->posts = $wpdb->get_var( $this->request ); |
| 2676 | return $this->posts; |
| 2677 | } |
| 2678 | |
2670 | 2679 | $split_the_query = ( $old_request == $this->request && "$wpdb->posts.*" == $fields && !empty( $limits ) && $q['posts_per_page'] < 500 ); |
2671 | 2680 | $split_the_query = apply_filters( 'split_the_query', $split_the_query, $this ); |
2672 | 2681 | |