-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
69 lines (59 loc) · 1.55 KB
/
uninstall.php
File metadata and controls
69 lines (59 loc) · 1.55 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
67
68
69
<?php
/**
* Uninstall handler for G-code Reference plugin.
*
* Removes all plugin data when plugin is deleted (not deactivated).
*
* @package GCode_Reference
* @since 2.0.0
*/
// Exit if not called by WordPress
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
/**
* Remove plugin settings from database
*/
delete_option('gcode_reference_settings');
/**
* Remove all transients (cached JSON data)
*
* Transients are cached with pattern: gcode_json_*
* We need to clean them all up to prevent orphaned cache entries.
*/
global $wpdb;
// Delete all transients matching our pattern
$wpdb->query(
"DELETE FROM {$wpdb->options}
WHERE option_name LIKE '_transient_gcode_json_%'
OR option_name LIKE '_transient_timeout_gcode_json_%'"
);
/**
* Remove uploaded JSON files from wp-content/uploads/gcode-reference/
*
* Only removes files in our dedicated directory, not touching
* any other uploads.
*/
$upload_dir = wp_upload_dir();
$plugin_upload_dir = trailingslashit($upload_dir['basedir']) . 'gcode-reference/';
if (is_dir($plugin_upload_dir)) {
// Remove all files in directory
$files = glob($plugin_upload_dir . '*');
if ($files) {
foreach ($files as $file) {
if (is_file($file)) {
unlink($file);
}
}
}
// Remove directory itself
rmdir($plugin_upload_dir);
}
/**
* Clear any object cache
*
* In case the site uses persistent object caching (Redis, Memcached),
* flush our cache group.
*/
wp_cache_flush();
// That's it! Plugin data is now completely removed.