Skip to content

Commit ad97d06

Browse files
committed
refactor: db query placeholders
1 parent 121ee00 commit ad97d06

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

bin/bump-version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,4 @@ function ($matches) use ($newVersion) {
5555
file_put_contents($configFile, $configContent);
5656
file_put_contents($readmeFile, $readmeContent);
5757

58-
echo "Updated Version v{$newVersion}" . "\n";
58+
echo "Updated Version v{$newVersion}\n";

includes/Actions/GamiPress/GamiPressController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static function fetchAllAchievementType()
8989
global $wpdb;
9090

9191
return $wpdb->get_results(
92-
$wpdb->prepare("SELECT ID, post_name, post_title, post_type FROM {$wpdb->posts} WHERE post_type LIKE %s AND post_status = 'publish' ORDER BY post_title ASC", 'achievement-type')
92+
$wpdb->prepare("SELECT ID, post_name, post_title, post_type FROM %1s WHERE post_type LIKE %2s AND post_status = 'publish' ORDER BY post_title ASC", $wpdb->posts, 'achievement-type')
9393
);
9494
}
9595

@@ -109,7 +109,7 @@ public static function fetchAllPointType()
109109
{
110110
global $wpdb;
111111
$points = $wpdb->get_results(
112-
$wpdb->prepare("SELECT ID, post_name, post_title, post_type FROM {$wpdb->posts} WHERE post_type LIKE %s AND post_status = 'publish' ORDER BY post_title ASC", 'points-type')
112+
$wpdb->prepare("SELECT ID, post_name, post_title, post_type FROM %1s WHERE post_type LIKE %2s AND post_status = 'publish' ORDER BY post_title ASC", $wpdb->posts, 'points-type')
113113
);
114114
wp_send_json_success($points);
115115
}

includes/Actions/WooCommerce/WooCommerceController.php

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,24 @@ public function searchProjects($queryParams)
273273
public static function allSubscriptionsProducts()
274274
{
275275
global $wpdb;
276-
$allSubscriptions = $wpdb->get_results("
277-
SELECT posts.ID, posts.post_title FROM {$wpdb->posts} as posts
278-
LEFT JOIN {$wpdb->term_relationships} as rel ON (posts.ID = rel.object_id)
279-
WHERE rel.term_taxonomy_id IN (SELECT term_id FROM {$wpdb->terms} WHERE slug IN ('subscription','variable-subscription'))
280-
AND posts.post_type = 'product'
281-
AND posts.post_status = 'publish'
282-
UNION ALL
283-
SELECT ID, post_title FROM {$wpdb->posts}
284-
WHERE post_type = 'shop_subscription'
285-
AND post_status = 'publish'
286-
ORDER BY post_title
287-
");
276+
$allSubscriptions = $wpdb->get_results(
277+
$wpdb->prepare(
278+
"SELECT posts.ID, posts.post_title FROM %1s as posts
279+
LEFT JOIN %2s as rel ON (posts.ID = rel.object_id)
280+
WHERE rel.term_taxonomy_id IN (SELECT term_id FROM %3s WHERE slug IN ('subscription','variable-subscription'))
281+
AND posts.post_type = 'product'
282+
AND posts.post_status = 'publish'
283+
UNION ALL
284+
SELECT ID, post_title FROM %4s
285+
WHERE post_type = 'shop_subscription'
286+
AND post_status = 'publish'
287+
ORDER BY post_title",
288+
$wpdb->posts,
289+
$wpdb->term_relationships,
290+
$wpdb->terms,
291+
$wpdb->posts
292+
)
293+
);
288294

289295
$subscriptions[] = [
290296
'product_id' => 'any',

includes/Core/Util/UnInstallation.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,21 @@ public function uninstall()
5050
}
5151

5252
foreach ($columns as $column) {
53-
$wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->prefix}options` WHERE option_name= %s", $column));
53+
$wpdb->query(
54+
$wpdb->prepare(
55+
'DELETE FROM %1s WHERE option_name= %2s',
56+
"{$wpdb->prefix}options",
57+
$column,
58+
)
59+
);
5460
}
5561

56-
$wpdb->query($wpdb->prepare("DELETE FROM `{$wpdb->prefix}options` WHERE `option_name` LIKE %s", '%btcbi_webhook_%'));
62+
$wpdb->query(
63+
$wpdb->prepare(
64+
'DELETE FROM %1s WHERE `option_name` LIKE %2s',
65+
"{$wpdb->prefix}options",
66+
'%btcbi_webhook_%'
67+
)
68+
);
5769
}
5870
}

0 commit comments

Comments
 (0)