PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
← All changes | app/Services/OptionsService.php +12 -6 2.0.2 → 2.1.1 View file →
@@ -6,29 +6,35 @@
6 6 {
7 7 /**
8 8 * Delete all plugin options from the wp_options table
9 9 * @param bool $private Whether to delete private options (prefixed with _)
10 + * @param string[] $exclude Exclude specific options from deletion
10 11 */
11 - public function wipe(bool $private = false): bool
12 + public function wipe(bool $private = false, array $exclude = []): bool
12 13 {
13 14 global $wpdb;
14 15
16 + $excludeSql = '';
17 + foreach ($exclude as $optionName) {
18 + $excludeSql .= $wpdb->prepare(' AND option_name != %s', $optionName);
19 + }
20 +
15 21 if ($private) {
16 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk delete has no WP API equivalent; cache is flushed below.
22 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Bulk delete has no WP API equivalent; cache is flushed below. Preserve clause is prepared above.
17 23 $result = $wpdb->query(
18 24 $wpdb->prepare(
19 - "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
25 + "DELETE FROM {$wpdb->options} WHERE (option_name LIKE %s OR option_name LIKE %s)",
20 26 'metricool_%',
21 27 '_metricool_%'
22 - )
28 + ) . $excludeSql
23 29 );
24 30 } else {
25 - // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk delete has no WP API equivalent; cache is flushed below.
31 + // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared -- Bulk delete has no WP API equivalent; cache is flushed below. Preserve clause is prepared above.
26 32 $result = $wpdb->query(
27 33 $wpdb->prepare(
28 34 "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
29 35 'metricool_%'
30 - )
36 + ) . $excludeSql
31 37 );
32 38 }
33 39
34 40 // Make sure deleted options are not cached