Make WordPress Core


Ignore:
Timestamp:
02/24/2023 01:21:54 AM (14 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/src/wp-includes/ms-blogs.php

    r55398 r55419  
    878878 *
    879879 * @since 4.0.0
    880  *
    881  * @param int $post_id Post ID.
    882  */
    883 function _update_posts_count_on_delete( $post_id ) {
    884     $post = get_post( $post_id );
    885 
     880 * @since 6.2.0 Added the `$post` parameter.
     881 *
     882 * @param int     $post_id Post ID.
     883 * @param WP_Post $post    Post object.
     884 */
     885function _update_posts_count_on_delete( $post_id, $post ) {
    886886    if ( ! $post || 'publish' !== $post->post_status || 'post' !== $post->post_type ) {
    887887        return;
Note: See TracChangeset for help on using the changeset viewer.