Make WordPress Core


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.