diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index cc8e843878..72ef1641aa 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4291,7 +4291,9 @@ function _page_traverse_name( $page_id, &$children, &$result ){ * @return string|false Page URI, false on error. */ function get_page_uri( $page ) { - $page = get_post( $page ); + if ( ! $page instanceof WP_Post ) { + $page = get_post( $page ); + } if ( ! $page ) return false; diff --git a/tests/phpunit/tests/admin/includesPost.php b/tests/phpunit/tests/admin/includesPost.php index c9e92f06aa..89803cc150 100644 --- a/tests/phpunit/tests/admin/includesPost.php +++ b/tests/phpunit/tests/admin/includesPost.php @@ -454,6 +454,29 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase { $this->assertEquals( '30', $found[1] ); } + /** + * @ticket 35368 + */ + public function test_get_sample_permalink_should_respect_hierarchy_of_draft_pages() { + $this->set_permalink_structure( '/%postname%/' ); + + $parent = self::factory()->post->create( array( + 'post_type' => 'page', + 'post_title' => 'Parent Page', + ) ); + + $child = self::factory()->post->create( array( + 'post_type' => 'page', + 'post_title' => 'Child Page', + 'post_parent' => $parent, + 'post_status' => 'draft', + ) ); + + $actual = get_sample_permalink( $child ); + $this->assertSame( home_url() . '/parent-page/%pagename%/', $actual[0] ); + $this->assertSame( 'child-page', $actual[1] ); + } + public function test_post_exists_should_match_title() { $p = self::factory()->post->create( array( 'post_title' => 'Foo Bar',