Make WordPress Core

Changeset 36404


Ignore:
Timestamp:
01/26/2016 03:11:12 AM (8 years ago)
Author:
boonebgorges
Message:

Query: Respect 'suppress_filters' when filtering search-related SQL.

Props 5um17.
Fixes #35594.

Location:
trunk
Files:
2 edited

Legend:

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

    r36403 r36404  
    27912791        }
    27922792
    2793         /**
    2794          * Filter the search SQL that is used in the WHERE clause of WP_Query.
    2795          *
    2796          * @since 3.0.0
    2797          *
    2798          * @param string   $search Search SQL for WHERE clause.
    2799          * @param WP_Query $this   The current WP_Query object.
    2800          */
    2801         $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) );
     2793        if ( ! $q['suppress_filters'] ) {
     2794            /**
     2795             * Filter the search SQL that is used in the WHERE clause of WP_Query.
     2796             *
     2797             * @since 3.0.0
     2798             *
     2799             * @param string   $search Search SQL for WHERE clause.
     2800             * @param WP_Query $this   The current WP_Query object.
     2801             */
     2802            $search = apply_filters_ref_array( 'posts_search', array( $search, &$this ) );
     2803        }
    28022804
    28032805        // Taxonomies
     
    30083010                $search_orderby = $this->parse_search_order( $q );
    30093011
    3010             /**
    3011              * Filter the ORDER BY used when ordering search results.
    3012              *
    3013              * @since 3.7.0
    3014              *
    3015              * @param string   $search_orderby The ORDER BY clause.
    3016              * @param WP_Query $this           The current WP_Query instance.
    3017              */
    3018             $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
     3012            if ( ! $q['suppress_filters'] ) {
     3013                /**
     3014                 * Filter the ORDER BY used when ordering search results.
     3015                 *
     3016                 * @since 3.7.0
     3017                 *
     3018                 * @param string   $search_orderby The ORDER BY clause.
     3019                 * @param WP_Query $this           The current WP_Query instance.
     3020                 */
     3021                $search_orderby = apply_filters( 'posts_search_orderby', $search_orderby, $this );
     3022            }
     3023
    30193024            if ( $search_orderby )
    30203025                $orderby = $orderby ? $search_orderby . ', ' . $orderby : $search_orderby;
  • trunk/tests/phpunit/tests/query/search.php

    r36278 r36404  
    160160        $this->assertEqualSets( array( $p2 ), $q->posts );
    161161    }
     162
     163    /**
     164     * @ticket 35594
     165     */
     166    public function test_search_should_respect_suppress_filters() {
     167        add_filter( 'posts_search', array( $this, 'filter_posts_search' ) );
     168        add_filter( 'posts_search_orderby', array( $this, 'filter_posts_search' ) );
     169        $q = new WP_Query( array(
     170            's' => 'foo',
     171            'suppress_filters' => true,
     172        ) );
     173        remove_filter( 'posts_search', array( $this, 'filter_posts_search' ) );
     174        remove_filter( 'posts_search_orderby', array( $this, 'filter_posts_search' ) );
     175
     176        $this->assertNotContains( 'posts_search', $q->request );
     177    }
     178
     179    public function filter_posts_search( $sql ) {
     180        return $sql . ' /* posts_search */';
     181    }
    162182}
Note: See TracChangeset for help on using the changeset viewer.