Ticket #21003: 21003.diff
File 21003.diff, 3.3 KB (added by , 12 years ago) |
---|
-
wp-includes/comment.php
190 190 * @since 3.1.0 191 191 */ 192 192 class WP_Comment_Query { 193 /** 194 * Metadata query container 195 * 196 * @since 3.? 197 * @access public 198 * @var object WP_Meta_Query 199 */ 200 var $meta_query = false; 193 201 194 202 /** 195 203 * Execute the query … … 223 231 'user_id' => '', 224 232 'search' => '', 225 233 'count' => false, 234 'meta_key' => '', 235 'meta_value' => '', 236 'meta_query' => '', 226 237 ); 227 238 228 239 $this->query_vars = wp_parse_args( $query_vars, $defaults ); 240 241 // Parse meta query 242 $this->meta_query = new WP_Meta_Query(); 243 $this->meta_query->parse_query_vars( $this->query_vars ); 244 229 245 do_action_ref_array( 'pre_get_comments', array( &$this ) ); 230 246 extract( $this->query_vars, EXTR_SKIP ); 231 247 232 248 // $args can be whatever, only use the args defined in defaults to compute the key 233 249 $key = md5( serialize( compact(array_keys($defaults)) ) ); 234 250 $last_changed = wp_cache_get('last_changed', 'comment'); 235 if ( ! $last_changed ) {251 if ( ! $last_changed ) { 236 252 $last_changed = time(); 237 253 wp_cache_set('last_changed', $last_changed, 'comment'); 238 254 } … … 257 273 258 274 if ( ! empty( $orderby ) ) { 259 275 $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby); 260 $ordersby = array_intersect( 261 $ordersby, 262 array( 263 'comment_agent', 264 'comment_approved', 265 'comment_author', 266 'comment_author_email', 267 'comment_author_IP', 268 'comment_author_url', 269 'comment_content', 270 'comment_date', 271 'comment_date_gmt', 272 'comment_ID', 273 'comment_karma', 274 'comment_parent', 275 'comment_post_ID', 276 'comment_type', 277 'user_id', 278 ) 276 $allowed_keys = array( 277 'comment_agent', 278 'comment_approved', 279 'comment_author', 280 'comment_author_email', 281 'comment_author_IP', 282 'comment_author_url', 283 'comment_content', 284 'comment_date', 285 'comment_date_gmt', 286 'comment_ID', 287 'comment_karma', 288 'comment_parent', 289 'comment_post_ID', 290 'comment_type', 291 'user_id', 279 292 ); 293 if ( ! empty( $this->query_vars['meta_key'] ) ) { 294 $allowed_keys[] = $q['meta_key']; 295 $allowed_keys[] = 'meta_value'; 296 $allowed_keys[] = 'meta_value_num'; 297 } 298 $ordersby = array_intersect( $ordersby, $allowed_keys ); 299 foreach ( $ordersby as $key => $value ) { 300 if ( $value == $q['meta_key'] || $value == 'meta_value' ) { 301 $ordersby[ $key ] = "$wpdb->commentmeta.meta_value"; 302 } elseif ( $value == 'meta_value_num' ) { 303 $ordersby[ $key ] = "$wpdb->commentmeta.meta_value+0"; 304 } 305 } 280 306 $orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby); 281 307 } else { 282 308 $orderby = 'comment_date_gmt'; … … 329 355 $where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value ); 330 356 } 331 357 358 if ( ! empty( $this->meta_query->queries ) ) { 359 $clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); 360 $join .= $clauses['join']; 361 $where .= $clauses['where']; 362 } 363 332 364 $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); 333 365 $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); 334 366 foreach ( $pieces as $piece )