Make WordPress Core

Changeset 7638


Ignore:
Timestamp:
04/09/2008 08:09:45 PM (18 years ago)
Author:
ryan
Message:

Use wp_count_posts() to determine availabel statuses for get_available_post_statuses(). fixes #6654 for trunk

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r7614 r7638  
    507507
    508508function get_available_post_statuses($type = 'post') {
    509         global $wpdb;
    510 
    511         $stati = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_status FROM $wpdb->posts WHERE post_type = %s", $type));
    512         return $stati;
     509        $stati = wp_count_posts($type);
     510
     511        return array_keys(get_object_vars($stati));
    513512}
    514513
  • trunk/wp-includes/post.php

    r7601 r7638  
    829829        $user = wp_get_current_user();
    830830
     831        $cache_key = $type;
     832        if ( !empty($perm) )
     833                $cache_key .= '_' . $perm;
     834
    831835        $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
    832836        if ( 'readable' == $perm && is_user_logged_in() ) {
    833                 if ( !current_user_can("read_private_{$type}s") )
     837                if ( !current_user_can("read_private_{$type}s") ) {
     838                        $cache_key .= '_' . $user->ID;
    834839                        $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))";
     840                }
    835841        }
    836842        $query .= ' GROUP BY post_status';
     843
     844        $count = wp_cache_get($cache_key, 'counts');
     845        if ( false !== $count )
     846                return $count;
     847
    837848        $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    838849
     
    842853        }
    843854
    844         return (object) $stats;
    845 }
     855        $stats = (object) $stats;
     856        wp_cache_set($cache_key, $stats, 'counts');
     857
     858        return $stats;
     859}
     860
    846861
    847862/**
Note: See TracChangeset for help on using the changeset viewer.