-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.php
91 lines (79 loc) · 2.05 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Uninstall Novelist
*
* Deletes the following plugin data:
* + Custom Post Types
* + Custom Taxonomies and Terms
* + Plugin Settings
* + Capabilities and Roles
* + Transients
*
* @package novelist
* @copyright Copyright (c) 2016, Nose Graze Ltd.
* @license GPL2+
*/
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
// Include Novelist file.
include_once 'novelist.php';
global $wpdb, $wp_roles;
// Bail if they haven't opted to delete settings.
if ( ! novelist_get_option( 'uninstall_on_delete' ) ) {
return;
}
/*
* Delete all the custom post types.
*/
$novelist_taxonomies = array( 'novelist-series', 'novelist-genre', );
$novelist_post_types = array( 'book' );
foreach ( $novelist_post_types as $post_type ) {
$novelist_taxonomies = array_merge( $novelist_taxonomies, get_object_taxonomies( $post_type ) );
$args = array(
'post_type' => $post_type,
'post_status' => 'any',
'numberposts' => - 1,
'fields' => 'ids'
);
$items = get_posts( $args );
if ( $items ) {
foreach ( $items as $item ) {
wp_delete_post( $item, true );
}
}
}
/*
* Delete all terms and taxonomies.
*/
$get_terms_args = array(
'taxonomy' => $novelist_taxonomies,
'hide_empty' => false
);
$terms = get_terms( $get_terms_args );
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
wp_delete_term( $term->term_id, $term->taxonomy );
}
}
/*
* Delete plugin settings.
*/
delete_option( 'novelist_settings' );
delete_option( 'novelist_version' );
delete_option( 'novelist_version_upgraded_from' );
delete_option( 'novelist_imported_demo_book' );
/*
* Delete capabilities and roles.
*/
Novelist()->roles->remove_caps();
$novelist_roles = array( 'book_manager' );
foreach ( $novelist_roles as $role ) {
remove_role( $role );
}
/*
* Delete transients.
*/
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_novelist_%'" );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE '_transient_timeout_novelist_%'" );