Make WordPress Core


Ignore:
Timestamp:
02/23/2016 02:20:28 AM (9 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r36566 r36625  
    42034203        }
    42044204
    4205         $attachment = (array) $attachment;
     4205        $attachment = array_map( 'strval', (array) $attachment );
    42064206
    42074207        $post_obj = $this->get_queried_object();
     
    42374237        $author_obj = $this->get_queried_object();
    42384238
    4239         $author = (array) $author;
     4239        $author = array_map( 'strval', (array) $author );
    42404240
    42414241        if ( in_array( (string) $author_obj->ID, $author ) )
     
    42694269        $cat_obj = $this->get_queried_object();
    42704270
    4271         $category = (array) $category;
     4271        $category = array_map( 'strval', (array) $category );
    42724272
    42734273        if ( in_array( (string) $cat_obj->term_id, $category ) )
     
    43014301        $tag_obj = $this->get_queried_object();
    43024302
    4303         $tag = (array) $tag;
     4303        $tag = array_map( 'strval', (array) $tag );
    43044304
    43054305        if ( in_array( (string) $tag_obj->term_id, $tag ) )
     
    45034503        $page_obj = $this->get_queried_object();
    45044504
    4505         $page = (array) $page;
     4505        $page = array_map( 'strval', (array) $page );
    45064506
    45074507        if ( in_array( (string) $page_obj->ID, $page ) ) {
     
    45964596        $post_obj = $this->get_queried_object();
    45974597
    4598         $post = (array) $post;
     4598        $post = array_map( 'strval', (array) $post );
    45994599
    46004600        if ( in_array( (string) $post_obj->ID, $post ) ) {
Note: See TracChangeset for help on using the changeset viewer.