-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathuninstall.php
114 lines (96 loc) · 2.53 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<?php
/**
* Fired when the plugin is uninstalled.
*
* When populating this file, consider the following flow
* of control:
*
* - This method should be static
* - Check if the $_REQUEST content actually is the plugin name
* - Run an admin referrer check to make sure it goes through authentication
* - Verify the output of $_GET makes sense
* - Repeat with other user roles. Best directly by using the links/query string parameters.
* - Repeat things for multisite. Once for a single site in the network, once sitewide.
*
* This file may be updated more in future version of the Boilerplate; however, this is the
* general skeleton and outline for how the file should work.
*
* For more information, see the following discussion:
* https://github.com/tommcfarlin/WordPress-Plugin-Boilerplate/pull/123#issuecomment-28541913
*
* @link https://justinfrydman.com/
* @since 0.0.3
*
* @package wpcable
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
exit;
}
// If uninstall not called from WordPress, then exit.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
/**
* Fired when the plugin is deleted.
*
* This class defines all code necessary to run during the plugin's deletion routine.
*
* @since 0.0.3
* @package wpcable
* @author Justin Frydman <justin.frydman@gmail.com>
*/
class wpcable_uninstall {
/**
* Fired on plugin deactivation.
*
* Removes all plugin tables and wp_option data
*
* @since 0.0.3
*/
public static function uninstall() {
// sanity checks
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
check_ajax_referer( 'updates' );
// good to go
self::remove_plugin_options();
self::remove_plugin_tables();
}
/**
* Removes plugin options from $prefix_options
*
* @since 0.0.3
*/
private static function remove_plugin_options() {
$prefix = 'wpcable_';
$options = array(
$prefix . 'account_details',
$prefix . 'revenue',
$prefix . 'balance',
$prefix . 'average',
$prefix . 'what_to_check',
$prefix . 'transcactions_version'
);
foreach( $options as $option ) {
delete_option( $option );
}
}
/*
* Remove plugin generated tables
*
* @since 0.0.3
*/
private static function remove_plugin_tables() {
global $wpdb;
$prefix = $wpdb->prefix;
$tables = array(
$prefix . 'codeable_transcactions',
$prefix . 'codeable_amounts',
$prefix . 'codeable_clients',
);
$wpdb->query( 'DROP TABLE IF EXISTS ' . implode( ',', $tables ) );
}
}
wpcable_uninstall::uninstall();