-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
uninstall.php
71 lines (60 loc) · 1.51 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
68
69
70
71
<?php
/**
* View Admin As - Uninstaller
*
* Remove plugin data from the database
*
* @author Jory Hogeveen <[email protected]>
* @package view-admin-as
* @since 1.3.4
* @version 1.8.2
*/
//if uninstall not called from WordPress exit
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die();
}
vaa_uninstall();
if ( is_multisite() ) {
global $wp_version;
if ( version_compare( $wp_version, '4.5.999', '<' ) ) {
// @codingStandardsIgnoreLine >> Backwards compat (Sadly does not work for large networks -> return false).
$blogs = wp_get_sites();
} else {
$blogs = get_sites();
}
if ( $blogs ) {
foreach ( $blogs as $blog ) {
$blog = (array) $blog;
vaa_uninstall( intval( $blog['blog_id'] ) );
}
vaa_uninstall( 'site' );
}
}
function vaa_uninstall( $blog_id = false ) {
// Delete all View Admin As options
$option_keys = array( 'vaa_view_admin_as', 'vaa_role_defaults', 'vaa_role_manager' );
if ( $blog_id ) {
if ( 'site' === $blog_id ) {
foreach ( $option_keys as $option_key ) {
delete_site_option( $option_key );
}
} else {
foreach ( $option_keys as $option_key ) {
delete_blog_option( $blog_id, $option_key );
}
}
} else {
foreach ( $option_keys as $option_key ) {
delete_option( $option_key );
}
// Delete all View Admin As user metadata
$user_meta_keys = array(
'vaa-view-admin-as',
// Older (not used anymore) keys
'view-admin-as',
);
foreach ( $user_meta_keys as $user_meta_key ) {
delete_metadata( 'user', null, $user_meta_key, '', true );
}
}
}