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

git-svn-id: http://svn.automattic.com/wordpress/trunk@7638 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-04-09 20:09:45 +00:00
parent 5b1208ebc3
commit 132ac51a5a
2 changed files with 19 additions and 5 deletions

View File

@ -506,10 +506,9 @@ function _relocate_children( $old_ID, $new_ID ) {
}
function get_available_post_statuses($type = 'post') {
global $wpdb;
$stati = wp_count_posts($type);
$stati = $wpdb->get_col($wpdb->prepare("SELECT DISTINCT post_status FROM $wpdb->posts WHERE post_type = %s", $type));
return $stati;
return array_keys(get_object_vars($stati));
}
function wp_edit_posts_query( $q = false ) {

View File

@ -828,12 +828,23 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
$user = wp_get_current_user();
$cache_key = $type;
if ( !empty($perm) )
$cache_key .= '_' . $perm;
$query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
if ( 'readable' == $perm && is_user_logged_in() ) {
if ( !current_user_can("read_private_{$type}s") )
if ( !current_user_can("read_private_{$type}s") ) {
$cache_key .= '_' . $user->ID;
$query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))";
}
}
$query .= ' GROUP BY post_status';
$count = wp_cache_get($cache_key, 'counts');
if ( false !== $count )
return $count;
$count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
$stats = array( );
@ -841,9 +852,13 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
$stats[$row['post_status']] = $row['num_posts'];
}
return (object) $stats;
$stats = (object) $stats;
wp_cache_set($cache_key, $stats, 'counts');
return $stats;
}
/**
* wp_count_attachments() - Count number of attachments
*