-
Notifications
You must be signed in to change notification settings - Fork 6
/
uninstall.php
31 lines (24 loc) · 932 Bytes
/
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
<?php
// If uninstall is not called from WordPress, exit
if ( !defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit();
}
global $wpdb;
$users_id = get_users( array(
'fields' => 'ID'
) );
foreach( $users_id as $user_id ){
delete_user_meta( $user_id, 'when_last_login' );
delete_user_meta( $user_id, 'when_last_login_count' );
delete_user_meta( $user_id, 'wll_consent_to_track' );
delete_user_meta( $user_id, 'wll_consent_to_track_date' );
}
//Delete CPT's from databse if you uninstall When Last Login and Post Meta.
$sql = "DELETE p, pm FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON pm.post_id = p.ID WHERE p.post_type = 'wll_records'";
$wpdb->query( $sql );
//Delete custom table if it exists
$delete_table = $wpdb->prefix . 'wll_login_attempts' ;
$sql = "DROP TABLE IF EXISTS `$delete_table`";
$wpdb->query( $sql );
$sqlQuery = "DELETE FROM $wpdb->options WHERE option_name LIKE 'wll%'";
$wpdb->query($sqlQuery);