Make WordPress Core

Ticket #30928: 30928.patch

File 30928.patch, 1.5 KB (added by SergeyBiryukov, 10 years ago)
  • src/wp-includes/post.php

     
    23512351
    23522352        $cache_key = _count_posts_cache_key( $type, $perm );
    23532353
     2354        $counts = wp_cache_get( $cache_key, 'counts' );
     2355        if ( $counts ) {
     2356                /** This filter is documented in wp-includes/post.php */
     2357                return apply_filters( 'wp_count_posts', $counts, $type, $perm );
     2358        }
     2359
    23542360        $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    23552361        if ( 'readable' == $perm && is_user_logged_in() ) {
    23562362                $post_type_object = get_post_type_object($type);
     
    23622368        }
    23632369        $query .= ' GROUP BY post_status';
    23642370
    2365         $counts = wp_cache_get( $cache_key, 'counts' );
    2366         if ( false === $counts ) {
    2367                 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    2368                 $counts = array_fill_keys( get_post_stati(), 0 );
     2371        $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
     2372        $counts = array_fill_keys( get_post_stati(), 0 );
    23692373
    2370                 foreach ( $results as $row )
    2371                         $counts[ $row['post_status'] ] = $row['num_posts'];
    2372 
    2373                 $counts = (object) $counts;
    2374                 wp_cache_set( $cache_key, $counts, 'counts' );
     2374        foreach ( $results as $row ) {
     2375                $counts[ $row['post_status'] ] = $row['num_posts'];
    23752376        }
    23762377
     2378        $counts = (object) $counts;
     2379        wp_cache_set( $cache_key, $counts, 'counts' );
     2380
    23772381        /**
    23782382         * Modify returned post counts by status for the current post type.
    23792383         *