diff --git a/wp-includes/comment.php b/wp-includes/comment.php index 76715f5f1f..0906040cba 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -304,6 +304,8 @@ class WP_Comment_Query { 'post_type' => '', 'status' => 'all', 'type' => '', + 'type__in' => '', + 'type__not_in' => '', 'user_id' => '', 'search' => '', 'count' => false, @@ -520,12 +522,43 @@ class WP_Comment_Query { $where[] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] ); } - if ( 'comment' == $this->query_vars['type'] ) { - $where[] = "comment_type = ''"; - } elseif( 'pings' == $this->query_vars['type'] ) { - $where[] = 'comment_type IN ("pingback", "trackback")'; - } elseif ( ! empty( $this->query_vars['type'] ) ) { - $where[] = $wpdb->prepare( 'comment_type = %s', $this->query_vars['type'] ); + // Filtering by comment_type: 'type', 'type__in', 'type__not_in'. + $raw_types = array( + 'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ), + 'NOT IN' => (array) $this->query_vars['type__not_in'], + ); + + $comment_types = array(); + foreach ( $raw_types as $operator => $_raw_types ) { + $_raw_types = array_unique( $_raw_types ); + + foreach ( $_raw_types as $type ) { + switch ( $type ) { + // An empty translates to 'all', for backward compatibility + case '': + case 'all' : + break; + + case 'comment': + case 'comments': + $comment_types[ $operator ][] = "''"; + break; + + case 'pings': + $comment_types[ $operator ][] = "'pingback'"; + $comment_types[ $operator ][] = "'trackback'"; + break; + + default: + $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type ); + break; + } + } + + if ( ! empty( $comment_types[ $operator ] ) ) { + $types_sql = implode( ', ', $comment_types[ $operator ] ); + $where[] = "comment_type $operator ($types_sql)"; + } } if ( '' !== $this->query_vars['parent'] ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index c3d594cd5c..240123a23e 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-alpha-30095'; +$wp_version = '4.1-alpha-30096'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.