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
This commit is contained in:
Boone Gorges 2016-02-23 02:21:25 +00:00
parent 53e0315242
commit 072c791df0
2 changed files with 7 additions and 7 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;

View File

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