PluginProbe
Metricool – Social media and site statistics / 2.0.2
Metricool – Social media and site statistics v2.0.2
2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / app / Services / OptionsService.php

OptionsService.php in Metricool – Social media and site statistics 2.0.2, at app/Services/OptionsService.php

42 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Metricool\Services;
4
5 class OptionsService
6 {
7 /**
8 * Delete all plugin options from the wp_options table
9 * @param bool $private Whether to delete private options (prefixed with _)
10 */
11 public function wipe(bool $private = false): bool
12 {
13 global $wpdb;
14
15 if ($private) {
16 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk delete has no WP API equivalent; cache is flushed below.
17 $result = $wpdb->query(
18 $wpdb->prepare(
19 "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
20 'metricool_%',
21 '_metricool_%'
22 )
23 );
24 } else {
25 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Bulk delete has no WP API equivalent; cache is flushed below.
26 $result = $wpdb->query(
27 $wpdb->prepare(
28 "DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
29 'metricool_%'
30 )
31 );
32 }
33
34 // Make sure deleted options are not cached
35 if (function_exists('wp_cache_flush')) {
36 wp_cache_flush();
37 }
38
39 return $result !== false;
40 }
41 }
42