Make WordPress Core

Changeset 54780


Ignore:
Timestamp:
11/09/2022 06:33:01 PM (18 months ago)
Author:
desrosj
Message:

Query: Bypass caching for filtered SELECTs.

Bypass caching within WP_Query when the SELECT clause has been modified via a filter. This prevents both cache key collisions and the returning of incomplete or unexpected results when the SELECT clause has been modified by an extender.

Props pypwalters, claytoncollie, johnwatkins0, TimothyBlynJacobs, costdev, spacedmonkey, peterwilsoncc.
Merges [54768] to the 6.1 branch.
Fixes #57012.

Location:
branches/6.1
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/6.1

  • branches/6.1/src/wp-includes/class-wp-query.php

    r54692 r54780  
    31043104         * search, that to ensure against a collision with another
    31053105         * function.
     3106         *
     3107         * If `$fields` has been modified by the `posts_fields`,
     3108         * `posts_fields_request`, `post_clauses` or `posts_clauses_request`
     3109         * filters, then caching is disabled to prevent caching collisions.
    31063110         */
    31073111        $id_query_is_cacheable = ! str_contains( strtoupper( $orderby ), ' RAND(' );
     3112
     3113        $cachable_field_values = array(
     3114            "{$wpdb->posts}.*",
     3115            "{$wpdb->posts}.ID, {$wpdb->posts}.post_parent",
     3116            "{$wpdb->posts}.ID",
     3117        );
     3118
     3119        if ( ! in_array( $fields, $cachable_field_values, true ) ) {
     3120            $id_query_is_cacheable = false;
     3121        }
     3122
    31083123        if ( $q['cache_results'] && $id_query_is_cacheable ) {
    31093124            $new_request = str_replace( $fields, "{$wpdb->posts}.*", $this->request );
Note: See TracChangeset for help on using the changeset viewer.