WC_Comments::wp_count_comments PHP Method

wp_count_comments() public static method

Remove order notes and webhook delivery logs from wp_count_comments().
Since: 2.2
public static wp_count_comments ( object $stats, integer $post_id ) : object
$stats object Comment stats.
$post_id integer Post ID.
return object
    public static function wp_count_comments($stats, $post_id)
    {
        global $wpdb;
        if (0 === $post_id) {
            $stats = get_transient('wc_count_comments');
            if (!$stats) {
                $stats = array();
                $count = $wpdb->get_results("\n\t\t\t\t\tSELECT comment_approved, COUNT(*) AS num_comments\n\t\t\t\t\tFROM {$wpdb->comments}\n\t\t\t\t\tWHERE comment_type NOT IN ('order_note', 'webhook_delivery')\n\t\t\t\t\tGROUP BY comment_approved\n\t\t\t\t", ARRAY_A);
                $total = 0;
                $approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
                foreach ((array) $count as $row) {
                    // Don't count post-trashed toward totals.
                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
                        $total += $row['num_comments'];
                    }
                    if (isset($approved[$row['comment_approved']])) {
                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
                    }
                }
                $stats['total_comments'] = $total;
                $stats['all'] = $total;
                foreach ($approved as $key) {
                    if (empty($stats[$key])) {
                        $stats[$key] = 0;
                    }
                }
                $stats = (object) $stats;
                set_transient('wc_count_comments', $stats);
            }
        }
        return $stats;
    }