Make WordPress Core


Ignore:
Timestamp:
02/29/2008 09:49:49 PM (17 years ago)
Author:
ryan
Message:

Add option to check caps when querying a particular post status. fixes #6052

File:
1 edited

Legend:

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

    r7100 r7109  
    823823 * @return array Number of posts for each status
    824824 */
    825 function wp_count_posts( $type = 'post' ) {
     825function wp_count_posts( $type = 'post', $perm = '' ) {
    826826    global $wpdb;
    827827
    828     $count = $wpdb->get_results( $wpdb->prepare( "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s GROUP BY post_status", $type ), ARRAY_A );
     828    $user = wp_get_current_user();
     829
     830    $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s";
     831    if ( 'readable' == $perm && is_user_logged_in() ) {
     832        if ( !current_user_can("read_private_{$type}s") )
     833            $query .= " AND (post_status != 'private' OR ( post_author = '$user->ID' AND post_status = 'private' ))";
     834    }
     835    $query .= ' GROUP BY post_status';
     836    $count = $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
    829837
    830838    $stats = array( );
Note: See TracChangeset for help on using the changeset viewer.