-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuninstall.php
46 lines (42 loc) · 1.31 KB
/
uninstall.php
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
<?php
/**
* Uninstall the plugin.
*
* Deletes the custom database tables, and the plugin options.
*
* @package Progress_Planner
*/
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
require_once __DIR__ . '/classes/class-settings.php';
require_once __DIR__ . '/classes/class-query.php';
/**
* Delete the plugin options.
*
* Keeps the badges and activation date.
*
* @return void
*/
function progress_planner_cleanup_options() {
$value = get_option( \Progress_Planner\Settings::OPTION_NAME, [] );
$keep = [ 'badges', 'activation_date' ];
foreach ( array_keys( $value ) as $key ) { // @phpstan-ignore-line argument.type
if ( ! in_array( $key, $keep, true ) ) {
unset( $value[ $key ] ); // @phpstan-ignore-line offsetAccess.nonOffsetAccessible
}
}
update_option( \Progress_Planner\Settings::OPTION_NAME, $value );
}
progress_planner_cleanup_options();
// Delete the custom database tables.
global $wpdb;
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
$wpdb->query(
$wpdb->prepare(
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders.UnsupportedIdentifierPlaceholder, WordPress.DB.DirectDatabaseQuery.SchemaChange
'DROP TABLE IF EXISTS %i',
$wpdb->prefix . \Progress_Planner\Query::TABLE_NAME
)
);