-
Notifications
You must be signed in to change notification settings - Fork 2
/
uninstall.php
50 lines (38 loc) · 1.57 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
<?php
/**
* CashTippr Uninstall
*
* Uninstall and delete all stored session & payment data from all users.
*/
defined( 'WP_UNINSTALL_PLUGIN' ) || exit;
require_once (plugin_dir_path ( __FILE__ ) . 'data.php');
class CashtipprUninstall {
public function __construct() {
}
public function uninstall() {
global $wpdb, $wp_version;
// Only remove all user session + payment data if this is set to true.
// This is to prevent data loss when deleting the plugin from the backend
// and to ensure only the site owner can perform this action.
if (CashtipprData::REMOVE_ALL_DATA !== true)
return;
//wp_clear_scheduled_hook( 'woocommerce_scheduled_sales' );
//$table = Cashtippr::getTableName('sessions'); // we don't have that class loaded
$tables = get_option('cashtippr_tables', array());
foreach ($tables as $table) {
$wpdb->query( "DROP TABLE IF EXISTS $table" );
}
delete_option('cashtippr_tables');
delete_option('cashtippr_settings'); // TODO load settings class in case that option name has been changed (currently not possible)
delete_option('cashtippr_memcached_secret');
delete_option('cashtippr_version');
$attributes = array('tipAmount');
$attributesStr = "'" . implode("', '", $attributes) . "'";
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ($attributesStr)");
// No post data to delete. The shortcode will be kept in posts, it just won't display anything anymore.
// Clear any cached data that has been removed.
wp_cache_flush();
}
}
$uninstall = new CashtipprUninstall();
$uninstall->uninstall();