forked from AyeCode/userswp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
99 lines (83 loc) · 2.76 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
<?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;
$wpdb->hide_errors();
if ( is_multisite() ) {
$main_site = get_network()->site_id;
$sql = "SELECT blog_id FROM $wpdb->blogs
WHERE archived = '0' AND spam = '0'
AND deleted = '0'";
$blog_ids = $wpdb->get_col( $sql );
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
uwp_uninstall();
}
switch_to_blog( $main_site );
uwp_drop_usermeta_table();
restore_current_blog();
} else {
uwp_uninstall();
uwp_drop_usermeta_table();
}
function uwp_uninstall() {
$uwp_options = get_option( 'uwp_settings' );
if ( $uwp_options['uninstall_erase_data'] == '1' ) {
global $wpdb;
$table_name = $wpdb->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 form fields table
$table_name = $wpdb->prefix . 'uwp_form_fields';
$sql = "DROP TABLE IF EXISTS $table_name";
$wpdb->query( $sql );
// Drop form extras table
$extras_table_name = $wpdb->prefix . 'uwp_form_extras';
$sql = "DROP TABLE IF EXISTS $extras_table_name";
$wpdb->query( $sql );
// Drop form profile tabs table
$profile_table_name = $wpdb->prefix . 'uwp_profile_tabs';
$sql = "DROP TABLE IF EXISTS $profile_table_name";
$wpdb->query( $sql );
// Delete pages
wp_delete_post( $uwp_options['register_page'], true );
wp_delete_post( $uwp_options['login_page'], true );
wp_delete_post( $uwp_options['profile_page'], true );
wp_delete_post( $uwp_options['account_page'], true );
wp_delete_post( $uwp_options['change_page'], true );
wp_delete_post( $uwp_options['forgot_page'], true );
wp_delete_post( $uwp_options['reset_page'], true );
wp_delete_post( $uwp_options['users_page'], true );
// 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' );
}
}
function uwp_drop_usermeta_table() {
global $wpdb;
// Drop usermeta table
$meta_table_name = $wpdb->prefix . 'uwp_usermeta';
$sql = "DROP TABLE IF EXISTS $meta_table_name";
$wpdb->query( $sql );
}