Make WordPress Core

Changeset 53503


Ignore:
Timestamp:
06/14/2022 04:15:52 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Docs: Add a comment for stripping the leading AND from SQL clauses in some query classes.

Follow-up to [30084], [34529], [34542], [36598], [37477], [37572], [43010].

See #55646.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

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

    r53469 r53503  
    912912
    913913        if ( ! empty( $this->query_vars['date_query'] ) && is_array( $this->query_vars['date_query'] ) ) {
    914             $this->date_query                         = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );
     914            $this->date_query = new WP_Date_Query( $this->query_vars['date_query'], 'comment_date' );
     915
     916            // Strip leading 'AND'.
    915917            $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
    916918        }
  • trunk/src/wp-includes/class-wp-site-query.php

    r53469 r53503  
    627627        $date_query = $this->query_vars['date_query'];
    628628        if ( ! empty( $date_query ) && is_array( $date_query ) ) {
    629             $this->date_query                         = new WP_Date_Query( $date_query, 'registered' );
     629            $this->date_query = new WP_Date_Query( $date_query, 'registered' );
     630
     631            // Strip leading 'AND'.
    630632            $this->sql_clauses['where']['date_query'] = preg_replace( '/^\s*AND\s*/', '', $this->date_query->get_sql() );
    631633        }
  • trunk/src/wp-includes/class-wp-term-query.php

    r53496 r53503  
    485485            $exclude_tree      = wp_parse_id_list( $exclude_tree );
    486486            $excluded_children = $exclude_tree;
     487
    487488            foreach ( $exclude_tree as $extrunk ) {
    488489                $excluded_children = array_merge(
     
    498499                );
    499500            }
     501
    500502            $exclusions = array_merge( $excluded_children, $exclusions );
    501503        }
     
    532534
    533535        if ( ! empty( $exclusions ) ) {
    534             // Must do string manipulation here for backward compatibility with filter.
     536            // Strip leading 'AND'. Must do string manipulation here for backward compatibility with filter.
    535537            $this->sql_clauses['where']['exclusions'] = preg_replace( '/^\s*AND\s*/', '', $exclusions );
    536538        }
     
    544546        if ( ! empty( $args['name'] ) ) {
    545547            $names = $args['name'];
     548
    546549            foreach ( $names as &$_name ) {
    547550                // `sanitize_term_field()` returns slashed data.
     
    651654
    652655        if ( ! empty( $meta_clauses ) ) {
    653             $join                                    .= $mq_sql['join'];
     656            $join .= $mq_sql['join'];
     657
     658            // Strip leading 'AND'.
    654659            $this->sql_clauses['where']['meta_query'] = preg_replace( '/^\s*AND\s*/', '', $mq_sql['where'] );
    655             $distinct                                .= 'DISTINCT';
     660
     661            $distinct .= 'DISTINCT';
    656662
    657663        }
     
    786792                $cache = array_map( 'intval', $cache );
    787793            } elseif ( 'count' !== $_fields ) {
    788                 if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) ) || ( 'all' === $_fields && $args['pad_counts'] ) ) {
     794                if ( ( 'all_with_object_id' === $_fields && ! empty( $args['object_ids'] ) )
     795                    || ( 'all' === $_fields && $args['pad_counts'] )
     796                ) {
    789797                    $term_ids = wp_list_pluck( $cache, 'term_id' );
    790798                } else {
    791799                    $term_ids = array_map( 'intval', $cache );
    792800                }
     801
    793802                _prime_term_caches( $term_ids, $args['update_term_meta_cache'] );
     803
    794804                $term_objects = $this->populate_terms( $cache );
    795805                $cache        = $this->format_terms( $term_objects, $_fields );
     
    838848                if ( ! $term->count ) {
    839849                    $children = get_term_children( $term->term_id, $term->taxonomy );
     850
    840851                    if ( is_array( $children ) ) {
    841852                        foreach ( $children as $child_id ) {
     
    887898            $term_cache = wp_list_pluck( $term_objects, 'term_id' );
    888899        }
     900
    889901        wp_cache_add( $cache_key, $term_cache, 'terms' );
    890902        $this->terms = $this->format_terms( $term_objects, $_fields );
Note: See TracChangeset for help on using the changeset viewer.