Tracker: fix review count.

Fixes #23848
This commit is contained in:
Dan Wyman 2019-05-30 12:45:47 -07:00
parent 3ea8162cff
commit 7355fadfdd
1 changed files with 20 additions and 10 deletions

View File

@ -349,7 +349,13 @@ class WC_Tracker {
*/
private static function get_review_counts() {
global $wpdb;
$review_count = array();
$review_count = array( 'total' => 0 );
$status_map = array(
'0' => 'pending',
'1' => 'approved',
'trash' => 'trash',
'spam' => 'spam',
);
$counts = $wpdb->get_results(
"
SELECT comment_approved, COUNT(*) AS num_reviews
@ -359,15 +365,19 @@ class WC_Tracker {
",
ARRAY_A
);
if ( $counts ) {
if ( ! $counts ) {
return $review_count;
}
foreach ( $counts as $count ) {
if ( 1 === $count['comment_approved'] ) {
$review_count['approved'] = $count['num_reviews'];
} else {
$review_count['pending'] = $count['num_reviews'];
}
$status = $count['comment_approved'];
if ( array_key_exists( $status, $status_map ) ) {
$review_count[ $status_map[ $status ] ] = $count['num_reviews'];
}
$review_count['total'] += $count['num_reviews'];
}
return $review_count;
}