From dfdb44040e5e1e38bd563b56c8b4d6ac5233f171 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 12 Jan 2025 18:14:23 +0000 Subject: [PATCH] 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: https://core.svn.wordpress.org/trunk@58985 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 23 +++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 74cedc40e1..8cb7287289 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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; diff --git a/wp-includes/version.php b/wp-includes/version.php index 0106be95fd..3da2fb655d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.