PluginProbe
SlimStat Analytics / trunk
SlimStat Analytics vtrunk
5.5.0 5.4.12 4.7.4 4.7.4.1 4.7.5 4.7.5.1 4.7.5.2 4.7.5.3 4.7.6 4.7.6.1 4.7.7 4.7.8 4.7.8.1 4.7.8.2 4.7.8.3 4.7.9 4.7.9.1 4.8 4.8.1 4.8.2 4.8.3 4.8.4 4.8.4.1 4.8.5 4.8.5.1 All 212 releases
wp-slimstat / uninstall.php

uninstall.php in SlimStat Analytics trunk, at uninstall.php

112 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Avoid direct access to this piece of code
4 if (!defined('WP_UNINSTALL_PLUGIN')) {
5 exit;
6 }
7
8 $slimstat_options = get_option('slimstat_options', []);
9
10 if (isset($slimstat_options['delete_data_on_uninstall']) && 'on' != $slimstat_options['delete_data_on_uninstall']) {
11 // Do not delete db data and settings
12 return;
13 }
14
15 if (!empty($slimstat_options['addon_custom_db_dbuser']) && !empty($slimstat_options['addon_custom_db_dbpass']) && !empty($slimstat_options['addon_custom_db_dbname']) && !empty($slimstat_options['addon_custom_db_dbhost'])) {
16 $slimstat_wpdb = new wpdb($slimstat_options['addon_custom_db_dbuser'], $slimstat_options['addon_custom_db_dbpass'], $slimstat_options['addon_custom_db_dbname'], $slimstat_options['addon_custom_db_dbhost']);
17 } else {
18 $slimstat_wpdb = $GLOBALS['wpdb'];
19 }
20
21 if (function_exists('is_multisite') && is_multisite()) {
22 $blogids = $GLOBALS['wpdb']->get_col($GLOBALS['wpdb']->prepare("
23 SELECT blog_id
24 FROM {$GLOBALS[ 'wpdb' ]->blogs}
25 WHERE site_id = %d
26 AND deleted = 0
27 AND spam = 0", $GLOBALS['wpdb']->siteid));
28
29 foreach ($blogids as $blog_id) {
30 switch_to_blog($blog_id);
31 slimstat_uninstall($slimstat_wpdb, $slimstat_options);
32 restore_current_blog();
33 }
34 } else {
35 slimstat_uninstall($slimstat_wpdb, $slimstat_options);
36 }
37
38 $slimstat_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_browsers', $GLOBALS[ 'wpdb' ]->base_prefix));
39 $slimstat_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_screenres', $GLOBALS[ 'wpdb' ]->base_prefix));
40 $slimstat_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_content_info', $GLOBALS[ 'wpdb' ]->base_prefix));
41
42 function slimstat_uninstall($_wpdb = '', $_options = [])
43 {
44 // Bye bye data...
45 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_outbound', $GLOBALS[ 'wpdb' ]->prefix));
46 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_events', $GLOBALS[ 'wpdb' ]->prefix));
47 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_stats', $GLOBALS[ 'wpdb' ]->prefix));
48 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_events_archive', $GLOBALS[ 'wpdb' ]->prefix));
49 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_stats_archive', $GLOBALS[ 'wpdb' ]->prefix));
50 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_stats_3', $GLOBALS[ 'wpdb' ]->prefix));
51 $_wpdb->query(sprintf('DROP TABLE IF EXISTS %sslim_stats_archive_3', $GLOBALS[ 'wpdb' ]->prefix));
52
53 // Bye bye options...
54 delete_option('slimstat_options');
55 delete_option('slimstat_visit_id');
56 delete_option('slimstat_filters');
57 delete_option('slimstat_tracker_error');
58
59 // Goals & Funnels (5.5.0+): admin-configured records + cache-version key.
60 delete_option('slimstat_goals');
61 delete_option('slimstat_funnels');
62 delete_option('slimstat_goals_cache_ver');
63
64 // Goals & Funnels (5.5.0+): per-goal/per-funnel transients plus the
65 // unique-visitor denominator transients (slimstat_uv_*), accumulated between
66 // cache-version bumps. Safe to DELETE with LIKE here because uninstall runs
67 // once and isn't racing other requests.
68 $GLOBALS['wpdb']->query(sprintf(
69 "DELETE FROM %soptions WHERE option_name LIKE '\\_transient\\_slimstat\\_goal\\_%%' OR option_name LIKE '\\_transient\\_timeout\\_slimstat\\_goal\\_%%' OR option_name LIKE '\\_transient\\_slimstat\\_funnel\\_%%' OR option_name LIKE '\\_transient\\_timeout\\_slimstat\\_funnel\\_%%' OR option_name LIKE '\\_transient\\_slimstat\\_uv\\_%%' OR option_name LIKE '\\_transient\\_timeout\\_slimstat\\_uv\\_%%'",
70 $GLOBALS['wpdb']->prefix
71 ));
72
73 $GLOBALS['wpdb']->query(sprintf("DELETE FROM %susermeta WHERE meta_key LIKE '%%meta-box-order_slimstat%%'", $GLOBALS[ 'wpdb' ]->prefix));
74 $GLOBALS['wpdb']->query(sprintf("DELETE FROM %susermeta WHERE meta_key LIKE '%%metaboxhidden_slimstat%%'", $GLOBALS[ 'wpdb' ]->prefix));
75 $GLOBALS['wpdb']->query(sprintf("DELETE FROM %susermeta WHERE meta_key LIKE '%%closedpostboxes_slimstat%%'", $GLOBALS[ 'wpdb' ]->prefix));
76
77 // Sweep filter-options transients left behind by the dropdown cache.
78 $transient_like = $GLOBALS['wpdb']->esc_like('_transient_slimstat_fopts_') . '%';
79 $timeout_like = $GLOBALS['wpdb']->esc_like('_transient_timeout_slimstat_fopts_') . '%';
80 $GLOBALS['wpdb']->query($GLOBALS['wpdb']->prepare(
81 "DELETE FROM {$GLOBALS['wpdb']->options} WHERE option_name LIKE %s OR option_name LIKE %s",
82 $transient_like,
83 $timeout_like
84 ));
85 if (function_exists('wp_cache_delete_group')) {
86 wp_cache_delete_group('slimstat_filter_options');
87 }
88
89 // Remove scheduled autopurge events
90 wp_clear_scheduled_hook('wp_slimstat_purge');
91 wp_clear_scheduled_hook('wp_slimstat_update_geoip_database');
92
93 // Remove the uploads folder
94 if (defined('UPLOADS')) {
95 $upload_dir = ABSPATH . UPLOADS . '/wp-slimstat';
96 } else {
97 $upload_dir_info = wp_upload_dir();
98 $upload_dir = $upload_dir_info['basedir'];
99
100 // Handle multisite environment
101 if (is_multisite() && !(is_main_network() && is_main_site() && defined('MULTISITE'))) {
102 $upload_dir = str_replace('/sites/' . get_current_blog_id(), '', $upload_dir);
103 }
104
105 $upload_dir .= '/wp-slimstat';
106 }
107
108 WP_Filesystem();
109 global $wp_filesystem;
110 $wp_filesystem->delete($upload_dir, true, 'd');
111 }
112