More careful type conversion in WP_Query is_*() methods.

`is_array( 1, '1-foo' )` returns true, which means that `is_page( 1 )`
was returning true when on a page with the slug '1-foo'. We avoid this odd
behavior by casting the queried object ID to a string before testing against
the value passed to the conditional function.

This also helps to avoid a problem where an arbitrary value for `$page` would
cause `is_page( $page )` to return true if the query had been manipulated by
a plugin to show that the current page's ID is 0.

Props boonebgorges, r-a-y, nunomorgadinho, wonderboymusic, clifgriffin.
Fixes #24674.
Built from https://develop.svn.wordpress.org/trunk@31458


git-svn-id: http://core.svn.wordpress.org/trunk@31439 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-02-14 02:09:25 +00:00
parent fc1d4b3489
commit 7dcb041d5a
2 changed files with 7 additions and 7 deletions

View File

@ -4077,7 +4077,7 @@ class WP_Query {
$post_obj = $this->get_queried_object();
if ( in_array( $post_obj->ID, $attachment ) ) {
if ( in_array( (string) $post_obj->ID, $attachment ) ) {
return true;
} elseif ( in_array( $post_obj->post_title, $attachment ) ) {
return true;
@ -4109,7 +4109,7 @@ class WP_Query {
$author = (array) $author;
if ( in_array( $author_obj->ID, $author ) )
if ( in_array( (string) $author_obj->ID, $author ) )
return true;
elseif ( in_array( $author_obj->nickname, $author ) )
return true;
@ -4141,7 +4141,7 @@ class WP_Query {
$category = (array) $category;
if ( in_array( $cat_obj->term_id, $category ) )
if ( in_array( (string) $cat_obj->term_id, $category ) )
return true;
elseif ( in_array( $cat_obj->name, $category ) )
return true;
@ -4173,7 +4173,7 @@ class WP_Query {
$tag = (array) $tag;
if ( in_array( $tag_obj->term_id, $tag ) )
if ( in_array( (string) $tag_obj->term_id, $tag ) )
return true;
elseif ( in_array( $tag_obj->name, $tag ) )
return true;
@ -4370,7 +4370,7 @@ class WP_Query {
$page = (array) $page;
if ( in_array( $page_obj->ID, $page ) ) {
if ( in_array( (string) $page_obj->ID, $page ) ) {
return true;
} elseif ( in_array( $page_obj->post_title, $page ) ) {
return true;
@ -4463,7 +4463,7 @@ class WP_Query {
$post = (array) $post;
if ( in_array( $post_obj->ID, $post ) ) {
if ( in_array( (string) $post_obj->ID, $post ) ) {
return true;
} elseif ( in_array( $post_obj->post_title, $post ) ) {
return true;

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.2-alpha-31457';
$wp_version = '4.2-alpha-31458';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.