Skip to content

Commit 8879667

Browse files
Coding Standards: Use strict comparison in get_page_by_path().
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
1 parent c0d073d commit 8879667

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/wp-includes/post.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6061,39 +6061,42 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
60616061

60626062
$revparts = array_reverse( $parts );
60636063

6064-
$foundid = 0;
6064+
$found_id = 0;
60656065
foreach ( (array) $pages as $page ) {
6066-
if ( $page->post_name == $revparts[0] ) {
6066+
if ( $page->post_name === $revparts[0] ) {
60676067
$count = 0;
60686068
$p = $page;
60696069

60706070
/*
60716071
* Loop through the given path parts from right to left,
60726072
* ensuring each matches the post ancestry.
60736073
*/
6074-
while ( 0 != $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
6074+
while ( 0 !== (int) $p->post_parent && isset( $pages[ $p->post_parent ] ) ) {
60756075
++$count;
60766076
$parent = $pages[ $p->post_parent ];
6077-
if ( ! isset( $revparts[ $count ] ) || $parent->post_name != $revparts[ $count ] ) {
6077+
if ( ! isset( $revparts[ $count ] ) || $parent->post_name !== $revparts[ $count ] ) {
60786078
break;
60796079
}
60806080
$p = $parent;
60816081
}
60826082

6083-
if ( 0 == $p->post_parent && count( $revparts ) === $count + 1 && $p->post_name == $revparts[ $count ] ) {
6084-
$foundid = $page->ID;
6085-
if ( $page->post_type == $post_type ) {
6083+
if ( 0 === (int) $p->post_parent
6084+
&& count( $revparts ) === $count + 1
6085+
&& $p->post_name === $revparts[ $count ]
6086+
) {
6087+
$found_id = $page->ID;
6088+
if ( $page->post_type === $post_type ) {
60866089
break;
60876090
}
60886091
}
60896092
}
60906093
}
60916094

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

6095-
if ( $foundid ) {
6096-
return get_post( $foundid, $output );
6098+
if ( $found_id ) {
6099+
return get_post( $found_id, $output );
60976100
}
60986101

60996102
return null;

0 commit comments

Comments
 (0)