[wp-trac] [WordPress Trac] #40073: WP_Comment_Query should support a comment type of "comment"
WordPress Trac
noreply at wordpress.org
Wed Mar 8 20:44:31 UTC 2017
#40073: WP_Comment_Query should support a comment type of "comment"
-------------------------+-----------------------------
Reporter: rogerlos | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Comments | Version: trunk
Severity: normal | Keywords:
Focuses: |
-------------------------+-----------------------------
Scenario: User is leveraging the `comment_type` field in their theme or a
plugin, and desires all comments to have a type. They assign "regular"
comments a `comment_type` of "comment" as that seems to make sense.
If they then ask for those comments using `get_comments` or another
function which leverages `WP_Comment_Query`:
{{{
$comments = get_comments( [
'type' => 'comment',
] );
}}}
The returned list will not return any comments which have `comment_type`
set to "comment", only those with no type at all.
As this behavior (the swallowing of "comment" as a type entirely, rather
than looking for `['','comment']`) is undocumented, perhaps
`WP_Comment_Query` could be altered as such:
{{{
715 case 'comment':
716 case 'comments':
717 $comment_types[ $operator ][] = "''";
___ $comment_types[ $operator ][] = "'comment'";
___ $comment_types[ $operator ][] = "'comments'";
718 break;
719
720 case 'pings':
721 $comment_types[ $operator ][] = "'pingback'";
722 $comment_types[ $operator ][] = "'trackback'";
___ $comment_types[ $operator ][] = "'pings'";
723 break;
}}}
A sounder approach would probably be to allow a flag to be passed:
{{{
708 foreach ( $_raw_types as $type ) {
___ if ( empty( $this->query_vars['ignore_default_types'] ) ) {
709 switch ( $type ) {
...
729 }
___ } else {
___ $comment_types[ $operator ][] = $wpdb->prepare( '%s', $type );
___ }
...
735 }
}}}
An alternative might be to throw an exception when setting `comment_type`
to one of the default values using `wp_new_comment`, `wp_insert_comment`
and similar functions.
(I feel since there is no way to retrieve a comment when the type is one
of these "reserved" words with standard WP functions, comments should
probably not be able to be saved with a "reserved" type using standard
functions if `WP_Comment_Query` is not altered.)
At the very least, the documentation for comment "insert" functions should
mention that there are reserved keywords on `comment_type`, note what they
are, and that if you use one of them you will need to use the
`comments_clauses` filter to allow them to be retrieved.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/40073>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list