forked from AyeCode/userswp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
64 lines (51 loc) · 1.7 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
<?php
/**
* Uninstall UsersWP
*
* Uninstalling UsersWP deletes tables and plugin options.
*
* @package userswp
* @since 1.0.0
*/
// Exit if accessed directly.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
global $wpdb;
if ( !class_exists( 'UsersWP' ) ) {
// Load plugin file.
include_once( 'userswp.php' );
}
if ( uwp_get_option('uninstall_erase_data') == '1' ) {
$wpdb->hide_errors();
// Delete options
delete_option('uwp_settings');
delete_option('uwp_activation_redirect');
delete_option('uwp_flush_rewrite');
delete_option('uwp_default_data_installed');
//delete_option('uwp_db_version');
$table_name = uwp_get_table_prefix() . 'uwp_form_fields';
$rows = $wpdb->get_results("select * from " . $table_name . "");
// Delete user meta for all users
$meta_type = 'user';
$user_id = 0; // This will be ignored, since we are deleting for all users.
$meta_key = 'uwp_usermeta';
$meta_value = ''; // Also ignored. The meta will be deleted regardless of value.
$delete_all = true;
foreach ($rows as $row) {
delete_metadata( $meta_type, $user_id, $row->htmlvar_name, $meta_value, $delete_all );
}
// Drop tables.
// Drop form fields table
$table_name = uwp_get_table_prefix() . 'uwp_form_fields';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query($sql);
// Drop form extras table
$extras_table_name = uwp_get_table_prefix() . 'uwp_form_extras';
$sql = "DROP TABLE IF EXISTS $extras_table_name";
$wpdb->query($sql);
// Drop usermeta table
$meta_table_name = uwp_get_table_prefix() . 'uwp_usermeta';
$sql = "DROP TABLE IF EXISTS $meta_table_name";
$wpdb->query($sql);
}