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.

git-svn-id: https://develop.svn.wordpress.org/trunk@36625 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2016-02-23 02:20:28 +00:00
parent b30e77f5fc
commit 0809037f61
2 changed files with 254 additions and 6 deletions

View File

@@ -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;