Make WordPress Core

Ticket #15963: 15963.5.diff

File 15963.5.diff, 1.4 KB (added by MikeHansenMe, 9 years ago)
  • src/wp-includes/post-functions.php

     
    41964196        $uri = $page->post_name;
    41974197
    41984198        foreach ( $page->ancestors as $parent ) {
    4199                 $uri = get_post( $parent )->post_name . '/' . $uri;
     4199                $parent = get_post( $parent );
     4200                if ( 'publish' === $parent->post_status ) {
     4201                        $uri = $parent->post_name . '/' . $uri;
     4202                }
    42004203        }
    42014204
    42024205        return $uri;
  • tests/phpunit/tests/post.php

     
    651651        }
    652652
    653653        /**
     654         * @ticket 15963
     655         */
     656        function test_get_post_uri_check_orphan() {
     657                $parent_id = $this->factory->post->create( array( 'post_name' => 'parent' ) );
     658                $child_id = $this->factory->post->create( array( 'post_name' => 'child', 'post_parent' => $parent_id ) );
     659
     660                //check the parent for good measure
     661                $this->assertEquals( 'parent', get_page_uri( $parent_id ) );
     662
     663                //try the child normally
     664                $this->assertEquals( 'parent/child', get_page_uri( $child_id ) );
     665
     666                //now delete the parent and check
     667                wp_delete_post( $parent_id );
     668                $this->assertEquals( 'child', get_page_uri( $child_id ) );
     669        }
     670
     671
     672        /**
    654673         * @ticket 23708
    655674         */
    656675        function test_get_post_ancestors_within_loop() {