| 1 |
<?php |
| 2 |
/** |
| 3 |
* Uninstall routine. Runs when the Plugin is deleted |
| 4 |
* at Plugins > Delete. |
| 5 |
* |
| 6 |
* @package ConvertKit |
| 7 |
* @author ConvertKit |
| 8 |
*/ |
| 9 |
|
| 10 |
// If uninstall.php is not called by WordPress, die. |
| 11 |
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
// Only WordPress and PHP methods can be used. Plugin classes and methods |
| 16 |
// are not reliably available due to the Plugin being deactivated and going |
| 17 |
// through deletion now. |
| 18 |
|
| 19 |
// Delete the log file from the uploads directory. |
| 20 |
// The Plugin's own directory is deleted by WordPress once this routine completes, |
| 21 |
// so any historic log file stored there doesn't need deleting here. |
| 22 |
// This mirrors ConvertKit_Log::get_log_file_name() in the Kit WordPress Libraries, |
| 23 |
// which we can't call as the Plugin's classes aren't reliably available. |
| 24 |
$upload_dir = wp_upload_dir(); |
| 25 |
if ( empty( $upload_dir['error'] ) && ! empty( $upload_dir['basedir'] ) ) { |
| 26 |
$log_slug = sanitize_key( basename( __DIR__ ) ); |
| 27 |
$log_file = trailingslashit( $upload_dir['basedir'] ) . 'kit-logs/' . $log_slug . '-' . wp_hash( $log_slug ) . '.log'; |
| 28 |
|
| 29 |
if ( file_exists( $log_file ) ) { |
| 30 |
wp_delete_file( $log_file ); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// Get settings. |
| 35 |
$settings = get_option( '_wp_convertkit_settings' ); |
| 36 |
|
| 37 |
// Bail if no settings exist. |
| 38 |
if ( ! $settings ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
// Revoke Access Token. |
| 43 |
if ( array_key_exists( 'access_token', $settings ) && ! empty( $settings['access_token'] ) ) { |
| 44 |
wp_remote_post( |
| 45 |
'https://api.kit.com/v4/oauth/revoke', |
| 46 |
array( |
| 47 |
'headers' => array( |
| 48 |
'Content-Type' => 'application/x-www-form-urlencoded', |
| 49 |
), |
| 50 |
'body' => array( |
| 51 |
'client_id' => 'HXZlOCj-K5r0ufuWCtyoyo3f688VmMAYSsKg1eGvw0Y', |
| 52 |
'token' => $settings['access_token'], |
| 53 |
'token_type_hint' => 'access_token', |
| 54 |
), |
| 55 |
'timeout' => 5, |
| 56 |
) |
| 57 |
); |
| 58 |
} |
| 59 |
|
| 60 |
// Revoke Refresh Token. |
| 61 |
if ( array_key_exists( 'refresh_token', $settings ) && ! empty( $settings['refresh_token'] ) ) { |
| 62 |
wp_remote_post( |
| 63 |
'https://api.kit.com/v4/oauth/revoke', |
| 64 |
array( |
| 65 |
'headers' => array( |
| 66 |
'Content-Type' => 'application/x-www-form-urlencoded', |
| 67 |
), |
| 68 |
'body' => array( |
| 69 |
'client_id' => 'HXZlOCj-K5r0ufuWCtyoyo3f688VmMAYSsKg1eGvw0Y', |
| 70 |
'token' => $settings['refresh_token'], |
| 71 |
'token_type_hint' => 'refresh_token', |
| 72 |
), |
| 73 |
'timeout' => 5, |
| 74 |
) |
| 75 |
); |
| 76 |
} |
| 77 |
|
| 78 |
// Remove credentials from settings. |
| 79 |
$settings['access_token'] = ''; |
| 80 |
$settings['refresh_token'] = ''; |
| 81 |
$settings['token_expires'] = ''; |
| 82 |
$settings['api_key'] = ''; |
| 83 |
$settings['api_secret'] = ''; |
| 84 |
|
| 85 |
// Save settings. |
| 86 |
update_option( '_wp_convertkit_settings', $settings ); |
| 87 |
|