-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuninstall.php
More file actions
140 lines (123 loc) · 3.64 KB
/
Copy pathuninstall.php
File metadata and controls
140 lines (123 loc) · 3.64 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Uninstall script for MCP for WooCommerce plugin
*
* This file is executed when the plugin is deleted from WordPress.
* It cleans up all plugin data including options, transients, and any other data.
*
* @package WordPress MCP
*/
// If uninstall not called from WordPress, exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Clean up plugin options
*/
function mcp_for_woocommerce_cleanup_options() {
// Remove plugin options
$options_to_delete = [
'mcpfowo_settings',
'mcp_for_woocommerce_jwt_secret',
'mcp_for_woocommerce_jwt_tokens',
'mcp_for_woocommerce_auth_settings',
'mcp_for_woocommerce_transport_settings',
'mcp_for_woocommerce_debug_mode',
'mcp_for_woocommerce_allowed_origins',
'mcp_for_woocommerce_rate_limit_settings',
];
foreach ( $options_to_delete as $option ) {
delete_option( $option );
delete_site_option( $option ); // For multisite
}
}
/**
* Clean up transients
*/
function mcp_for_woocommerce_cleanup_transients() {
global $wpdb;
// Delete all transients that start with mcp_for_woocommerce_
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
'_transient_mcp_for_woocommerce_%',
'_transient_timeout_mcp_for_woocommerce_%'
)
);
// For multisite
if ( is_multisite() ) {
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->sitemeta} WHERE meta_key LIKE %s OR meta_key LIKE %s",
'_site_transient_mcp_for_woocommerce_%',
'_site_transient_timeout_mcp_for_woocommerce_%'
)
);
}
}
/**
* Clean up user meta
*/
function mcp_for_woocommerce_cleanup_user_meta() {
global $wpdb;
// Delete user meta related to the plugin
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE %s",
'mcp_for_woocommerce_%'
)
);
}
/**
* Clean up any custom tables (if any were created)
*/
function mcp_for_woocommerce_cleanup_custom_tables() {
// This plugin doesn't create custom tables, but if it did in the future,
// we would drop them here
// global $wpdb;
// $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}mcp_for_woocommerce_logs" );
}
/**
* Clear any cached data
*/
function mcp_for_woocommerce_clear_caches() {
// Clear object cache
wp_cache_flush();
// Clear any plugin-specific cache directories
$cache_dir = WP_CONTENT_DIR . '/cache/mcp-for-woocommerce/';
if ( is_dir( $cache_dir ) ) {
mcp_for_woocommerce_recursive_rmdir( $cache_dir );
}
}
/**
* Recursively remove directory
*
* @param string $dir Directory path
*/
function mcp_for_woocommerce_recursive_rmdir( $dir ) {
if ( ! is_dir( $dir ) ) {
return;
}
$files = array_diff( scandir( $dir ), [ '.', '..' ] );
foreach ( $files as $file ) {
$path = $dir . '/' . $file;
if ( is_dir( $path ) ) {
mcp_for_woocommerce_recursive_rmdir( $path );
} else {
wp_delete_file( $path );
}
}
// Use WP_Filesystem for directory operations
global $wp_filesystem;
if ( empty( $wp_filesystem ) ) {
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();
}
$wp_filesystem->rmdir( $dir );
}
// Execute cleanup functions
mcp_for_woocommerce_cleanup_options();
mcp_for_woocommerce_cleanup_transients();
mcp_for_woocommerce_cleanup_user_meta();
mcp_for_woocommerce_cleanup_custom_tables();
mcp_for_woocommerce_clear_caches();