| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall Powered Cache |
| 4 |
* Deletes all plugin related data and configurations |
| 5 |
* |
| 6 |
* @package PoweredCache |
| 7 |
*/ |
| 8 |
|
| 9 |
// phpcs:disable WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
| 10 |
// phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
require_once 'powered-cache.php'; |
| 18 |
|
| 19 |
// flush cache |
| 20 |
\PoweredCache\Utils\powered_cache_flush(); |
| 21 |
|
| 22 |
if ( is_multisite() ) { |
| 23 |
$sites = get_sites(); |
| 24 |
foreach ( $sites as $site ) { |
| 25 |
switch_to_blog( $site->blog_id ); |
| 26 |
\PoweredCache\Utils\log( sprintf( 'Uninstalling site %s', $site->blog_id ) ); |
| 27 |
powered_cache_uninstall_site(); |
| 28 |
restore_current_blog(); |
| 29 |
} |
| 30 |
} else { |
| 31 |
\PoweredCache\Utils\log( sprintf( 'Uninstalling...' ) ); |
| 32 |
powered_cache_uninstall_site(); |
| 33 |
} |
| 34 |
|
| 35 |
\PoweredCache\Config::factory()->define_wp_cache( false ); |
| 36 |
|
| 37 |
// delete object cache file |
| 38 |
if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' ) |
| 39 |
&& false !== strpos( file_get_contents( $file ), 'POWERED_OBJECT_CACHE' ) ) { |
| 40 |
\PoweredCache\Utils\log( sprintf( 'Removing: %s', 'object-cache.php' ) ); |
| 41 |
|
| 42 |
unlink( untrailingslashit( WP_CONTENT_DIR ) . '/object-cache.php' ); |
| 43 |
} |
| 44 |
|
| 45 |
// delete advanced cache file |
| 46 |
if ( file_exists( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ) ) { |
| 47 |
\PoweredCache\Utils\log( sprintf( 'Removing: %s', 'advanced-cache.php' ) ); |
| 48 |
|
| 49 |
unlink( untrailingslashit( WP_CONTENT_DIR ) . '/advanced-cache.php' ); |
| 50 |
} |
| 51 |
|
| 52 |
// delete cache directory |
| 53 |
if ( file_exists( \PoweredCache\Utils\get_cache_dir() ) ) { |
| 54 |
\PoweredCache\Utils\log( sprintf( 'Removing dir: %s', \PoweredCache\Utils\get_cache_dir() ) ); |
| 55 |
\PoweredCache\Utils\remove_dir( \PoweredCache\Utils\get_cache_dir() ); |
| 56 |
} |
| 57 |
|
| 58 |
// delete configuration files |
| 59 |
if ( file_exists( WP_CONTENT_DIR . '/pc-config' ) ) { |
| 60 |
\PoweredCache\Utils\log( 'Removing config dir...' ); |
| 61 |
\PoweredCache\Utils\remove_dir( WP_CONTENT_DIR . '/pc-config' ); |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Uninstall Powered Cache |
| 66 |
* |
| 67 |
* @since 2.0 |
| 68 |
*/ |
| 69 |
function powered_cache_uninstall_site() { |
| 70 |
// delete network settings |
| 71 |
delete_site_option( \PoweredCache\Constants\SETTING_OPTION ); |
| 72 |
delete_site_option( \PoweredCache\Constants\DB_VERSION_OPTION_NAME ); |
| 73 |
|
| 74 |
// delete site settings |
| 75 |
delete_option( \PoweredCache\Constants\SETTING_OPTION ); |
| 76 |
delete_option( \PoweredCache\Constants\DB_VERSION_OPTION_NAME ); |
| 77 |
|
| 78 |
// remove cron tasks |
| 79 |
wp_clear_scheduled_hook( \PoweredCache\Constants\PURGE_CACHE_CRON_NAME ); |
| 80 |
wp_clear_scheduled_hook( \PoweredCache\Constants\PURGE_FO_CRON_NAME ); |
| 81 |
} |
| 82 |
|