Make WordPress Core


Ignore:
Timestamp:
10/17/2022 11:47:41 AM (2 years ago)
Author:
audrasjb
Message:

Query: Validate relation in WP_Date_Query.

Props dd32, johnjamesjacoby, martinkrcho, ehtis, paulkevan, peterwilsoncc.

File:
1 edited

Legend:

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

    r54133 r54530  
    151151        }
    152152
    153         if ( isset( $date_query['relation'] ) && 'OR' === strtoupper( $date_query['relation'] ) ) {
    154             $this->relation = 'OR';
     153        if ( isset( $date_query['relation'] ) ) {
     154            $this->relation = $this->sanitize_relation( $date_query['relation'] );
    155155        } else {
    156156            $this->relation = 'AND';
     
    220220            $this->validate_date_values( $queries );
    221221        }
     222
     223        // Sanitize the relation parameter.
     224        $queries['relation'] = $this->sanitize_relation( $queries['relation'] );
    222225
    223226        foreach ( $queries as $key => $q ) {
     
    10421045        return $wpdb->prepare( "DATE_FORMAT( $column, %s ) $compare %f", $format, $time );
    10431046    }
     1047
     1048    /**
     1049     * Sanitizes a 'relation' operator.
     1050     *
     1051     * @since 6.0.3
     1052     *
     1053     * @param string $relation Raw relation key from the query argument.
     1054     * @return string Sanitized relation ('AND' or 'OR').
     1055     */
     1056    public function sanitize_relation( $relation ) {
     1057        if ( 'OR' === strtoupper( $relation ) ) {
     1058            return 'OR';
     1059        } else {
     1060            return 'AND';
     1061        }
     1062    }
    10441063}
Note: See TracChangeset for help on using the changeset viewer.