berlindb / core

All of the required core code
MIT License
255 stars 29 forks source link

Query:get_results() incorrectly wipes out $where_cols #41

Closed pippinsplugins closed 4 years ago

pippinsplugins commented 4 years ago

In the get_results() method of the query class, the logic that validates the $where_cols is not working correctly. Currently it is:

foreach ( $columns as $column ) {
    if ( ! array_key_exists( $column, $column_names ) ) {
        unset( $where_cols[ $column ] );
    }
}

This always results in the $where_cols getting set to an empty array.

To fix it, we need to unset using the column index, like so:

foreach ( $columns as $index => $column ) {
    if ( ! array_key_exists( $column, $column_names ) ) {
        unset( $where_cols[ $index ] );
    }
}

Discovered via Sugar Calendar https://github.com/sugarcalendar/standard/issues/352