From 072c791df0b1d6648e100c16c21af7b489db4f03 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 23 Feb 2016 02:21:25 +0000 Subject: [PATCH] Query: `is_*( $int )` should not falsely match strings starting with "$int". Another chapter in the Storied Annals of Weird `in_array()` Behavior: `in_array( 4, array( "4-cool-dudes" ) );` resolves to `true`, such that `is_page( 4 )` was returning true for posts with the name `'4-cool-dudes'`. We work around this behavior by ensuring that values passed to the `is_` methods are cast to strings before the `in_array()` checks. ID checks still work as expected; see #24674. Props mikejolley, swissspidy, boonebgorges. Fixes #35902. Built from https://develop.svn.wordpress.org/trunk@36625 git-svn-id: http://core.svn.wordpress.org/trunk@36592 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/query.php | 12 ++++++------ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/wp-includes/query.php b/wp-includes/query.php index 053f4e95c5..70d02378d9 100644 --- a/wp-includes/query.php +++ b/wp-includes/query.php @@ -4202,7 +4202,7 @@ class WP_Query { return true; } - $attachment = (array) $attachment; + $attachment = array_map( 'strval', (array) $attachment ); $post_obj = $this->get_queried_object(); @@ -4236,7 +4236,7 @@ class WP_Query { $author_obj = $this->get_queried_object(); - $author = (array) $author; + $author = array_map( 'strval', (array) $author ); if ( in_array( (string) $author_obj->ID, $author ) ) return true; @@ -4268,7 +4268,7 @@ class WP_Query { $cat_obj = $this->get_queried_object(); - $category = (array) $category; + $category = array_map( 'strval', (array) $category ); if ( in_array( (string) $cat_obj->term_id, $category ) ) return true; @@ -4300,7 +4300,7 @@ class WP_Query { $tag_obj = $this->get_queried_object(); - $tag = (array) $tag; + $tag = array_map( 'strval', (array) $tag ); if ( in_array( (string) $tag_obj->term_id, $tag ) ) return true; @@ -4502,7 +4502,7 @@ class WP_Query { $page_obj = $this->get_queried_object(); - $page = (array) $page; + $page = array_map( 'strval', (array) $page ); if ( in_array( (string) $page_obj->ID, $page ) ) { return true; @@ -4595,7 +4595,7 @@ class WP_Query { $post_obj = $this->get_queried_object(); - $post = (array) $post; + $post = array_map( 'strval', (array) $post ); if ( in_array( (string) $post_obj->ID, $post ) ) { return true; diff --git a/wp-includes/version.php b/wp-includes/version.php index 9c154a4bef..862edef316 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36624'; +$wp_version = '4.5-alpha-36625'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.