Fix notices and logic errors in get_page_by_path(). Props duck_. see #17670

git-svn-id: https://develop.svn.wordpress.org/trunk@19075 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2011-10-28 19:32:19 +00:00
parent 722c6d7003
commit a3f2a7ce55
1 changed files with 9 additions and 15 deletions

View File

@ -3164,22 +3164,16 @@ function get_page_by_path($page_path, $output = OBJECT, $post_type = 'page') {
foreach ( (array) $pages as $page ) {
if ( $page->post_name == $revparts[0] ) {
$count = 0;
if ( $page->post_parent != 0 ) {
if ( null === ( $parent_page = $pages[ $page->post_parent ] ) )
continue;
while ( $parent_page->ID != 0 ) {
$count++;
if ( $parent_page->post_name != $revparts[ $count ] )
break;
$parent_page = $pages[ $parent_page->post_parent ];
}
if ( $parent_page->ID == 0 && $count+1 == count($revparts) ) {
$foundid = $page->ID;
$p = $page;
while ( $p->post_parent != 0 && isset( $pages[ $p->post_parent ] ) ) {
$count++;
$parent = $pages[ $p->post_parent ];
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] )
break;
}
} else if ( count($revparts) == 1 ) {
$p = $parent;
}
if ( $p->post_parent == 0 && $count+1 == count( $revparts ) && $p->post_name == $revparts[ $count ] ) {
$foundid = $page->ID;
break;
}