Make WordPress Core

Changeset 54768


Ignore:
Timestamp:
11/09/2022 12:26:41 AM (21 months ago)
Author:
peterwilsoncc
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.
Fixes #57012.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r54685 r54768  
    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.