Ticket #21003: comment.php.patch
File comment.php.patch, 3.0 KB (added by , 12 years ago) |
---|
-
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 … … 222 230 'type' => '', 223 231 'user_id' => '', 224 232 'search' => '', 225 'count' => false 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 // Parse meta query 241 $this->meta_query = new WP_Meta_Query(); 242 $this->meta_query->parse_query_vars( $this->query_vars ); 243 229 244 do_action_ref_array( 'pre_get_comments', array( &$this ) ); 230 245 extract( $this->query_vars, EXTR_SKIP ); 231 246 … … 259 274 260 275 if ( ! empty( $orderby ) ) { 261 276 $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby); 262 $ordersby = array_intersect( 263 $ordersby, 264 array( 265 'comment_agent', 266 'comment_approved', 267 'comment_author', 268 'comment_author_email', 269 'comment_author_IP', 270 'comment_author_url', 271 'comment_content', 272 'comment_date', 273 'comment_date_gmt', 274 'comment_ID', 275 'comment_karma', 276 'comment_parent', 277 'comment_post_ID', 278 'comment_type', 279 'user_id', 280 ) 277 $allowed_keys = array( 278 'comment_agent', 279 'comment_approved', 280 'comment_author', 281 'comment_author_email', 282 'comment_author_IP', 283 'comment_author_url', 284 'comment_content', 285 'comment_date', 286 'comment_date_gmt', 287 'comment_ID', 288 'comment_karma', 289 'comment_parent', 290 'comment_post_ID', 291 'comment_type', 292 'user_id', 281 293 ); 294 if ( !empty($this->query_vars['meta_key']) ) { 295 $allowed_keys[] = $q['meta_key']; 296 $allowed_keys[] = 'meta_value'; 297 $allowed_keys[] = 'meta_value_num'; 298 } 299 $ordersby = array_intersect( $ordersby, $allowed_keys ); 300 foreach ($ordersby as $key => $value) { 301 if ( $value == $q['meta_key'] || $value == 'meta_value' ) { 302 $ordersby[$key] = "$wpdb->commentmeta.meta_value"; 303 } elseif ( $value == 'meta_value_num' ) { 304 $ordersby[$key] = "$wpdb->commentmeta.meta_value+0"; 305 } 306 } 282 307 $orderby = empty( $ordersby ) ? 'comment_date_gmt' : implode(', ', $ordersby); 283 308 } else { 284 309 $orderby = 'comment_date_gmt'; … … 331 356 $where .= $wpdb->prepare( " AND {$wpdb->posts}.{$field_name} = %s", $field_value ); 332 357 } 333 358 359 if ( !empty( $this->meta_query->queries ) ) { 360 $clauses = $this->meta_query->get_sql( 'comment', $wpdb->comments, 'comment_ID', $this ); 361 $join .= $clauses['join']; 362 $where .= $clauses['where']; 363 } 364 334 365 $pieces = array( 'fields', 'join', 'where', 'orderby', 'order', 'limits' ); 335 366 $clauses = apply_filters_ref_array( 'comments_clauses', array( compact( $pieces ), &$this ) ); 336 367 foreach ( $pieces as $piece )