From fbc417775d9e8562222171b7dc69cc334cb779dd Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Mon, 23 Sep 2013 19:07:08 +0000 Subject: [PATCH] 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 --- src/wp-includes/post.php | 42 ++++++++++++++++-------------------- tests/phpunit/tests/post.php | 4 ++-- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 1d305de18d..4130ffaf1e 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -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 ); } /** diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php index 4428143f00..d259329997 100644 --- a/tests/phpunit/tests/post.php +++ b/tests/phpunit/tests/post.php @@ -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 ) {