WordPress.org

Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r35757 r36361  
    5959        'limits'  => '',
    6060    );
     61
     62    /**
     63     * SQL WHERE clause.
     64     *
     65     * Stored after the 'comments_clauses' filter is run on the compiled WHERE sub-clauses.
     66     *
     67     * @since 4.4.2
     68     * @access protected
     69     * @var string
     70     */
     71    protected $filtered_where_clause;
    6172
    6273    /**
     
    748759                // $field_value may be an array.
    749760                $esses = array_fill( 0, count( (array) $field_value ), '%s' );
    750                 $this->sql_clauses['where']['post_fields'] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
     761                $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ')', $field_value );
    751762            }
    752763        }
     
    817828        $groupby = isset( $clauses[ 'groupby' ] ) ? $clauses[ 'groupby' ] : '';
    818829
     830        $this->filtered_where_clause = $where;
     831
    819832        if ( $where ) {
    820833            $where = 'WHERE ' . $where;
     
    868881        );
    869882
    870         $where_clauses = $this->sql_clauses['where'];
    871         unset(
    872             $where_clauses['parent'],
    873             $where_clauses['parent__in'],
    874             $where_clauses['parent__not_in']
    875         );
     883        /*
     884         * The WHERE clause for the descendant query is the same as for the top-level
     885         * query, minus the `parent`, `parent__in`, and `parent__not_in` sub-clauses.
     886         */
     887        $_where = $this->filtered_where_clause;
     888        $exclude_keys = array( 'parent', 'parent__in', 'parent__not_in' );
     889        foreach ( $exclude_keys as $exclude_key ) {
     890            if ( isset( $this->sql_clauses['where'][ $exclude_key ] ) ) {
     891                $clause = $this->sql_clauses['where'][ $exclude_key ];
     892
     893                // Strip the clause as well as any adjacent ANDs.
     894                $pattern = '|(?:AND)?\s*' . $clause . '\s*(?:AND)?|';
     895                $_where_parts = preg_split( $pattern, $_where );
     896
     897                // Remove empties.
     898                $_where_parts = array_filter( array_map( 'trim', $_where_parts ) );
     899
     900                // Reassemble with an AND.
     901                $_where = implode( ' AND ', $_where_parts );
     902            }
     903        }
    876904
    877905        // Fetch an entire level of the descendant tree at a time.
     
    883911            }
    884912
    885             $where = 'WHERE ' . implode( ' AND ', $where_clauses ) . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')';
     913            $where = 'WHERE ' . $_where . ' AND comment_parent IN (' . implode( ',', array_map( 'intval', $parent_ids ) ) . ')';
    886914            $comment_ids = $wpdb->get_col( "{$this->sql_clauses['select']} {$this->sql_clauses['from']} {$where} {$this->sql_clauses['groupby']} ORDER BY comment_date_gmt ASC, comment_ID ASC" );
    887915
Note: See TracChangeset for help on using the changeset viewer.