-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
35 lines (28 loc) · 766 Bytes
/
uninstall.php
File metadata and controls
35 lines (28 loc) · 766 Bytes
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
<?php
/**
* Uninstall handler.
*
* Runs when the plugin is deleted from WordPress.
* Respects user preference for keeping data.
*
* @package MyPlugin
*/
// Exit if not called by WordPress uninstallation
defined('WP_UNINSTALL_PLUGIN') || exit;
// Load autoloader
require_once __DIR__ . '/vendor/autoload.php';
use MyPlugin\Core\PluginContext;
use MyPlugin\Lifecycle\Uninstaller;
// Create context
$context = PluginContext::create([
'file' => __DIR__ . '/my-plugin.php',
'slug' => 'my-plugin',
'prefix' => 'myplugin_',
'textDomain' => 'my-plugin',
'version' => '1.0.0',
]);
// Check user preference
$keepData = get_option($context->optionKey('keep_data_on_uninstall'), true);
if (!$keepData) {
Uninstaller::uninstall($context);
}