Add hooks to wp_count_posts(). Adds filter docs. Adds unit test to test count_posts filter.

Props nacin, DrewAPicture. 
Fixes #16603.



git-svn-id: https://develop.svn.wordpress.org/trunk@25554 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2013-09-21 17:54:36 +00:00
parent 0d6c7bbbc3
commit 5a74d939ec
2 changed files with 47 additions and 15 deletions
+22
View File
@@ -808,6 +808,28 @@ class Tests_Post extends WP_UnitTestCase {
$this->assertEquals( new stdClass, wp_count_posts( $post_type, 'readable' ) );
}
function test_wp_count_posts_filtered() {
$post_type = rand_str(20);
register_post_type( $post_type );
$this->factory->post->create_many( 10, array(
'post_type' => $post_type,
'post_author' => $this->author_id
) );
$count1 = wp_count_posts( $post_type, 'readable' );
$this->assertEquals( 10, $count1->publish );
add_filter( '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' ) );
}
function filter_wp_count_posts( $counts ) {
$counts->publish = 7;
return $counts;
}
/**
* @ticket 22074
*/