Prevent unnecessary $wpdb->update() when hierarchical post doesn't have children.
Props danielbachhuber. Fixes #34896. git-svn-id: https://develop.svn.wordpress.org/trunk@35817 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
57a81709a4
commit
0a2a83056c
|
@ -2405,9 +2405,10 @@ function wp_delete_post( $postid = 0, $force_delete = false ) {
|
|||
// Point children of this page to its parent, also clean the cache of affected children.
|
||||
$children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
|
||||
$children = $wpdb->get_results( $children_query );
|
||||
|
||||
if ( $children ) {
|
||||
$wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Do raw query. wp_get_post_revisions() is filtered.
|
||||
$revision_ids = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_parent = %d AND post_type = 'revision'", $postid ) );
|
||||
|
|
|
@ -1253,4 +1253,16 @@ class Tests_Post extends WP_UnitTestCase {
|
|||
$this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date);
|
||||
$this->assertEquals($post['post_date_gmt'], $out->post_date_gmt);
|
||||
}
|
||||
|
||||
function test_wp_delete_post_reassign_hierarchical_post_type() {
|
||||
$grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
|
||||
$parent_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $grandparent_page_id ) );
|
||||
$page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_page_id ) );
|
||||
$this->assertEquals( $parent_page_id, get_post( $page_id )->post_parent );
|
||||
wp_delete_post( $parent_page_id, true );
|
||||
$this->assertEquals( $grandparent_page_id, get_post( $page_id )->post_parent );
|
||||
wp_delete_post( $grandparent_page_id, true );
|
||||
$this->assertEquals( 0, get_post( $page_id )->post_parent );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue