Repository navigation
Expand file tree
/
Copy pathuninstall.php
More file actions
100 lines (81 loc) · 3.09 KB
/
Copy pathuninstall.php
File metadata and controls
100 lines (81 loc) · 3.09 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
<?php
/**
* Uninstall script for PublishPress Checklists (Free Version)
*
* This file is executed when the plugin is deleted from the WordPress admin.
* It will remove all plugin data if the user has enabled the "Delete All Data on Uninstall" option.
*/
defined('ABSPATH') || exit;
// If uninstall not called from WordPress, then exit.
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
/**
* Delete all plugin data if the user has enabled the option
*/
function publishpress_checklists_uninstall_cleanup()
{
// Check if user has enabled data deletion on uninstall
$settings_options = get_option('publishpress_checklists_settings_options', []);
if (is_object($settings_options)) {
$settings_options = (array) $settings_options;
}
if (!is_array($settings_options)) {
$settings_options = [];
}
$delete_option_value = $settings_options['delete_data_on_uninstall'] ?? 'off';
$delete_data = in_array($delete_option_value, ['on', '1', 1, true], true);
if (!$delete_data) {
// User hasn't enabled data deletion, so we keep all data
return;
}
// Delete all plugin options (free version only)
$options_to_delete = [
// Core free plugin options
'publishpress_checklists_checklists_options',
'publishpress_checklists_settings_options',
// Free module options only
'publishpress_checklists_permalinks_options',
'publishpress_checklists_permissions_options',
'publishpress_checklists_reviews_options',
'publishpress_checklists_yoastseo_options',
'publishpress_checklists_version',
// Migration flags
'publishpress_checklists_options_migrated_2_0_0',
'publishpress_checklists_options_migrated_2_6_0',
// Reviews/branding
'publishpress-checklists_wp_reviews_installed_on',
'PUBLISHPRESS_CAPS_VERSION',
// Activation flag
'ppch_activated',
];
foreach ($options_to_delete as $option_name) {
delete_option($option_name);
// Also delete from multisite if applicable
if (is_multisite()) {
delete_site_option($option_name);
}
}
// Delete any transients (only if they exist)
global $wpdb;
$transient_prefix = $wpdb->esc_like('_transient_publishpress_checklists_') . '%';
$timeout_prefix = $wpdb->esc_like('_transient_timeout_publishpress_checklists_') . '%';
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall cleanup; wp_cache_flush() runs below.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$transient_prefix
)
);
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.NoCaching -- Uninstall cleanup; wp_cache_flush() runs below.
$wpdb->query(
$wpdb->prepare(
"DELETE FROM {$wpdb->options} WHERE option_name LIKE %s",
$timeout_prefix
)
);
// Clear any cached data
wp_cache_flush();
}
// Execute the cleanup
publishpress_checklists_uninstall_cleanup();