Make WordPress Core

Ticket #35084: 35084.3.diff

File 35084.3.diff, 2.0 KB (added by netweb, 7 years ago)
  • src/wp-includes/post.php

     
    42864286 * Sub pages will be in the "directory" under the parent page post name.
    42874287 *
    42884288 * @since 1.5.0
     4289 * @since 4.4.0 Do not add parent slugs to orphaned pages
     4290 * @since 4.4.1 Support custom post statuses
    42894291 *
    42904292 * @param WP_Post|object|int $page Page object or page ID.
    42914293 * @return string|false Page URI, false on error.
     
    43004302
    43014303        foreach ( $page->ancestors as $parent ) {
    43024304                $parent = get_post( $parent );
    4303                 if ( 'publish' === $parent->post_status ) {
     4305                if ( ! in_array( $parent->post_status, get_post_stati( array( 'internal' => true ) ) ) ){
    43044306                        $uri = $parent->post_name . '/' . $uri;
    43054307                }
    43064308        }
  • tests/phpunit/tests/post.php

     
    680680        }
    681681
    682682        /**
     683         * @ticket 35084
     684         */
     685        function test_get_post_uri_check_ancestor_post_status() {
     686
     687                $post_statuses = get_post_stati( array(), 'objects' );
     688
     689                foreach( $post_statuses as $index => $post_status ){
     690                        $parent_id = self::factory()->post->create( array( 'post_name' => 'parent_' . $index, 'post_status' => $post_status->name ) );
     691                        $child_id = self::factory()->post->create( array( 'post_name' => 'child_' . $index, 'post_parent' => $parent_id ) );
     692
     693                        // check the parent for good measure
     694                        $this->assertEquals( 'parent_' . $index, get_page_uri( $parent_id ) );
     695
     696                        // if the parent's post status is not an internal post status, it should be in the uri
     697                        if( ! ( $post_status->internal ) ){
     698                                $this->assertEquals( 'parent_' . $index . '/child_' . $index, get_page_uri( $child_id ) );
     699                        }
     700                        else{
     701                                $this->assertEquals( 'child_' . $index, get_page_uri( $child_id ) );
     702                        }
     703                }
     704        }
     705
     706        /**
    683707         * @ticket 23708
    684708         */
    685709        function test_get_post_ancestors_within_loop() {