Skip to content

Commit 867a8d2

Browse files
committed
Update disable-comments.php
Update disable-comments.php
1 parent bbb4aec commit 867a8d2

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

disable-comments.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -1131,9 +1131,9 @@ private function delete_comments($_args){
11311131
if (!empty($delete_post_types)) {
11321132
// Loop through post_types and remove comments/meta and set posts comment_count to 0.
11331133
foreach ($delete_post_types as $delete_post_type) {
1134-
$wpdb->query("DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'");
1135-
$wpdb->query("DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$delete_post_type'");
1136-
$wpdb->query("UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '$delete_post_type'");
1134+
$wpdb->query($wpdb->prepare("DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '%s'", $delete_post_type));
1135+
$wpdb->query($wpdb->prepare("DELETE comments FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '%s'", $delete_post_type));
1136+
$wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET comment_count = 0 WHERE post_author != 0 AND post_type = '%s'", $delete_post_type));
11371137

11381138
$post_type_object = get_post_type_object($delete_post_type);
11391139
$post_type_label = $post_type_object ? $post_type_object->labels->name : $delete_post_type;
@@ -1151,15 +1151,15 @@ private function delete_comments($_args){
11511151
if (!empty($delete_comment_types)) {
11521152
// Loop through comment_types and remove comments/meta and set posts comment_count to 0.
11531153
foreach ($delete_comment_types as $delete_comment_type) {
1154-
$wpdb->query("DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID WHERE comments.comment_type = '$delete_comment_type'");
1155-
$wpdb->query("DELETE comments FROM $wpdb->comments comments WHERE comments.comment_type = '$delete_comment_type'");
1154+
$wpdb->query($wpdb->prepare("DELETE cmeta FROM $wpdb->commentmeta cmeta INNER JOIN $wpdb->comments comments ON cmeta.comment_id=comments.comment_ID WHERE comments.comment_type = '%s'", $delete_comment_type));
1155+
$wpdb->query($wpdb->prepare("DELETE comments FROM $wpdb->comments comments WHERE comments.comment_type = '%s'", $delete_comment_type));
11561156
$deletedPostTypeNames[] = $commenttypes[$delete_comment_type];
11571157
}
11581158

11591159
// Update comment_count on post_types
11601160
foreach ($types as $key => $value) {
1161-
$comment_count = $wpdb->get_var("SELECT COUNT(comments.comment_ID) FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '$key'");
1162-
$wpdb->query("UPDATE $wpdb->posts SET comment_count = $comment_count WHERE post_author != 0 AND post_type = '$key'");
1161+
$comment_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(comments.comment_ID) FROM $wpdb->comments comments INNER JOIN $wpdb->posts posts ON comments.comment_post_ID=posts.ID WHERE posts.post_type = '%s'", $key));
1162+
$wpdb->query($wpdb->prepare("UPDATE $wpdb->posts SET comment_count = %d WHERE post_author != 0 AND post_type = '%s'", $comment_count, $key));
11631163
}
11641164

11651165
$wpdb->query("OPTIMIZE TABLE $wpdb->commentmeta");

0 commit comments

Comments
 (0)