Better flexibility for 'type' in `WP_Comment_Query`.
* Add support for an array of values in 'type'. * Introduce `type__in` parameter. This duplicates 'type' but is added for better consistency with other query classes. * Introduce `type__not_in`. Among other things, these changes will make it easier for plugin authors to manage the appearance of custom comment types in various WP interfaces. Props dancameron, mordauk. See #12668. Built from https://develop.svn.wordpress.org/trunk@30096 git-svn-id: http://core.svn.wordpress.org/trunk@30096 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ee6d4968da
commit
56f55ea507
|
@ -304,6 +304,8 @@ class WP_Comment_Query {
|
||||||
'post_type' => '',
|
'post_type' => '',
|
||||||
'status' => 'all',
|
'status' => 'all',
|
||||||
'type' => '',
|
'type' => '',
|
||||||
|
'type__in' => '',
|
||||||
|
'type__not_in' => '',
|
||||||
'user_id' => '',
|
'user_id' => '',
|
||||||
'search' => '',
|
'search' => '',
|
||||||
'count' => false,
|
'count' => false,
|
||||||
|
@ -520,12 +522,43 @@ class WP_Comment_Query {
|
||||||
$where[] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
|
$where[] = $wpdb->prepare( 'comment_karma = %d', $this->query_vars['karma'] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'comment' == $this->query_vars['type'] ) {
|
// Filtering by comment_type: 'type', 'type__in', 'type__not_in'.
|
||||||
$where[] = "comment_type = ''";
|
$raw_types = array(
|
||||||
} elseif( 'pings' == $this->query_vars['type'] ) {
|
'IN' => array_merge( (array) $this->query_vars['type'], (array) $this->query_vars['type__in'] ),
|
||||||
$where[] = 'comment_type IN ("pingback", "trackback")';
|
'NOT IN' => (array) $this->query_vars['type__not_in'],
|
||||||
} elseif ( ! empty( $this->query_vars['type'] ) ) {
|
);
|
||||||
$where[] = $wpdb->prepare( 'comment_type = %s', $this->query_vars['type'] );
|
|
||||||
|
$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'] ) {
|
if ( '' !== $this->query_vars['parent'] ) {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @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.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue