From 0fd7e3376df41523abcbf4345956104db783ef60 Mon Sep 17 00:00:00 2001 From: Max Rice Date: Wed, 30 Jul 2014 16:23:41 -0400 Subject: [PATCH] Hide webhook comments Part of #5564 --- includes/class-wc-comments.php | 68 +++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-comments.php b/includes/class-wc-comments.php index 968e2bc4e0c..9acf82a1a9f 100644 --- a/includes/class-wc-comments.php +++ b/includes/class-wc-comments.php @@ -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' ) ); } /** @@ -75,7 +80,7 @@ class WC_Comments { public static function exclude_order_comments_from_feed_join( $join ) { global $wpdb; - if ( ! strstr( $join, $wpdb->posts ) ) + if ( ! strstr( $join, $wpdb->posts ) ) $join = " LEFT JOIN $wpdb->posts ON $wpdb->comments.comment_post_ID = $wpdb->posts.ID "; return $join; @@ -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. *