-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
141 lines (121 loc) · 4.64 KB
/
Copy pathuninstall.php
File metadata and controls
141 lines (121 loc) · 4.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
140
141
<?php
/**
* Jetonomy Uninstall
*
* Runs when a site administrator deletes the Jetonomy plugin from wp-admin.
* Removes all database tables, options, capabilities, cron jobs, and transients
* created by the plugin.
*
* This file is intentionally standalone — it does not require or include any
* other plugin files so it remains safe to execute after the plugin files have
* been removed by WordPress.
*
* @package Jetonomy
* @since 1.0.0
*/
// WordPress sets this constant before calling uninstall.php.
// Bail immediately if this file is accessed directly.
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
defined( 'ABSPATH' ) || exit;
global $wpdb;
// -------------------------------------------------------------------------
// 1. Drop custom database tables.
//
// Pulls the canonical table list from Schema::get_table_names() so the drop
// list never goes stale when a new table is added to Schema. Schema is a
// pure namespaced helper with no load-time side effects (no hooks, no DB
// calls in the class body), so requiring it here is safe even after
// plugin files are mostly removed by WordPress's uninstall flow. The
// Composer autoloader is intentionally NOT relied on — vendor/ may already
// be deleted by the time this file runs.
// -------------------------------------------------------------------------
require_once __DIR__ . '/includes/db/class-schema.php';
\Jetonomy\DB\Schema::drop_tables();
// -------------------------------------------------------------------------
// 2. Delete plugin options.
// -------------------------------------------------------------------------
delete_option( 'jetonomy_settings' );
delete_option( 'jetonomy_db_version' );
delete_option( 'jetonomy_setup_complete' );
delete_option( 'jetonomy_demo_data' );
delete_option( 'jetonomy_clean_uninstall' );
// Delete any option whose name begins with "jetonomy_permalinks_flushed"
// (the plugin stores per-blog variants of this key on multisite).
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$wpdb->esc_like( 'jetonomy_permalinks_flushed' ) . '%'
)
);
// -------------------------------------------------------------------------
// 3. Remove Jetonomy capabilities from all WordPress roles.
//
// get_editable_roles() covers built-in and any custom roles added by other
// plugins, ensuring nothing is left behind regardless of site configuration.
// -------------------------------------------------------------------------
$jetonomy_caps = array(
'jetonomy_read',
'jetonomy_create_posts',
'jetonomy_create_replies',
'jetonomy_vote',
'jetonomy_upload',
'jetonomy_edit_own_posts',
'jetonomy_edit_others_posts',
'jetonomy_delete_others_posts',
'jetonomy_close_posts',
'jetonomy_pin_posts',
'jetonomy_move_posts',
'jetonomy_moderate',
'jetonomy_manage_spaces',
'jetonomy_manage_settings',
'jetonomy_manage_users',
'jetonomy_view_reports',
'jetonomy_manage_tags',
'jetonomy_manage_categories',
'jetonomy_ban_users',
'jetonomy_manage_restrictions',
);
foreach ( array_keys( get_editable_roles() ) as $role_name ) {
$role = get_role( $role_name );
if ( ! $role ) {
continue;
}
foreach ( $jetonomy_caps as $cap ) {
$role->remove_cap( $cap );
}
}
// -------------------------------------------------------------------------
// 4. Clear scheduled cron jobs.
// -------------------------------------------------------------------------
$cron_hooks = array(
'jetonomy_evaluate_trust_levels',
'jetonomy_cleanup_restrictions',
'jetonomy_prune_activity_log',
'jetonomy_cleanup_notifications',
);
foreach ( $cron_hooks as $hook ) {
wp_clear_scheduled_hook( $hook );
}
// -------------------------------------------------------------------------
// 5. Delete transients created by the plugin.
//
// WordPress stores transients as options with the key "_transient_{name}"
// (and "_transient_timeout_{name}" for the expiry). A LIKE query is the
// only reliable way to bulk-delete transients by prefix.
// -------------------------------------------------------------------------
$transient_prefix = $wpdb->esc_like( '_transient_jetonomy_' );
$timeout_prefix = $wpdb->esc_like( '_transient_timeout_jetonomy_' );
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s",
$transient_prefix . '%',
$timeout_prefix . '%'
)
);
// -------------------------------------------------------------------------
// 6. Flush rewrite rules.
//
// Remove the plugin's custom rewrite rules from the database so WordPress
// does not attempt to resolve /community/* URLs after the plugin is gone.
// -------------------------------------------------------------------------
delete_option( 'rewrite_rules' );