Make WordPress Core

Changeset 28613


Ignore:
Timestamp:
05/29/2014 06:03:15 AM (11 years ago)
Author:
wonderboymusic
Message:

If post__in or post_parent__in is passed to WP_Query as an empty array, nuke the query. Both vars are currently only checked for truthiness after which they are ignored. Setting these vars at all indicates explicit filtering being desired.

Adds unit test.

Fixes #28099.

Location:
trunk
Files:
2 edited

Legend:

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

    r28612 r28613  
    24492449            $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
    24502450            $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
     2451        } elseif ( isset( $this->query['post__in'] ) ) {
     2452            $post__in = 0;
     2453            $where .= " AND 1=0 ";
    24512454        } elseif ( $q['post__not_in'] ) {
    24522455            $post__not_in = implode(',',  array_map( 'absint', $q['post__not_in'] ));
     
    24592462            $post_parent__in = implode( ',', array_map( 'absint', $q['post_parent__in'] ) );
    24602463            $where .= " AND {$wpdb->posts}.post_parent IN ($post_parent__in)";
     2464        } elseif ( isset( $this->query['post_parent__in'] ) ) {
     2465            $post_parent__in = 0;
     2466            $where .= " AND 1=0 ";
    24612467        } elseif ( $q['post_parent__not_in'] ) {
    24622468            $post_parent__not_in = implode( ',',  array_map( 'absint', $q['post_parent__not_in'] ) );
  • trunk/tests/phpunit/tests/query/results.php

    r27686 r28613  
    403403    }
    404404
     405    function test_empty_post__in() {
     406        $posts1 = $this->q->query( array() );
     407        $this->assertNotEmpty( $posts1 );
     408        $posts2 = $this->q->query( array( 'post__in' => array() ) );
     409        $this->assertEmpty( $posts2 );
     410        $posts3 = $this->q->query( array( 'post_parent__in' => array() ) );
     411        $this->assertEmpty( $posts3 );
     412    }
     413
    405414    function test_exlude_from_search_empty() {
    406415        global $wp_post_types;
Note: See TracChangeset for help on using the changeset viewer.