Skip to content

Commit

Permalink
Coding Standards: Use strict comparison in get_page_by_path().
Browse files Browse the repository at this point in the history
Follow-up to [3511], [18541], [19075], [21845].

Props aristath, poena, afercia, SergeyBiryukov.
See #62279.

git-svn-id: https://develop.svn.wordpress.org/trunk@59599 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Jan 12, 2025
1 parent c0d073d commit 8879667
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -6061,39 +6061,42 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {

$revparts = array_reverse( $parts );

$foundid = 0;
$found_id = 0;
foreach ( (array) $pages as $page ) {
if ( $page->post_name == $revparts[0] ) {
if ( $page->post_name === $revparts[0] ) {
$count = 0;
$p = $page;

/*
* Loop through the given path parts from right to left,
* ensuring each matches the post ancestry.
*/
while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
while ( 0 !== (int) $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
++$count;
$parent = $pages[ $p->post_parent ];
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
if ( ! isset( $revparts[ $count ] ) || $parent->post_name !== $revparts[ $count ] ) {
break;
}
$p = $parent;
}

if ( 0 == $p->post_parent && count( $revparts ) === $count + 1 && $p->post_name == $revparts[ $count ] ) {
$foundid = $page->ID;
if ( $page->post_type == $post_type ) {
if ( 0 === (int) $p->post_parent
&& count( $revparts ) === $count + 1
&& $p->post_name === $revparts[ $count ]
) {
$found_id = $page->ID;
if ( $page->post_type === $post_type ) {
break;
}
}
}
}

// We cache misses as well as hits.
wp_cache_set( $cache_key, $foundid, 'post-queries' );
wp_cache_set( $cache_key, $found_id, 'post-queries' );

if ( $foundid ) {
return get_post( $foundid, $output );
if ( $found_id ) {
return get_post( $found_id, $output );
}

return null;
Expand Down

0 comments on commit 8879667

Please sign in to comment.