Make WordPress Core

Ticket #16603: 16603.diff

File 16603.diff, 1.4 KB (added by nacin, 12 years ago)

Something like this.

  • wp-includes/post.php

     
    19891989
    19901990        $user = wp_get_current_user();
    19911991
    1992         $cache_key = $type;
     1992        $cache_key = 'posts-' . $type;
    19931993
    19941994        $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    19951995        if ( 'readable' == $perm && is_user_logged_in() ) {
     
    20012001        }
    20022002        $query .= ' GROUP BY post_status';
    20032003
    2004         $count = wp_cache_get($cache_key, 'counts');
    2005         if ( false !== $count )
    2006                 return $count;
     2004        $counts = wp_cache_get( $cache_key, 'counts' );
     2005        if ( false !== $counts )
     2006                return apply_filters( 'count_posts', $counts, $type, $perm );
    20072007
    2008         $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
     2008        $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    20092009
    2010         $stats = array();
    2011         foreach ( get_post_stati() as $state )
    2012                 $stats[$state] = 0;
     2010        $counts = array_fill_keys( get_post_stati(), 0 );
    20132011
    2014         foreach ( (array) $count as $row )
    2015                 $stats[$row['post_status']] = $row['num_posts'];
     2012        foreach ( $results as $row )
     2013                $counts[ $row['post_status'] ] = $row['num_posts'];
    20162014
    2017         $stats = (object) $stats;
    2018         wp_cache_set($cache_key, $stats, 'counts');
     2015        $counts = (object) $counts;
     2016        wp_cache_set( $cache_key, $counts, 'counts' );
    20192017
    2020         return $stats;
     2018        return apply_filters( 'count_posts', $counts, $type, $perm );
    20212019}
    20222020
    20232021/**