-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathuninstall.php
85 lines (68 loc) · 2.68 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Uninstall Powered Cache
* Deletes all plugin related data and configurations
*
* @package PoweredCache
*/
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
// phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
require_once 'powered-cache.php';
// flush cache
\PoweredCache\Utils\powered_cache_flush();
if ( is_multisite() ) {
$sites = get_sites();
foreach ( $sites as $site ) {
switch_to_blog( $site->blog_id );
\PoweredCache\Utils\log( sprintf( 'Uninstalling site %s', $site->blog_id ) );
powered_cache_uninstall_site();
restore_current_blog();
}
} else {
\PoweredCache\Utils\log( sprintf( 'Uninstalling...' ) );
powered_cache_uninstall_site();
}
\PoweredCache\Config::factory()->define_wp_cache( false );
$object_cache_file = untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php';
// delete object cache file
if ( file_exists( $object_cache_file ) && false !== strpos( file_get_contents( $object_cache_file ), 'POWERED_OBJECT_CACHE' ) ) {
\PoweredCache\Utils\log( sprintf( 'Removing: %s', 'object-cache.php' ) );
unlink( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' );
}
// delete advanced cache file
if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ) ) {
\PoweredCache\Utils\log( sprintf( 'Removing: %s', 'advanced-cache.php' ) );
unlink( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' );
}
// delete cache directory
if ( file_exists( \PoweredCache\Utils\get_cache_dir() ) ) {
\PoweredCache\Utils\log( sprintf( 'Removing dir: %s', \PoweredCache\Utils\get_cache_dir() ) );
\PoweredCache\Utils\remove_dir( \PoweredCache\Utils\get_cache_dir() );
}
// delete configuration files
if ( file_exists( WP_CONTENT_DIR . '/pc-config' ) ) {
\PoweredCache\Utils\log( 'Removing config dir...' );
\PoweredCache\Utils\remove_dir( WP_CONTENT_DIR . '/pc-config' );
}
/**
* Uninstall Powered Cache
*
* @since 2.0
*/
function powered_cache_uninstall_site() {
// delete network settings
delete_site_option( \PoweredCache\Constants\SETTING_OPTION );
delete_site_option( \PoweredCache\Constants\DB_VERSION_OPTION_NAME );
// delete site settings
delete_option( \PoweredCache\Constants\SETTING_OPTION );
delete_option( \PoweredCache\Constants\DB_VERSION_OPTION_NAME );
// remove cron tasks
wp_clear_scheduled_hook( \PoweredCache\Constants\PURGE_CACHE_CRON_NAME );
wp_clear_scheduled_hook( \PoweredCache\Constants\PURGE_FO_CRON_NAME );
delete_site_transient( \PoweredCache\Constants\PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
delete_transient( \PoweredCache\Constants\PURGE_CACHE_PLUGIN_NOTICE_TRANSIENT );
}