Ticket #29612: 29612.2.diff
| File 29612.2.diff, 3.1 KB (added by , 11 years ago) |
|---|
-
src/wp-includes/comment.php
303 303 return $cache; 304 304 } 305 305 306 $status = $this->query_vars['status']; 307 if ( 'hold' == $status ) { 308 $approved = "comment_approved = '0'"; 309 } elseif ( 'approve' == $status ) { 310 $approved = "comment_approved = '1'"; 311 } elseif ( ! empty( $status ) && 'all' != $status ) { 312 $approved = $wpdb->prepare( "comment_approved = %s", $status ); 313 } else { 314 $approved = "( comment_approved = '0' OR comment_approved = '1' )"; 306 $status_queries = array(); 307 $statuses = empty( $this->query_vars['status'] ) ? array( 'all' ) : (array) $this->query_vars['status']; 308 309 foreach ( $statuses as $s ) { 310 if ( 'hold' == $s || '0' == $s ) { 311 $status_queries['hold'] = "comment_approved = '0'"; 312 } elseif ( 'approve' == $s || '1' == $s ) { 313 $status_queries['approve'] = "comment_approved = '1'"; 314 } elseif ( 'all' == $s ) { 315 $status_queries['hold'] = "comment_approved = '0'"; 316 $status_queries['approve'] = "comment_approved = '1'"; 317 } else { 318 $status_queries[ $s ] = $wpdb->prepare( "comment_approved = %s", $s ); 319 } 315 320 } 321 322 $approved = "( " . implode( " OR ", $status_queries ) . " )"; 323 316 324 $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC'; 317 325 318 326 if ( ! empty( $this->query_vars['orderby'] ) ) { -
tests/phpunit/tests/comment/query.php
16 16 } 17 17 18 18 /** 19 * @ticket 29612 20 */ 21 function test_get_comments_by_status_array_3() { 22 $approved_comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) ); 23 24 $trashed_comment_id = $this->factory->comment->create( 25 array( 26 'comment_post_ID' => $this->post_id, 27 'comment_approved' => 'trash' 28 ) 29 ); 30 31 $hold_comment_id = $this->factory->comment->create( 32 array( 33 'comment_post_ID' => $this->post_id, 34 'comment_approved' => 0 35 ) 36 ); 37 38 $comments_by_array = get_comments( 39 array( 40 'status' => array( 'approve', 'hold', 'trash' ) 41 ) 42 ); 43 44 $this->assertEquals( 3, count( $comments_by_array ) ); 45 } 46 47 function test_get_comments_by_status_array_2() { 48 $approved_comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) ); 49 50 $trashed_comment_id = $this->factory->comment->create( 51 array( 52 'comment_post_ID' => $this->post_id, 53 'comment_approved' => 'trash' 54 ) 55 ); 56 57 $hold_comment_id = $this->factory->comment->create( 58 array( 59 'comment_post_ID' => $this->post_id, 60 'comment_approved' => 0 61 ) 62 ); 63 64 $comments_by_array = get_comments( 65 array( 66 'status' => array( 'approve', 'hold' ) 67 ) 68 ); 69 70 $this->assertEquals( 2, count( $comments_by_array ) ); 71 } 72 73 /** 19 74 * @ticket 21101 20 75 */ 21 76 function test_get_comment_comment_approved_0() {