In get_page_uri()
, do not add parent slugs to orphaned pages.
Adds unit test. Props filosofo, MikeHansenMe, MikeHansenMe, chriscct7. Fixes #15963. git-svn-id: https://develop.svn.wordpress.org/trunk@34001 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2deb9565c0
commit
ad163d3547
@ -4196,7 +4196,10 @@ function get_page_uri( $page ) {
|
||||
$uri = $page->post_name;
|
||||
|
||||
foreach ( $page->ancestors as $parent ) {
|
||||
$uri = get_post( $parent )->post_name . '/' . $uri;
|
||||
$parent = get_post( $parent );
|
||||
if ( 'publish' === $parent->post_status ) {
|
||||
$uri = $parent->post_name . '/' . $uri;
|
||||
}
|
||||
}
|
||||
|
||||
return $uri;
|
||||
|
@ -650,6 +650,24 @@ class Tests_Post extends WP_UnitTestCase {
|
||||
$this->assertFalse( get_page_uri( $post_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 15963
|
||||
*/
|
||||
function test_get_post_uri_check_orphan() {
|
||||
$parent_id = $this->factory->post->create( array( 'post_name' => 'parent' ) );
|
||||
$child_id = $this->factory->post->create( array( 'post_name' => 'child', 'post_parent' => $parent_id ) );
|
||||
|
||||
// check the parent for good measure
|
||||
$this->assertEquals( 'parent', get_page_uri( $parent_id ) );
|
||||
|
||||
// try the child normally
|
||||
$this->assertEquals( 'parent/child', get_page_uri( $child_id ) );
|
||||
|
||||
// now delete the parent and check
|
||||
wp_delete_post( $parent_id );
|
||||
$this->assertEquals( 'child', get_page_uri( $child_id ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 23708
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user