Make WordPress Core

Ticket #25775: date.php.patch

File date.php.patch, 1.2 KB (added by ew_holmes, 11 years ago)

reworking of validate_column to prepend the table name

  • date.php

     
    151151        }
    152152
    153153        /**
    154          * Validates a column name parameter.
     154         * Validates a column name parameter and prepends the appropriate $wpdb table name.
    155155         *
    156156         * @since 3.7.0
    157157         * @access public
    158158         *
    159159         * @param string $column The user-supplied column name.
    160          * @return string A validated column name value.
     160         * @return string A validated column name value prepended by its $wpdb table name.
    161161         */
    162162        public function validate_column( $column ) {
     163                global $wpdb;
    163164                $valid_columns = array(
    164165                        'post_date', 'post_date_gmt', 'post_modified',
    165166                        'post_modified_gmt', 'comment_date', 'comment_date_gmt'
     
    174175                 */
    175176                if ( ! in_array( $column, apply_filters( 'date_query_valid_columns', $valid_columns ) ) )
    176177                        $column = 'post_date';
    177 
     178               
     179                // Add our table prefix depending on what column we are looking at.
     180                if ( 0 === strpos( $column, 'comment' ) )
     181                          $column = "{$wpdb->comments}.{$column}";
     182                else if ( 0 === strpos( $column, 'post' ) )
     183                          $column = "{$wpdb->posts}.{$column}";
     184               
    178185                return $column;
    179186        }
    180187