Make WordPress Core

Ticket #29612: trac-29612.diff

File trac-29612.diff, 1.7 KB (added by ebinnion, 12 years ago)

Alternative patch for allowing an array of comment statuses.

  • wp-includes/comment.php

    diff --git a/wp-includes/comment.php b/wp-includes/comment.php
    index a4cc7e2..5c5f737 100644
    a b public function query( $query_vars ) { 
    303303                        return $cache;
    304304                }
    305305
    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                        }
    315320                }
     321
     322                $approved = "( " . implode( " OR ", $status_queries ) . " )";
     323
    316324                $order = ( 'ASC' == strtoupper( $this->query_vars['order'] ) ) ? 'ASC' : 'DESC';
    317325
    318326                if ( ! empty( $this->query_vars['orderby'] ) ) {
    public function query( $query_vars ) { 
    466474                if ( $groupby ) {
    467475                        $groupby = 'GROUP BY ' . $groupby;
    468476                }
     477
    469478                $query = "SELECT $fields FROM $wpdb->comments $join WHERE $where $groupby ORDER BY $orderby $order $limits";
    470479
    471480                if ( $this->query_vars['count'] ) {