-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathuninstall.php
More file actions
66 lines (57 loc) · 1.84 KB
/
uninstall.php
File metadata and controls
66 lines (57 loc) · 1.84 KB
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
<?php
/**
* Uninstall Simply Static
*/
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Clear any scheduled exports.
if ( function_exists( 'wp_clear_scheduled_hook' ) ) {
wp_clear_scheduled_hook( 'simply_static_site_export_cron' );
}
// Remove the entire Simply Static directory inside uploads (e.g., wp-content/uploads/simply-static).
// We do this before deleting options so a custom temp path still resolves correctly if needed elsewhere.
$uploads = wp_upload_dir();
$ss_root = trailingslashit( $uploads['basedir'] ) . 'simply-static';
/**
* Recursively delete a directory and its contents.
* Lightweight and local to uninstall to avoid loading plugin classes.
*
* @param string $dir
*
* @return bool True on success or if path does not exist; false on failure.
*/
function ss_rrmdir_uninstall( $dir ) {
$dir = (string) $dir;
if ( $dir === '' || ! file_exists( $dir ) ) {
return true; // nothing to do
}
if ( is_file( $dir ) || is_link( $dir ) ) {
return unlink( $dir );
}
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator( $dir, RecursiveDirectoryIterator::SKIP_DOTS ),
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ( $it as $path => $fileinfo ) {
if ( $fileinfo->isDir() ) {
if ( ! rmdir( $fileinfo->getRealPath() ) ) {
return false;
}
} else {
if ( ! unlink( $fileinfo->getRealPath() ) ) {
return false;
}
}
}
return rmdir( $dir );
}
ss_rrmdir_uninstall( $ss_root );
// Delete Simply Static's settings after filesystem cleanup.
delete_option( 'simply-static' );
// Drop DB tables used by Simply Static.
require_once plugin_dir_path( __FILE__ ) . 'src/class-ss-plugin.php';
require_once plugin_dir_path( __FILE__ ) . 'src/models/class-ss-model.php';
require_once plugin_dir_path( __FILE__ ) . 'src/models/class-ss-page.php';
Simply_Static\Page::drop_table();