| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall handler — deletes options, cache, and drop-in. |
| 4 |
* |
| 5 |
* @package XSpeed |
| 6 |
*/ |
| 7 |
|
| 8 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 9 |
exit; |
| 10 |
} |
| 11 |
|
| 12 |
xspeed_uninstall_cleanup(); |
| 13 |
|
| 14 |
/** |
| 15 |
* Run all uninstall cleanup. Wrapped in a function so locals don't pollute global scope. |
| 16 |
*/ |
| 17 |
function xspeed_uninstall_cleanup() { |
| 18 |
delete_option( 'xspeed_options' ); |
| 19 |
delete_option( 'xspeed_stats' ); |
| 20 |
|
| 21 |
if ( ! function_exists( 'WP_Filesystem' ) ) { |
| 22 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 23 |
} |
| 24 |
WP_Filesystem(); |
| 25 |
global $wp_filesystem; |
| 26 |
if ( ! $wp_filesystem ) { |
| 27 |
return; |
| 28 |
} |
| 29 |
|
| 30 |
$cache_dir = WP_CONTENT_DIR . '/cache/xspeed'; |
| 31 |
if ( $wp_filesystem->is_dir( $cache_dir ) ) { |
| 32 |
$wp_filesystem->delete( $cache_dir, true ); |
| 33 |
} |
| 34 |
|
| 35 |
// Static-cache tree — separate from the flat-hash cache dir, holds |
| 36 |
// the {host}/{path}/index.html files the .htaccess rewrite block |
| 37 |
// serves directly. Same teardown rules as XSPEED_CACHE_DIR. |
| 38 |
$static_dir = WP_CONTENT_DIR . '/cache/xspeed-static'; |
| 39 |
if ( $wp_filesystem->is_dir( $static_dir ) ) { |
| 40 |
$wp_filesystem->delete( $static_dir, true ); |
| 41 |
} |
| 42 |
|
| 43 |
// Rewrite block in site-root .htaccess. WP's marker helpers handle |
| 44 |
// the "remove only our block" semantics — passing an empty array |
| 45 |
// strips the markers in place. |
| 46 |
$htaccess = ABSPATH . '.htaccess'; |
| 47 |
if ( $wp_filesystem->exists( $htaccess ) && $wp_filesystem->is_writable( $htaccess ) ) { |
| 48 |
if ( ! function_exists( 'insert_with_markers' ) ) { |
| 49 |
require_once ABSPATH . 'wp-admin/includes/misc.php'; |
| 50 |
} |
| 51 |
insert_with_markers( $htaccess, 'xSpeed Static Cache', array() ); |
| 52 |
} |
| 53 |
|
| 54 |
$drop_in = WP_CONTENT_DIR . '/advanced-cache.php'; |
| 55 |
if ( $wp_filesystem->exists( $drop_in ) ) { |
| 56 |
$contents = $wp_filesystem->get_contents( $drop_in ); |
| 57 |
if ( is_string( $contents ) && false !== strpos( $contents, 'XSPEED_DROPIN' ) ) { |
| 58 |
$wp_filesystem->delete( $drop_in ); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
$wp_config = ABSPATH . 'wp-config.php'; |
| 63 |
if ( defined( 'WP_CACHE' ) && WP_CACHE && $wp_filesystem->is_writable( $wp_config ) ) { |
| 64 |
$config = $wp_filesystem->get_contents( $wp_config ); |
| 65 |
if ( is_string( $config ) ) { |
| 66 |
$config = preg_replace( "/define\\(\\s*['\"]WP_CACHE['\"]\\s*,\\s*true\\s*\\);\\s*\\n?/", '', $config ); |
| 67 |
$wp_filesystem->put_contents( $wp_config, $config, FS_CHMOD_FILE ); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|