-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.php
More file actions
94 lines (83 loc) · 2.9 KB
/
Copy pathuninstall.php
File metadata and controls
94 lines (83 loc) · 2.9 KB
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
<?php
/**
* Uninstall routine. Runs when the Plugin is deleted
* at Plugins > Delete.
*
* @package CKWC
* @author ConvertKit
*/
// If uninstall.php is not called by WordPress, die.
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
die;
}
// Only WordPress and PHP methods can be used. Plugin classes and methods
// are not reliably available due to the Plugin being deactivated and going
// through deletion now.
// Delete the log file from the uploads directory.
// The Plugin's own directory is deleted by WordPress once this routine completes,
// so any historic log file stored there doesn't need deleting here.
// This mirrors ConvertKit_Log::get_log_file_name() in the Kit WordPress Libraries,
// which we can't call as the Plugin's classes aren't reliably available.
$upload_dir = wp_upload_dir();
if ( empty( $upload_dir['error'] ) && ! empty( $upload_dir['basedir'] ) ) {
$log_slug = sanitize_key( basename( __DIR__ ) );
$log_file = trailingslashit( $upload_dir['basedir'] ) . 'kit-logs/' . $log_slug . '-' . wp_hash( $log_slug ) . '.log';
if ( file_exists( $log_file ) ) {
wp_delete_file( $log_file );
}
}
// Get providers.
$providers = get_option( 'wpforms_providers' );
// Bail if no providers exist.
if ( ! $providers ) {
return;
}
// Bail if no Kit connections exist.
if ( ! array_key_exists( 'convertkit', $providers ) ) {
return;
}
// Iterate through each connection, revoking the tokens.
foreach ( $providers['convertkit'] as $account_id => $connection ) {
// Revoke Access Token.
if ( array_key_exists( 'access_token', $connection ) && ! empty( $connection['access_token'] ) ) {
wp_remote_post(
'https://api.kit.com/v4/oauth/revoke',
array(
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
),
'body' => array(
'client_id' => '147qqKJeENYp5MqgL6AOShDDcLK3UQeClmcIV1ij3gI',
'token' => $connection['access_token'],
'token_type_hint' => 'access_token',
),
'timeout' => 5,
)
);
}
// Revoke Refresh Token.
if ( array_key_exists( 'refresh_token', $connection ) && ! empty( $connection['refresh_token'] ) ) {
wp_remote_post(
'https://api.kit.com/v4/oauth/revoke',
array(
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded',
),
'body' => array(
'client_id' => '147qqKJeENYp5MqgL6AOShDDcLK3UQeClmcIV1ij3gI',
'token' => $connection['refresh_token'],
'token_type_hint' => 'refresh_token',
),
'timeout' => 5,
)
);
}
// Remove credentials from settings.
$providers['convertkit'][ $account_id ]['access_token'] = '';
$providers['convertkit'][ $account_id ]['refresh_token'] = '';
$providers['convertkit'][ $account_id ]['token_expires'] = '';
$providers['convertkit'][ $account_id ]['api_key'] = '';
$providers['convertkit'][ $account_id ]['api_secret'] = '';
}
// Save settings.
update_option( 'wpforms_providers', $providers );