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