| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall Surge |
| 4 |
* |
| 5 |
* @package Surge |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Surge; |
| 9 |
|
| 10 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
include_once( __DIR__ . '/include/common.php' ); |
| 15 |
|
| 16 |
// Remove advanced-cache.php only if its ours. |
| 17 |
if ( file_exists( WP_CONTENT_DIR . '/advanced-cache.php' ) ) { |
| 18 |
$contents = file_get_contents( WP_CONTENT_DIR . '/advanced-cache.php' ); |
| 19 |
if ( strpos( $contents, 'namespace Surge;' ) !== false ) { |
| 20 |
unlink( WP_CONTENT_DIR . '/advanced-cache.php' ); |
| 21 |
} |
| 22 |
} |
| 23 |
|
| 24 |
// Delete the cache directory |
| 25 |
function delete( $path ) { |
| 26 |
if ( is_file( $path ) ) { |
| 27 |
unlink( $path ); |
| 28 |
return; |
| 29 |
} |
| 30 |
|
| 31 |
if ( ! is_dir( $path ) ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
$entries = scandir( $path ); |
| 36 |
foreach ( $entries as $entry ) { |
| 37 |
if ( $entry == '.' || $entry == '..' ) { |
| 38 |
continue; |
| 39 |
} |
| 40 |
|
| 41 |
delete( $path . '/' . $entry ); |
| 42 |
} |
| 43 |
|
| 44 |
rmdir( $path ); |
| 45 |
} |
| 46 |
|
| 47 |
delete( CACHE_DIR ); |
| 48 |
|
| 49 |
delete_option( 'surge_installed' ); |
| 50 |
|