Changeset 28458
- Timestamp:
- 05/16/2014 07:32:05 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment.php
r28457 r28458 278 278 279 279 // $args can be whatever, only use the args defined in defaults to compute the key 280 $key = md5( serialize( compact( array_keys($defaults)) ) );280 $key = md5( serialize( compact( array_keys( $defaults ) ) ) ); 281 281 $last_changed = wp_cache_get( 'last_changed', 'comment' ); 282 282 if ( ! $last_changed ) { … … 286 286 $cache_key = "get_comments:$key:$last_changed"; 287 287 288 if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) 288 if ( $cache = wp_cache_get( $cache_key, 'comment' ) ) { 289 289 return $cache; 290 291 $post_id = absint($post_id); 292 293 if ( 'hold' == $status ) 290 } 291 292 $status = $this->query_vars['status']; 293 if ( 'hold' == $status ) { 294 294 $approved = "comment_approved = '0'"; 295 elseif ( 'approve' == $status )295 } elseif ( 'approve' == $status ) { 296 296 $approved = "comment_approved = '1'"; 297 elseif ( ! empty( $status ) && 'all' != $status )297 } elseif ( ! empty( $status ) && 'all' != $status ) { 298 298 $approved = $wpdb->prepare( "comment_approved = %s", $status ); 299 else299 } else { 300 300 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 301 302 $order = ( 'ASC' == strtoupper($order) ) ? 'ASC' : 'DESC'; 303 304 if ( ! empty( $orderby ) ) { 305 $ordersby = is_array($orderby) ? $orderby : preg_split('/[,\s]/', $orderby); 301 } 302 $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC'; 303 304 if ( ! empty( $this->query_vars['orderby'] ) ) { 305 $ordersby = is_array( $this->query_vars['orderby'] ) ? 306 $this->query_vars['orderby'] : 307 preg_split( '/[,\s]/', $this->query_vars['orderby'] ); 308 306 309 $allowed_keys = array( 307 310 'comment_agent', … … 339 342 } 340 343 341 $number = absint( $number);342 $offset = absint( $offset);343 344 if ( ! empty($number) ) {345 if ( $offset ) 344 $number = absint( $this->query_vars['number'] ); 345 $offset = absint( $this->query_vars['offset'] ); 346 347 if ( ! empty( $number ) ) { 348 if ( $offset ) { 346 349 $limits = 'LIMIT ' . $offset . ',' . $number; 347 else350 } else { 348 351 $limits = 'LIMIT ' . $number; 352 } 349 353 } else { 350 354 $limits = ''; 351 355 } 352 356 353 if ( $ count )357 if ( $this->query_vars['count'] ) { 354 358 $fields = 'COUNT(*)'; 355 else359 } else { 356 360 $fields = '*'; 357 361 } 358 362 $join = ''; 359 363 $where = $approved; 360 364 361 if ( ! empty($post_id) ) 365 $post_id = absint( $this->query_vars['post_id'] ); 366 if ( ! empty( $post_id ) ) { 362 367 $where .= $wpdb->prepare( ' AND comment_post_ID = %d', $post_id ); 363 if ( '' !== $author_email ) 364 $where .= $wpdb->prepare( ' AND comment_author_email = %s', $author_email ); 365 if ( '' !== $karma ) 366 $where .= $wpdb->prepare( ' AND comment_karma = %d', $karma ); 367 if ( 'comment' == $type ) { 368 } 369 370 if ( '' !== $this->query_vars['author_email'] ) { 371 $where .= $wpdb->prepare( ' AND comment_author_email = %s', $this->query_vars['author_email'] ); 372 } 373 374 if ( '' !== $this->query_vars['karma'] ) { 375 $where .= $wpdb->prepare( ' AND comment_karma = %d', $this->query_vars['karma'] ); 376 } 377 378 if ( 'comment' == $this->query_vars['type'] ) { 368 379 $where .= " AND comment_type = ''"; 369 } elseif( 'pings' == $t ype) {380 } elseif( 'pings' == $this->query_vars['type'] ) { 370 381 $where .= ' AND comment_type IN ("pingback", "trackback")'; 371 } elseif ( ! empty( $type ) ) { 372 $where .= $wpdb->prepare( ' AND comment_type = %s', $type ); 373 } 374 if ( '' !== $parent ) 375 $where .= $wpdb->prepare( ' AND comment_parent = %d', $parent ); 376 377 if ( is_array( $user_id ) ) { 378 $where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $user_id ) ) . ')'; 379 } elseif ( '' !== $user_id ) { 380 $where .= $wpdb->prepare( ' AND user_id = %d', $user_id ); 381 } 382 383 if ( '' !== $search ) 384 $where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) ); 385 386 $post_fields = array_filter( compact( array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type', ) ) ); 382 } elseif ( ! empty( $this->query_vars['type'] ) ) { 383 $where .= $wpdb->prepare( ' AND comment_type = %s', $this->query_vars['type'] ); 384 } 385 386 if ( '' !== $this->query_vars['parent'] ) { 387 $where .= $wpdb->prepare( ' AND comment_parent = %d', $this->query_vars['parent'] ); 388 } 389 390 if ( is_array( $this->query_vars['user_id'] ) ) { 391 $where .= ' AND user_id IN (' . implode( ',', array_map( 'absint', $this->query_vars['user_id'] ) ) . ')'; 392 } elseif ( '' !== $this->query_vars['user_id'] ) { 393 $where .= $wpdb->prepare( ' AND user_id = %d', $this->query_vars['user_id'] ); 394 } 395 396 if ( '' !== $this->query_vars['search'] ) { 397 $where .= $this->get_search_sql( 398 $this->query_vars['search'], 399 array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) 400 ); 401 } 402 403 $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent', 'post_status', 'post_type' ) ); 404 $post_fields = array_filter( $plucked ); 405 387 406 if ( ! empty( $post_fields ) ) { 388 407 $join = "JOIN $wpdb->posts ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID"; … … 398 417 } 399 418 419 $date_query = $this->query_vars['date_query']; 400 420 if ( ! empty( $date_query ) && is_array( $date_query ) ) { 401 421 $date_query_object = new WP_Date_Query( $date_query, 'comment_date' ); … … 416 436 $$piece = isset( $clauses[ $piece ] ) ? $clauses[ $piece ] : ''; 417 437 418 if ( $groupby ) 438 if ( $groupby ) { 419 439 $groupby = 'GROUP BY ' . $groupby; 420 440 } 421 441 $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits"; 422 442 423 if ( $ count )443 if ( $this->query_vars['count'] ) { 424 444 return $wpdb->get_var( $query ); 425 426 $ comments = $wpdb->get_results( $query );445 } 446 $results = $wpdb->get_results( $query ); 427 447 /** 428 448 * Filter the comment query results. … … 430 450 * @since 3.1.0 431 451 * 432 * @param array $ commentsAn array of comments.452 * @param array $results An array of comments. 433 453 * @param WP_Comment_Query &$this Current instance of WP_Comment_Query, passed by reference. 434 454 */ 435 $comments = apply_filters_ref_array( 'the_comments', array( $ comments, &$this ) );455 $comments = apply_filters_ref_array( 'the_comments', array( $results, &$this ) ); 436 456 437 457 wp_cache_add( $cache_key, $comments, 'comment' );
Note: See TracChangeset
for help on using the changeset viewer.