* * @param array $args The hook parameters. * @return array The expanded hook parameters. */ public function expand_wp_insert_comment( $args ) { return array( $args[0], $this->filter_comment( $args[1] ) ); } /** * Filter a comment object to the fields we need. * * @access public * * @param \WP_Comment $comment The unfiltered comment object. * @return \WP_Comment Filtered comment object. */ public function filter_comment( $comment ) { /** * Filters whether to prevent sending comment data to .com * * Passing true to the filter will prevent the comment data from being sent * to the WordPress.com. * Instead we pass data that will still enable us to do a checksum against the * Jetpacks data but will prevent us from displaying the data on in the API as well as * other services. * * @since 4.2.0 * * @param boolean false prevent post data from bing synced to WordPress.com * @param mixed $comment WP_COMMENT object */ if ( apply_filters( 'jetpack_sync_prevent_sending_comment_data', false, $comment ) ) { $blocked_comment = new \stdClass(); $blocked_comment->comment_ID = $comment->comment_ID; $blocked_comment->comment_date = $comment->comment_date; $blocked_comment->comment_date_gmt = $comment->comment_date_gmt; $blocked_comment->comment_approved = 'jetpack_sync_blocked'; return $blocked_comment; } return $comment; } /** * Whether a certain comment meta key is whitelisted for sync. * * @access public * * @param string $meta_key Comment meta key. * @return boolean Whether the meta key is whitelisted. */ public function is_whitelisted_comment_meta( $meta_key ) { return in_array( $meta_key, Settings::get_setting( 'comment_meta_whitelist' ), true ); } /** * Handler for filtering out non-whitelisted comment meta. * * @access public * * @param array $args Hook args. * @return array|boolean False if not whitelisted, the original hook args otherwise. */ public function filter_meta( $args ) { if ( $this->is_comment_type_allowed( $args[1] ) && $this->is_whitelisted_comment_meta( $args[2] ) ) { return $args; } return false; } /** * Expand the comment IDs to comment objects and meta before being serialized and sent to the server. * * @access public * * @param array $args The hook parameters. * @return array The expanded hook parameters. */ public function expand_comment_ids( $args ) { list( $comment_ids, $previous_interval_end ) = $args; $comments = get_comments( array( 'include_unapproved' => true, 'comment__in' => $comment_ids, 'orderby' => 'comment_ID', 'order' => 'DESC', ) ); return array( $comments, $this->get_metadata( $comment_ids, 'comment', Settings::get_setting( 'comment_meta_whitelist' ) ), $previous_interval_end, ); } }