-
Notifications
You must be signed in to change notification settings - Fork 2
/
uninstall.php
49 lines (40 loc) · 1.01 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
47
48
49
<?php
/**
* Uninstall Book Database
*
* Delete the following data when the plugin is uninstalled:
* - All options.
* - Custom tables.
* - Custom capabilities.
*
* @package book-database
* @copyright Copyright (c) 2020, Ashley Gibson
* @license GPL2+
* @since 1.0
*/
namespace Book_Database;
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Load BDB
include_once( 'book-database.php' );
book_database();
// Bail if delete isn't enabled.
if ( ! function_exists( __NAMESPACE__ . '\bdb_get_option' ) || ! bdb_get_option( 'delete_on_uninstall' ) ) {
return;
}
global $wpdb;
// Remove all plugin settings.
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'bdb\_%'" );
// Drop tables
foreach ( book_database()->get_tables() as $table ) {
if ( $table->exists() ) {
$table->uninstall();
}
}
// Remove capabilities
$role = get_role( 'administrator' );
foreach ( get_book_capabilities() as $capability ) {
$role->remove_cap( $capability );
}