-
Notifications
You must be signed in to change notification settings - Fork 2
/
uninstall.php
73 lines (54 loc) · 1.72 KB
/
uninstall.php
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
67
68
69
70
71
72
73
<?php
/**
* Fired when the plugin is uninstalled.
*
* @package Recently
* @author Hector Cabrera <[email protected]>
* @license GPL-2.0+
* @link http://cabrerahector.com
* @copyright 2022 Hector Cabrera
*/
// If uninstall, not called from WordPress, then exit
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Run uninstall for each blog in the network
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
global $wpdb;
$original_blog_id = get_current_blog_id();
$blogs_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
foreach( $blogs_ids as $blog_id ) {
switch_to_blog( $blog_id );
// Delete plugin's options
delete_site_option( 'recently_ver' );
delete_site_option( 'recently_config' );
delete_site_option( 'recently_rand' );
delete_site_option( 'recently_transients' );
// delete thumbnails cache and its directory
recently_delete_thumb_cache();
}
// Switch back to current blog
switch_to_blog( $original_blog_id );
} else {
// Delete plugin's options
delete_option( 'recently_ver' );
delete_option( 'recently_config' );
delete_option( 'recently_rand' );
delete_option( 'recently_transients' );
// delete thumbnails cache and its directory
recently_delete_thumb_cache();
}
function recently_delete_thumb_cache() {
$wp_upload_dir = wp_upload_dir();
if ( is_dir( $wp_upload_dir['basedir'] . "/recently" ) ) {
$files = glob( $wp_upload_dir['basedir'] . "/recently/*" ); // get all file names
if ( is_array($files) && ! empty($files) ) {
foreach($files as $file){ // iterate files
if ( is_file($file) )
@unlink($file); // delete file
}
}
// Finally, delete recently's upload directory
@rmdir( $wp_upload_dir['basedir'] . "/recently" );
}
}