-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathuninstall.php
More file actions
43 lines (33 loc) · 1.27 KB
/
Copy pathuninstall.php
File metadata and controls
43 lines (33 loc) · 1.27 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
<?php
/**
* Fired when the plugin is uninstalled.
*
* @link https://actitud.xyz
* @since 2023-12-01
*/
// If uninstall not called from WordPress, then exit.
if (!defined('WP_UNINSTALL_PLUGIN')) {
exit;
}
// Nonce?: https://core.trac.wordpress.org/ticket/38661
// Validate the request to ensure the correct plugin is being uninstalled
$plugin = isset($_REQUEST['plugin']) ? sanitize_text_field(wp_unslash((string) $_REQUEST['plugin'])) : '';
$action = isset($_REQUEST['action']) ? sanitize_text_field(wp_unslash((string) $_REQUEST['action'])) : '';
$validPlugins = [
'hyperpress/hyperpress.php',
'hyperpress/api-for-htmx.php', // legacy entry point
'api-for-htmx/api-for-htmx.php', // legacy entry point
];
if ($action !== 'delete-plugin' || !in_array($plugin, $validPlugins, true)) {
wp_die('Error uninstalling: wrong plugin.');
}
// Clears HyperPress left-overs
global $wpdb;
$hp_options = $wpdb->get_results("SELECT option_name FROM $wpdb->options WHERE option_name LIKE '_hxwp_%' OR option_name LIKE 'hxwp_%' OR option_name LIKE '_hyperpress_%' OR option_name LIKE 'hyperpress_%'");
if (is_array($hp_options) && !empty($hp_options)) {
foreach ($hp_options as $option) {
delete_option($option->option_name);
}
}
// Flush rewrite rules
flush_rewrite_rules();