mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-11 12:20:22 +00:00
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:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user