mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 20:30:23 +00:00
Use wp_count_posts() to determine availabel statuses for get_available_post_statuses(). fixes #6654 for trunk
git-svn-id: https://develop.svn.wordpress.org/trunk@7638 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
+17
-2
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user