Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
89 lines (75 loc) · 2.78 KB
/
Copy pathuninstall.php
File metadata and controls
89 lines (75 loc) · 2.78 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
<?php
/**
* Plugin uninstall routine.
*
* Runs when a user deletes the plugin from the WordPress Plugins screen.
* No plugin classes are available in this context.
*
* Data removal is opt-in: tables are dropped only when 'delete_data_on_uninstall'
* was enabled in settings before deletion.
*
* @package Intercessor
* @since 1.0.0
*/
declare(strict_types=1);
// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
global $wpdb;
// Retrieve settings before deletion to check the data-removal flag.
$intercessor_settings = get_option( 'intercessor_settings', array() );
// Remove all plugin options unconditionally.
delete_option( 'intercessor_version' );
delete_option( 'intercessor_settings' );
// Remove per-table schema version options written by the BerlinDB Table layer.
delete_option( 'db_version_intercessor_prayer_requests' );
delete_option( 'db_version_intercessor_requesters' );
delete_option( 'db_version_intercessor_prayer_history' );
delete_option( 'db_version_intercessor_prayer_notes' );
delete_option( 'db_version_intercessor_prayed_counts' );
delete_option( 'db_version_intercessor_requester_notes' );
// Remove the six custom prayer capabilities from all roles, then remove
// the three custom roles (prayer_manager, prayer_warrior, requester).
// Use $wp_roles directly — plugin classes are not available in uninstall.php.
global $wp_roles;
if ( ! isset( $wp_roles ) ) {
$wp_roles = new WP_Roles();
}
$intercessor_prayer_caps = array(
'edit_prayers',
'manage_prayer_settings',
'view_prayer_reports',
'export_prayer_reports',
'view_prayer_sensitive_data',
'read_private_prayers',
);
$intercessor_cap_bearing_roles = array(
'administrator',
'prayer_manager',
'prayer_warrior',
'requester',
);
foreach ( $intercessor_cap_bearing_roles as $intercessor_role_slug ) {
foreach ( $intercessor_prayer_caps as $intercessor_cap ) {
$wp_roles->remove_cap( $intercessor_role_slug, $intercessor_cap );
}
}
remove_role( 'prayer_manager' );
remove_role( 'prayer_warrior' );
remove_role( 'requester' );
// Drop tables only when the site owner explicitly opted in.
if ( ! empty( $intercessor_settings['delete_data_on_uninstall'] ) ) {
// Drop in reverse dependency order: child tables before parent tables.
$intercessor_tables = array(
$wpdb->prefix . 'intercessor_prayed_counts',
$wpdb->prefix . 'intercessor_requester_notes',
$wpdb->prefix . 'intercessor_prayer_notes',
$wpdb->prefix . 'intercessor_prayer_history',
$wpdb->prefix . 'intercessor_prayer_requests',
$wpdb->prefix . 'intercessor_requesters',
);
foreach ( $intercessor_tables as $intercessor_table ) {
// phpcs:ignore WordPress.DB.DirectDatabaseQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$wpdb->query( "DROP TABLE IF EXISTS {$intercessor_table}" );
}
}