Make WordPress Core

Ticket #30928: 30928.diff

File 30928.diff, 1.8 KB (added by MikeHansenMe, 10 years ago)
  • src/wp-includes/post.php

     
    23462346function wp_count_posts( $type = 'post', $perm = '' ) {
    23472347        global $wpdb;
    23482348
    2349         if ( ! post_type_exists( $type ) )
     2349        if ( ! post_type_exists( $type ) ) {
    23502350                return new stdClass;
     2351        }
    23512352
    23522353        $cache_key = _count_posts_cache_key( $type, $perm );
    23532354
    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 
    23652355        $counts = wp_cache_get( $cache_key, 'counts' );
    23662356        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';
    23672367                $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    23682368                $counts = array_fill_keys( get_post_stati(), 0 );
    23692369
    2370                 foreach ( $results as $row )
     2370                foreach ( $results as $row ) {
    23712371                        $counts[ $row['post_status'] ] = $row['num_posts'];
     2372                }
    23722373
    23732374                $counts = (object) $counts;
    23742375                wp_cache_set( $cache_key, $counts, 'counts' );