Ticket #16603: 16603.2.diff
File 16603.2.diff, 2.6 KB (added by , 11 years ago) |
---|
-
src/wp-includes/post.php
2067 2067 } 2068 2068 2069 2069 /** 2070 * Count number of posts of a post type and i suser has permissions to view.2070 * Count number of posts of a post type and if user has permissions to view. 2071 2071 * 2072 2072 * This function provides an efficient method of finding the amount of post's 2073 2073 * type a blog has. Another method is to count the amount of items in … … 2077 2077 * The $perm parameter checks for 'readable' value and if the user can read 2078 2078 * private posts, it will display that for the user that is signed in. 2079 2079 * 2080 * @since 2.5.02081 2080 * @link http://codex.wordpress.org/Template_Tags/wp_count_posts 2082 2081 * 2082 * @since 2.5.0 2083 * 2083 2084 * @param string $type Optional. Post type to retrieve count 2084 2085 * @param string $perm Optional. 'readable' or empty. 2085 2086 * @return object Number of posts for each status … … 2092 2093 2093 2094 $user = wp_get_current_user(); 2094 2095 2095 $cache_key = $type;2096 $cache_key = 'posts-' . $type; 2096 2097 2097 2098 $query = "SELECT post_status, COUNT( * ) AS num_posts FROM {$wpdb->posts} WHERE post_type = %s"; 2098 2099 if ( 'readable' == $perm && is_user_logged_in() ) { … … 2104 2105 } 2105 2106 $query .= ' GROUP BY post_status'; 2106 2107 2107 $count = wp_cache_get($cache_key, 'counts'); 2108 if ( false !== $count ) 2109 return $count; 2108 $counts = wp_cache_get( $cache_key, 'counts' ); 2109 if ( false !== $counts ) { 2110 /** 2111 * Modify returned post counts by status for the current post type. 2112 * 2113 * @since 3.7.0 2114 * 2115 * @param object $counts An object containing the current post_type's post counts by status. 2116 * @param string $type The post type. 2117 * @param string $perm The permission to determine if the posts are 'readable' by the current user. 2118 */ 2119 return apply_filters( 'count_posts', $counts, $type, $perm ); 2120 } 2110 2121 2111 $ count =$wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );2122 $results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A ); 2112 2123 2113 $stats = array(); 2114 foreach ( get_post_stati() as $state ) 2115 $stats[$state] = 0; 2124 $counts = array_fill_keys( get_post_stati(), 0 ); 2116 2125 2117 foreach ( (array) $countas $row )2118 $ stats[$row['post_status']] = $row['num_posts'];2126 foreach ( $results as $row ) 2127 $counts[ $row['post_status'] ] = $row['num_posts']; 2119 2128 2120 $ stats = (object) $stats;2121 wp_cache_set( $cache_key, $stats, 'counts');2129 $counts = (object) $counts; 2130 wp_cache_set( $cache_key, $counts, 'counts' ); 2122 2131 2123 return $stats; 2132 //duplicate_hook 2133 return apply_filters( 'count_posts', $counts, $type, $perm ); 2124 2134 } 2125 2135 2126 2136 /**