Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/wp-includes/ms-blogs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 25 additions & 0 deletions tests/phpunit/tests/post/wpDeletePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Loading