Ticket #29612: 29612.diff
| File 29612.diff, 3.1 KB (added by , 12 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 $trashed_comment_id = $this->factory->comment->create( 24 array( 25 'comment_post_ID' => $this->post_id, 26 'comment_approved' => 'trash' 27 ) 28 ); 29 $hold_comment_id = $this->factory->comment->create( 30 array( 31 'comment_post_ID' => $this->post_id, 32 'comment_approved' => 0 33 ) 34 ); 35 36 $comments_by_array = get_comments( 37 array( 38 'status' => array( 'approve', 'hold', 'trash' ) 39 ) 40 ); 41 42 $this->assertEquals( 3, count( $comments_by_array ) ); 43 } 44 45 function test_get_comments_by_status_array_2() { 46 $approved_comment_id = $this->factory->comment->create( array( 'comment_post_ID' => $this->post_id ) ); 47 $trashed_comment_id = $this->factory->comment->create( 48 array( 49 'comment_post_ID' => $this->post_id, 50 'comment_approved' => 'trash' 51 ) 52 ); 53 $hold_comment_id = $this->factory->comment->create( 54 array( 55 'comment_post_ID' => $this->post_id, 56 'comment_approved' => 0 57 ) 58 ); 59 60 $comments_by_array = get_comments( 61 array( 62 'status' => array( 'approve', 'hold' ) 63 ) 64 ); 65 66 $this->assertEquals( 2, count( $comments_by_array ) ); 67 } 68 69 /** 19 70 * @ticket 21101 20 71 */ 21 72 function test_get_comment_comment_approved_0() {