Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Remove wpdb prepare statement in get_category_review_count method #5471

Merged
merged 1 commit into from
Jan 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/StoreApi/Schemas/ProductCategorySchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,12 @@ protected function get_category_review_count( $term ) {
$terms_to_count_str = implode( ',', $terms_to_count );
}

// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$products_of_category_sql = $wpdb->prepare(
"SELECT SUM(comment_count) as review_count
$products_of_category_sql = "
SELECT SUM(comment_count) as review_count
FROM {$wpdb->posts} AS posts
INNER JOIN {$wpdb->term_relationships} AS term_relationships ON posts.ID = term_relationships.object_id
WHERE term_relationships.term_taxonomy_id IN ({$terms_to_count_str})"
);
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
WHERE term_relationships.term_taxonomy_id IN (" . esc_sql( $terms_to_count_str ) . ')
';

$review_count = $wpdb->get_var( $products_of_category_sql ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared

Expand Down