-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
95 lines (79 loc) · 2.33 KB
/
uninstall.php
File metadata and controls
95 lines (79 loc) · 2.33 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
* ThemePlus Uninstall
*
* Fired when the plugin is uninstalled. Safely removes all
* ThemePlus data including user-configured dynamic options.
*
* @package ThemePlus
*/
// If uninstall not called from WordPress, exit
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
/**
* Simple cleanup that handles dynamic option names
*/
function themeplus_uninstall_simple(): void {
global $wpdb;
// 1. Default options (always the same)
delete_option('themeplus_options');
delete_option('themeplus_custom_fonts');
delete_option('themeplus_custom_fonts_css');
// 2. Find and delete dynamic options created by users
// Pattern: themeplus_options_xxxxxxxx (e.g., themeplus_options_mytheme)
$options = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options
WHERE option_name LIKE %s",
'themeplus_options_%'
)
);
foreach ($options as $option_name) {
delete_option($option_name);
}
// 3. Clean up other possible patterns (extra safety)
$common_patterns = [
'themeplus_%_options', // Matches: themeplus_mytheme_options
'%_themeplus_settings', // Matches: my_themeplus_settings (less common)
];
foreach ($common_patterns as $pattern) {
$options = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options
WHERE option_name LIKE %s",
$pattern
)
);
foreach ($options as $option_name) {
delete_option($option_name);
}
}
// 4. Multisite cleanup (clean every site in network)
if (is_multisite()) {
$blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
foreach ($blog_ids as $blog_id) {
switch_to_blog($blog_id);
// Delete default options for this site
delete_option('themeplus_options');
delete_option('themeplus_custom_fonts');
delete_option('themeplus_custom_fonts_css');
// Delete dynamic options for this site
$site_options = $wpdb->get_col(
$wpdb->prepare(
"SELECT option_name FROM $wpdb->options
WHERE option_name LIKE %s",
'themeplus_options_%'
)
);
foreach ($site_options as $option_name) {
delete_option($option_name);
}
restore_current_blog();
}
}
// 5. Clear WordPress object cache
wp_cache_flush();
}
// Run cleanup
themeplus_uninstall_simple();