WC_Comments::wp_count_comments() public WC 2.2
Remove order notes and webhook delivery logs from wp_count_comments().
{} Это метод класса: WC_Comments{}
Хуков нет.
Возвращает
Объект.
Использование
$result = WC_Comments::wp_count_comments( $stats, $post_id );
- $stats(объект) (обязательный)
- Comment stats.
- $post_id(число) (обязательный)
- Post ID.
Список изменений
С версии 2.2 | Введена. |
Код WC_Comments::wp_count_comments() WC Comments::wp count comments WC 5.0.0
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(
'total_comments' => 0,
'all' => 0,
);
$count = $wpdb->get_results(
"
SELECT comment_approved, COUNT(*) AS num_comments
FROM {$wpdb->comments}
WHERE comment_type NOT IN ('action_log', 'order_note', 'webhook_delivery')
GROUP BY comment_approved
",
ARRAY_A
);
$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 ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash', 'spam' ), true ) ) {
$stats['all'] += $row['num_comments'];
$stats['total_comments'] += $row['num_comments'];
} elseif ( ! in_array( $row['comment_approved'], array( 'post-trashed', 'trash' ), true ) ) {
$stats['total_comments'] += $row['num_comments'];
}
if ( isset( $approved[ $row['comment_approved'] ] ) ) {
$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
}
}
foreach ( $approved as $key ) {
if ( empty( $stats[ $key ] ) ) {
$stats[ $key ] = 0;
}
}
$stats = (object) $stats;
set_transient( 'wc_count_comments', $stats );
}
}
return $stats;
}