Coding Standards: Use strict comparison in get_page_by_path().

Follow-up to [3511], [18541], [19075], [21845].

Props aristath, poena, afercia, SergeyBiryukov.
See #62279.
Built from https://develop.svn.wordpress.org/trunk@59599


git-svn-id: http://core.svn.wordpress.org/trunk@58985 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov
2025-01-12 18:14:23 +00:00
parent b9a1723711
commit 6f097ada4b
2 changed files with 14 additions and 11 deletions

View File

@@ -6061,9 +6061,9 @@ 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;
@@ -6071,18 +6071,21 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = '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;
}
}
@@ -6090,10 +6093,10 @@ function get_page_by_path( $page_path, $output = OBJECT, $post_type = 'page' ) {
}
// 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;

View File

@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.8-alpha-59598';
$wp_version = '6.8-alpha-59599';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.