Hide webhook comments

Part of #5564
This commit is contained in:
Max Rice 2014-07-30 16:23:41 -04:00
parent 572becdcde
commit 0fd7e3376d
1 changed files with 67 additions and 1 deletions

View File

@ -32,6 +32,11 @@ class WC_Comments {
add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ), 10, 1 );
add_action( 'comment_feed_join', array( __CLASS__, 'exclude_order_comments_from_feed_join' ) );
add_action( 'comment_feed_where', array( __CLASS__, 'exclude_order_comments_from_feed_where' ) );
// secure webhook comments
add_filter( 'comments_clauses', array( __CLASS__, 'exclude_webhook_comments' ), 10, 1 );
add_action( 'comment_feed_join', array( __CLASS__, 'exclude_webhook_comments_from_feed_join' ) );
add_action( 'comment_feed_where', array( __CLASS__, 'exclude_webhook_comments_from_feed_where' ) );
}
/**
@ -98,6 +103,67 @@ class WC_Comments {
return $where;
}
/**
* Exclude webhook comments from queries and RSS
*
* @since 2.2
* @param array $clauses
* @return array
*/
public static function exclude_webhook_comments( $clauses ) {
global $wpdb;
if ( ! $clauses['join'] ) {
$clauses['join'] = '';
}
if ( ! strstr( $clauses['join'], "JOIN $wpdb->posts" ) ) {
$clauses['join'] .= " LEFT JOIN $wpdb->posts ON comment_post_ID = $wpdb->posts.ID ";
}
if ( $clauses['where'] ) {
$clauses['where'] .= ' AND ';
}
$clauses['where'] .= " $wpdb->posts.post_type <> 'shop_webhook' ";
return $clauses;
}
/**
* Exclude webhook comments from queries and RSS
*
* @since 2.2
* @param string $join
* @return string
*/
public static function exclude_webhook_comments_from_feed_join( $join ) {
global $wpdb;
if ( ! strstr( $join, $wpdb->posts ) )
$join = " LEFT JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID ";
return $join;
}
/**
* Exclude webhook comments from queries and RSS
*
* @since 2.1
* @param string $where
* @return string
*/
public static function exclude_webhook_comments_from_feed_where( $where ) {
global $wpdb;
if ( $where )
$where .= ' AND ';
$where .= " $wpdb->posts.post_type <> 'shop_webhook' ";
return $where;
}
/**
* Validate the comment ratings.
*