diff --git a/src/wp-includes/ms-blogs.php b/src/wp-includes/ms-blogs.php index d791dd2f4526d..c963161bc9c18 100644 --- a/src/wp-includes/ms-blogs.php +++ b/src/wp-includes/ms-blogs.php @@ -872,6 +872,10 @@ function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) { function _update_blog_date_on_post_delete( $post_id ) { $post = get_post( $post_id ); + if ( ! $post ) { + return; + } + $post_type_obj = get_post_type_object( $post->post_type ); if ( ! $post_type_obj || ! $post_type_obj->public ) { return; diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index e0afc05cd1b54..f4907e1e9085e 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4226,6 +4226,10 @@ function wp_delete_post( $post_id = 0, $force_delete = false ) { function _reset_front_page_settings_for_post( $post_id ) { $post = get_post( $post_id ); + if ( ! $post ) { + return; + } + if ( 'page' === $post->post_type ) { /* * If the page is defined in option page_on_front or post_for_posts, diff --git a/tests/phpunit/tests/post/wpDeletePost.php b/tests/phpunit/tests/post/wpDeletePost.php index 3c2a40fa92bec..77d2299dd8981 100644 --- a/tests/phpunit/tests/post/wpDeletePost.php +++ b/tests/phpunit/tests/post/wpDeletePost.php @@ -206,4 +206,29 @@ public function test_wp_delete_post_reassigns_attachments_to_parent() { $this->assertSame( $parent_post_id, get_post( $attachment_id )->post_parent ); } + + /** + * Tests that wp_delete_post() does not trigger a warning when the post is deleted + * by another process while it is being deleted. + * + * The concurrent delete is simulated by deleting the post from a `before_delete_post` + * callback that runs before `_reset_front_page_settings_for_post()`. + * + * @ticket 66684 + * + * @covers ::_reset_front_page_settings_for_post + */ + public function test_wp_delete_post_handles_post_deleted_concurrently() { + $post_id = self::factory()->post->create(); + + $delete_concurrently = static function ( $post_id_being_deleted ) use ( &$delete_concurrently ) { + remove_action( 'before_delete_post', $delete_concurrently, 1 ); + wp_delete_post( $post_id_being_deleted, true ); + }; + add_action( 'before_delete_post', $delete_concurrently, 1 ); + + wp_delete_post( $post_id, true ); + + $this->assertNull( get_post( $post_id ) ); + } }