Make WordPress Core


Ignore:
Timestamp:
02/24/2023 01:21:54 AM (22 months ago)
Author:
SergeyBiryukov
Message:

Posts, Post Types: Pass the post object to _update_posts_count_on_delete().

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/multisite/updatePostsCount.php

    r54762 r55419  
    3131            $post_count_after_creating = get_site()->post_count;
    3232
    33             wp_delete_post( $post_id );
     33            wp_delete_post( $post_id, true );
    3434
    3535            $post_count_after_deleting = get_site()->post_count;
     
    4848            /*
    4949             * Check that posts count is updated when a post is deleted:
    50              * add_action( 'deleted_post', '_update_posts_count_on_delete' );
     50             * add_action( 'after_delete_post', '_update_posts_count_on_delete', 10, 2 );
    5151             *
    5252             * Check that _update_posts_count_on_delete() is called on that filter,
Note: See TracChangeset for help on using the changeset viewer.