In wp_count_posts(), rename 'count_posts' hook to 'wp_count_posts', for clarity. see #16603.

git-svn-id: https://develop.svn.wordpress.org/trunk@25578 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-09-23 19:07:08 +00:00
parent 7203c7c012
commit fbc417775d
2 changed files with 21 additions and 25 deletions

View File

@ -2109,31 +2109,27 @@ function wp_count_posts( $type = 'post', $perm = '' ) {
$query .= ' GROUP BY post_status';
$counts = wp_cache_get( $cache_key, 'counts' );
if ( false !== $counts ) {
/**
* Modify returned post counts by status for the current post type.
*
* @since 3.7.0
*
* @param object $counts An object containing the current post_type's post counts by status.
* @param string $type The post type.
* @param string $perm The permission to determine if the posts are 'readable' by the current user.
*/
return apply_filters( 'count_posts', $counts, $type, $perm );
if ( false === $counts ) {
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
$counts = array_fill_keys( get_post_stati(), 0 );
foreach ( $results as $row )
$counts[ $row['post_status'] ] = $row['num_posts'];
$counts = (object) $counts;
wp_cache_set( $cache_key, $counts, 'counts' );
}
$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $type ), ARRAY_A );
$counts = array_fill_keys( get_post_stati(), 0 );
foreach ( $results as $row )
$counts[ $row['post_status'] ] = $row['num_posts'];
$counts = (object) $counts;
wp_cache_set( $cache_key, $counts, 'counts' );
//duplicate_hook
return apply_filters( 'count_posts', $counts, $type, $perm );
/**
* Modify returned post counts by status for the current post type.
*
* @since 3.7.0
*
* @param object $counts An object containing the current post_type's post counts by status.
* @param string $type The post type.
* @param string $perm The permission to determine if the posts are 'readable' by the current user.
*/
return apply_filters( 'wp_count_posts', $counts, $type, $perm );
}
/**

View File

@ -817,12 +817,12 @@ class Tests_Post extends WP_UnitTestCase {
) );
$count1 = wp_count_posts( $post_type, 'readable' );
$this->assertEquals( 10, $count1->publish );
add_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
add_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
$count2 = wp_count_posts( $post_type, 'readable' );
$this->assertEquals( 7, $count2->publish );
remove_filter( 'count_posts', array( $this, 'filter_wp_count_posts' ) );
remove_filter( 'wp_count_posts', array( $this, 'filter_wp_count_posts' ) );
}
function filter_wp_count_posts( $counts ) {