mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
The function checks the status of the post being deleted, and then only calls `update_posts_count()` if the deleted post was previously published, as the update query would be unnecessary otherwise. However, by the time the function runs, the post is already deleted from the database, and the post status check fails. This commit uses the previously retrieved post object for the status check, so that the function proceeds as expected. Includes updating the unit test to call `wp_delete_post()` with the `$force_delete` argument, so that the post is actually deleted, not trashed, and the `after_delete_post` action is run. Follow-up to [28835], [52207], [54760], [54762]. Fixes #57023. git-svn-id: https://develop.svn.wordpress.org/trunk@55419 602fd350-edb4-49c9-b593-d223f7449a82
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
if ( is_multisite() ) :
|
|
/**
|
|
* Test that update_posts_count() gets called via default filters on multisite.
|
|
*
|
|
* @group ms-site
|
|
* @group multisite
|
|
*
|
|
* @covers ::update_posts_count
|
|
*/
|
|
class Tests_Multisite_UpdatePostsCount extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* Tests that posts count is updated correctly when posts are added or deleted.
|
|
*
|
|
* @ticket 27952
|
|
* @ticket 53443
|
|
*
|
|
* @covers ::_update_posts_count_on_transition_post_status
|
|
* @covers ::_update_posts_count_on_delete
|
|
*/
|
|
public function test_update_posts_count() {
|
|
$blog_id = self::factory()->blog->create();
|
|
switch_to_blog( $blog_id );
|
|
|
|
$original_post_count = (int) get_site()->post_count;
|
|
|
|
$post_id = self::factory()->post->create();
|
|
|
|
$post_count_after_creating = get_site()->post_count;
|
|
|
|
wp_delete_post( $post_id, true );
|
|
|
|
$post_count_after_deleting = get_site()->post_count;
|
|
|
|
restore_current_blog();
|
|
|
|
/*
|
|
* Check that posts count is updated when a post is created:
|
|
* add_action( 'transition_post_status', '_update_posts_count_on_transition_post_status', 10, 3 );
|
|
*
|
|
* Check that _update_posts_count_on_transition_post_status() is called on that filter,
|
|
* which then calls update_posts_count() to update the count.
|
|
*/
|
|
$this->assertSame( $original_post_count + 1, $post_count_after_creating, 'Post count should be incremented by 1.' );
|
|
|
|
/*
|
|
* Check that posts count is updated when a post is deleted:
|
|
* add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 );
|
|
*
|
|
* Check that _update_posts_count_on_delete() is called on that filter,
|
|
* which then calls update_posts_count() to update the count.
|
|
*/
|
|
$this->assertSame( $original_post_count, $post_count_after_deleting, 'Post count should match the original count.' );
|
|
}
|
|
}
|
|
|
|
endif;
|