-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuninstall.php
66 lines (52 loc) · 1.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
<?php
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die( esc_html__( 'Access Denied', 'validate-user' ) );
}
// Delete Options
$options = [
'validate-user-admin-email-send',
'validate-user-admin-email-from-name',
'validate-user-admin-email-from-address',
'validate-user-admin-email-to-name',
'validate-user-admin-email-to-address',
'validate-user-admin-email-message',
'validate-user-client-email-from-name',
'validate-user-client-email-from-address',
'validate-user-confirmation-email-subject',
'validate-user-confirmation-email-message',
'validate-user-rejection-email-send',
'validate-user-rejection-email-subject',
'validate-user-rejection-email-message',
'validate-user-use-recaptcha',
'validate-user-recaptcha-public-key',
'validate-user-recaptcha-secret-key'
];
foreach ( $options as $option ) {
delete_option( $option );
}
// Delete Applications Post Type
$application_ids = get_posts( [
'fields' => 'ids',
'numberposts' => - 1,
'post_type' => 'validate-apps'
] );
foreach ( $application_ids as $id ) {
wp_delete_post( $id );
}
// Delete User Meta and change role
$users = get_users();
foreach ( $users as $user ) {
$user_meta = get_user_meta( $user->ID );
foreach ( $user_meta as $key => $value ) {
if ( str_starts_with( $key, 'validate-user-' ) ) {
delete_user_meta( $user->ID, $key );
}
}
$roles = $user->roles;
if ( in_array( 'validated_user', $roles, true ) ) {
$user->remove_role( 'validated_user' );
$user->add_role( 'subscriber' );
}
}
// Remove custom role
remove_role( 'validated_user' );