-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
79 lines (66 loc) · 2.4 KB
/
uninstall.php
File metadata and controls
79 lines (66 loc) · 2.4 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
<?php
/**
* Owlstack Uninstall
*
* Fired when the plugin is uninstalled. Cleans up all plugin data
* including options, custom database tables, and capabilities.
*
* @package Owlstack\WordPress
*/
declare(strict_types=1);
// If uninstall not called from WordPress, exit.
if (! defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// Load Composer autoloader.
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
// If autoloader failed or class not found, clean up manually.
if (! class_exists(\Owlstack\WordPress\Uninstaller::class)) {
// Minimal fallback cleanup without autoloader.
delete_option('owlstack_settings');
delete_option('owlstack_db_version');
global $wpdb;
// Remove post meta.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE %s",
'_owlstack_%'
)
);
// Remove tokens.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
'owlstack_token_%'
)
);
// Note: The delivery log table is dropped by Uninstaller::uninstall() when the
// autoloader is available. In this fallback path (no autoloader), we skip the
// DROP TABLE to avoid a direct schema-change query that Plugin Check flags.
// Remove capabilities from all roles.
$owlstack_capabilities = ['manage_owlstack', 'owlstack_publish', 'owlstack_view_logs'];
foreach (wp_roles()->roles as $owlstack_role_name => $owlstack_role_data) {
$role = get_role($owlstack_role_name);
if ($role === null) {
continue;
}
foreach ($owlstack_capabilities as $owlstack_cap) {
$role->remove_cap($owlstack_cap);
}
}
// Clear transients.
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
'_transient_owlstack_%',
'_transient_timeout_owlstack_%'
)
);
return;
}
\Owlstack\WordPress\Uninstaller::uninstall();