From ccb70aee4b7f83a9497f782971b0639c19fd7e16 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 23 Jul 2016 10:04:20 +0000 Subject: [PATCH] Permalinks: In `get_page_uri()`, don't prepend a parent page slug if it's empty. Props inderpreet99, SergeyBiryukov. Fixes #36174. git-svn-id: https://develop.svn.wordpress.org/trunk@38145 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post.php | 2 +- tests/phpunit/tests/post/getPageUri.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index b055e4bbc4..f5cfd0c32f 100644 --- a/src/wp-includes/post.php +++ b/src/wp-includes/post.php @@ -4333,7 +4333,7 @@ function get_page_uri( $page = 0 ) { foreach ( $page->ancestors as $parent ) { $parent = get_post( $parent ); - if ( $parent ) { + if ( $parent && $parent->post_name ) { $uri = $parent->post_name . '/' . $uri; } } diff --git a/tests/phpunit/tests/post/getPageUri.php b/tests/phpunit/tests/post/getPageUri.php index 6f766fcc67..5a5a0a0bea 100644 --- a/tests/phpunit/tests/post/getPageUri.php +++ b/tests/phpunit/tests/post/getPageUri.php @@ -46,6 +46,18 @@ class Tests_Post_getPageUri extends WP_UnitTestCase { $this->assertEquals( 'child', get_page_uri( $child_id ) ); } + /** + * @ticket 36174 + */ + function test_get_page_uri_with_a_draft_parent_with_empty_slug() { + $parent_id = self::factory()->post->create( array( 'post_name' => 'parent' ) ); + $child_id = self::factory()->post->create( array( 'post_name' => 'child', 'post_parent' => $parent_id ) ); + + wp_update_post( array( 'ID' => $parent_id, 'post_name' => '', 'post_status' => 'draft' ) ); + + $this->assertEquals( 'child', get_page_uri( $child_id ) ); + } + /** * @ticket 26284 */