Ticket #30928: 30928.diff
File 30928.diff, 1.8 KB (added by , 10 years ago) |
---|
-
src/wp-includes/post.php
2346 2346 function wp_count_posts( $type = 'post', $perm = '' ) { 2347 2347 global $wpdb; 2348 2348 2349 if ( ! post_type_exists( $type ) ) 2349 if ( ! post_type_exists( $type ) ) { 2350 2350 return new stdClass; 2351 } 2351 2352 2352 2353 $cache_key = _count_posts_cache_key( $type, $perm ); 2353 2354 2354 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";2355 if ( 'readable' == $perm && is_user_logged_in() ) {2356 $post_type_object = get_post_type_object($type);2357 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) {2358 $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))",2359 get_current_user_id()2360 );2361 }2362 }2363 $query .= ' GROUP BY post_status';2364 2365 2355 $counts = wp_cache_get( $cache_key, 'counts' ); 2366 2356 if ( false === $counts ) { 2357 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2358 if ( 'readable' == $perm && is_user_logged_in() ) { 2359 $post_type_object = get_post_type_object($type); 2360 if ( ! current_user_can( $post_type_object->cap->read_private_posts ) ) { 2361 $query .= $wpdb->prepare( " AND (post_status != 'private' OR ( post_author = %d AND post_status = 'private' ))", 2362 get_current_user_id() 2363 ); 2364 } 2365 } 2366 $query .= ' GROUP BY post_status'; 2367 2367 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2368 2368 $counts = array_fill_keys( get_post_stati(), 0 ); 2369 2369 2370 foreach ( $results as $row ) 2370 foreach ( $results as $row ) { 2371 2371 $counts[ $row['post_status'] ] = $row['num_posts']; 2372 } 2372 2373 2373 2374 $counts = (object) $counts; 2374 2375 wp_cache_set( $cache_key, $counts, 'counts' );