forked from google/site-kit-wp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
67 lines (57 loc) · 1.8 KB
/
uninstall.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Plugin reset and uninstall cleanup.
*
* @package Google\Site_Kit
* @copyright 2019 Google LLC
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
* @link https://sitekit.withgoogle.com
*/
namespace Google\Site_Kit;
// Bail if not uninstalling or resetting the plugin.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) && empty( $googlesitekit_reset_context ) ) {
return;
}
global $wpdb;
$prefix = 'googlesitekit\_%';
// Delete options and transients.
$wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery
$wpdb->prepare(
"DELETE FROM $wpdb->options WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s OR option_name = %s",
$prefix,
'_transient_' . $prefix,
'_transient_timeout_' . $prefix,
'googlesitekit-active-modules'
)
);
// Delete user meta.
$wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery
$wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $wpdb->get_blog_prefix() . $prefix )
);
// Clear network data if multisite and uninstalling or resetting network-wide.
$conditions = (
is_multisite()
&&
(
defined( 'WP_UNINSTALL_PLUGIN' )
||
( ! empty( $googlesitekit_reset_context ) && $googlesitekit_reset_context->is_network_mode() )
)
);
if ( $conditions ) {
$wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery
$wpdb->prepare(
"DELETE FROM $wpdb->sitemeta WHERE meta_key LIKE %s OR meta_key LIKE %s OR meta_key LIKE %s OR meta_key = %s",
$prefix,
'_site_transient_' . $prefix,
'_site_transient_timeout_' . $prefix,
'googlesitekit-active-modules'
)
);
// Delete user meta.
$wpdb->query( // phpcs:ignore WordPress.VIP.DirectDatabaseQuery
$wpdb->prepare( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE %s", $prefix )
);
}
// Clear options cache.
wp_cache_flush();