forked from ashleyfae/book-database
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
69 lines (57 loc) · 1.21 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* Uninstall Book Database
*
* Delete the following data when the plugin is uninstalled:
* - All options.
* - Drop custom tables.
*
* @package book-database
* @copyright Copyright (c) 2017, 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' );
// Bail if delete isn't enabled.
if ( ! 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
$tables = array(
'authors',
'book_author_relationships',
'book_taxonomies',
'book_term_relationships',
'book_terms',
'books',
'book_meta',
'owned_editions',
'reading_log',
'reviewmeta',
'reviews',
'review_meta',
'series'
);
foreach ( $tables as $table_key ) {
$table = book_database()->get_table( $table_key );
if ( ! $table ) {
continue;
}
if ( $table->exists() ) {
$table->uninstall();
}
}
// Remove capabilities
$role = get_role( 'administrator' );
foreach ( get_book_capabilities() as $capability ) {
$role->remove_cap( $capability );
}