Make WordPress Core

Ticket #34896: 34896.1.diff

File 34896.1.diff, 1.9 KB (added by danielbachhuber, 10 years ago)
  • src/wp-includes/post.php

    diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php
    index d0bc1a3..1ab1601 100644
    a b function wp_delete_post( $postid = 0, $force_delete = false ) { 
    24052405                // Point children of this page to its parent, also clean the cache of affected children.
    24062406                $children_query = $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_parent = %d AND post_type = %s", $postid, $post->post_type );
    24072407                $children = $wpdb->get_results( $children_query );
    2408 
    2409                 $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
     2408                if ( count( $children ) ) {
     2409                        $wpdb->update( $wpdb->posts, $parent_data, $parent_where + array( 'post_type' => $post->post_type ) );
     2410                }
    24102411        }
    24112412
    24122413        // Do raw query. wp_get_post_revisions() is filtered.
  • tests/phpunit/tests/post.php

    diff --git a/tests/phpunit/tests/post.php b/tests/phpunit/tests/post.php
    index 71fe55e..6c13225 100644
    a b class Tests_Post extends WP_UnitTestCase { 
    12291229                $this->assertEquals(get_date_from_gmt($post['post_date_gmt']), $out->post_date);
    12301230                $this->assertEquals($post['post_date_gmt'], $out->post_date_gmt);
    12311231        }
     1232
     1233        function test_wp_delete_post_reassign_hierarchical_post_type() {
     1234                $grandparent_page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
     1235                $parent_page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $grandparent_page_id ) );
     1236                $page_id = self::factory()->post->create( array( 'post_type' => 'page', 'post_parent' => $parent_page_id ) );
     1237                $this->assertEquals( $parent_page_id, get_post( $page_id )->post_parent );
     1238                wp_delete_post( $parent_page_id, true );
     1239                $this->assertEquals( $grandparent_page_id, get_post( $page_id )->post_parent );
     1240                wp_delete_post( $grandparent_page_id, true );
     1241                $this->assertEquals( 0, get_post( $page_id )->post_parent );
     1242        }
     1243
    12321244}