|
1 | 1 | <?php
|
2 |
| -if ( ! defined( 'ABSPATH' ) ) { |
3 |
| - exit; // Exit if accessed directly. |
4 |
| -} |
| 2 | +/** |
| 3 | + * WooCommerce Stripe Gateway Uninstall |
| 4 | + * |
| 5 | + * @version x.x.x |
| 6 | + */ |
5 | 7 |
|
6 |
| -// if uninstall not called from WordPress exit. |
7 |
| -if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { |
8 |
| - exit; |
9 |
| -} |
| 8 | +// Exit if accessed directly. |
| 9 | +defined( 'ABSPATH' ) || exit; |
| 10 | + |
| 11 | +// Exit if uninstall not called from WordPress. |
| 12 | +defined( 'WP_UNINSTALL_PLUGIN' ) || exit; |
| 13 | + |
| 14 | +// Remove OAuth access_token refresh scheduled job. |
| 15 | +wp_clear_scheduled_hook( 'wc_stripe_refresh_connection' ); |
10 | 16 |
|
11 | 17 | /*
|
12 |
| - * Only remove ALL product and page data if WC_REMOVE_ALL_DATA constant is set to true in user's |
13 |
| - * wp-config.php. This is to prevent data loss when deleting the plugin from the backend |
| 18 | + * ONLY remove the Stripe keys and keep the other configuration. |
| 19 | + * This is to prevent data loss when deleting the plugin from the backend |
14 | 20 | * and to ensure only the site owner can perform this action.
|
15 | 21 | */
|
16 |
| -if ( defined( 'WC_REMOVE_ALL_DATA' ) && true === WC_REMOVE_ALL_DATA ) { |
17 |
| - // Delete options. |
| 22 | +if ( ! defined( 'WC_REMOVE_ALL_DATA' ) || true !== WC_REMOVE_ALL_DATA ) { |
| 23 | + // Remove OAuth keys from the settings |
| 24 | + $settings = get_option( 'woocommerce_stripe_settings', [] ); |
| 25 | + if ( is_array( $settings ) ) { |
| 26 | + // Disable the gateway before removing the plugin, to avoid an invalid API keys notice when reinstalling. |
| 27 | + $settings['enabled'] = 'no'; |
| 28 | + // Live keys |
| 29 | + unset( $settings['publishable_key'], $settings['secret_key'] ); |
| 30 | + unset( $settings['connection_type'], $settings['refresh_token'] ); |
| 31 | + unset( $settings['webhook_data'] ); |
| 32 | + unset( $settings['webhook_secret'] ); |
| 33 | + // Test keys |
| 34 | + unset( $settings['test_publishable_key'], $settings['test_secret_key'] ); |
| 35 | + unset( $settings['test_connection_type'], $settings['test_refresh_token'] ); |
| 36 | + unset( $settings['test_webhook_data'] ); |
| 37 | + unset( $settings['test_webhook_secret'] ); |
| 38 | + } |
| 39 | + update_option( 'woocommerce_stripe_settings', $settings ); |
| 40 | + |
| 41 | +} else { |
| 42 | + // If WC_REMOVE_ALL_DATA constant is set to true in the merchant's wp-config.php, |
| 43 | + // remove ALL plugin settings. |
18 | 44 | delete_option( 'woocommerce_stripe_settings' );
|
| 45 | + |
| 46 | + // Individual payment methods settings |
| 47 | + delete_option( 'woocommerce_stripe_affirm_settings' ); |
| 48 | + delete_option( 'woocommerce_stripe_afterpay_clearpay_settings' ); |
| 49 | + delete_option( 'woocommerce_stripe_alipay_settings' ); |
| 50 | + delete_option( 'woocommerce_stripe_bancontact_settings' ); |
| 51 | + delete_option( 'woocommerce_stripe_boleto_settings' ); |
| 52 | + delete_option( 'woocommerce_stripe_cashapp_settings' ); |
| 53 | + delete_option( 'woocommerce_stripe_card_settings' ); |
| 54 | + delete_option( 'woocommerce_stripe_eps_settings' ); |
| 55 | + delete_option( 'woocommerce_stripe_giropay_settings' ); |
| 56 | + delete_option( 'woocommerce_stripe_ideal_settings' ); |
| 57 | + delete_option( 'woocommerce_stripe_klarna_settings' ); |
| 58 | + delete_option( 'woocommerce_stripe_link_settings' ); |
| 59 | + delete_option( 'woocommerce_stripe_multibanco_settings' ); |
| 60 | + delete_option( 'woocommerce_stripe_oxxo_settings' ); |
| 61 | + delete_option( 'woocommerce_stripe_p24_settings' ); |
| 62 | + delete_option( 'woocommerce_stripe_sepa_settings' ); |
| 63 | + delete_option( 'woocommerce_stripe_sepa_debit_settings' ); |
| 64 | + delete_option( 'woocommerce_stripe_sofort_settings' ); |
| 65 | + delete_option( 'woocommerce_stripe_wechat_pay_settings' ); |
| 66 | + |
| 67 | + delete_option( 'woocommerce_gateway_stripe_retention' ); |
| 68 | + delete_option( 'woocommerce_stripe_subscriptions_legacy_sepa_tokens_updated' ); |
| 69 | + |
| 70 | + delete_option( 'wc_stripe_elements_options' ); |
| 71 | + delete_option( 'wc_stripe_version' ); |
| 72 | + |
| 73 | + delete_option( 'wc_stripe_show_style_notice' ); |
19 | 74 | delete_option( 'wc_stripe_show_styles_notice' );
|
| 75 | + delete_option( 'wc_stripe_show_ssl_notice' ); |
20 | 76 | delete_option( 'wc_stripe_show_request_api_notice' );
|
21 | 77 | delete_option( 'wc_stripe_show_apple_pay_notice' );
|
22 |
| - delete_option( 'wc_stripe_show_ssl_notice' ); |
23 | 78 | delete_option( 'wc_stripe_show_keys_notice' );
|
| 79 | + delete_option( 'wc_stripe_show_3ds_notice' ); |
| 80 | + delete_option( 'wc_stripe_show_phpver_notice' ); |
| 81 | + delete_option( 'wc_stripe_show_wcver_notice' ); |
| 82 | + delete_option( 'wc_stripe_show_curl_notice' ); |
| 83 | + delete_option( 'wc_stripe_show_sca_notice' ); |
| 84 | + delete_option( 'wc_stripe_show_changed_keys_notice' ); |
| 85 | + delete_option( 'wc_stripe_show_customization_notice' ); |
| 86 | + delete_option( 'wc_stripe_show_payment_methods_notice' ); |
| 87 | + delete_option( 'wc_stripe_show_upe_payment_methods_notice' ); |
24 | 88 | delete_option( 'wc_stripe_show_alipay_notice' );
|
25 | 89 | delete_option( 'wc_stripe_show_bancontact_notice' );
|
26 |
| - delete_option( 'wc_stripe_show_bitcoin_notice' ); |
27 | 90 | delete_option( 'wc_stripe_show_eps_notice' );
|
28 | 91 | delete_option( 'wc_stripe_show_giropay_notice' );
|
29 | 92 | delete_option( 'wc_stripe_show_ideal_notice' );
|
30 | 93 | delete_option( 'wc_stripe_show_multibanco_notice' );
|
| 94 | + delete_option( 'wc_stripe_show_oxxo_notice' ); |
31 | 95 | delete_option( 'wc_stripe_show_p24_notice' );
|
32 | 96 | delete_option( 'wc_stripe_show_sepa_notice' );
|
33 | 97 | delete_option( 'wc_stripe_show_sofort_notice' );
|
34 |
| - delete_option( 'wc_stripe_version' ); |
35 |
| - delete_option( 'woocommerce_stripe_bancontact_settings' ); |
36 |
| - delete_option( 'woocommerce_stripe_alipay_settings' ); |
37 |
| - delete_option( 'woocommerce_stripe_bitcoin_settings' ); |
38 |
| - delete_option( 'woocommerce_stripe_ideal_settings' ); |
39 |
| - delete_option( 'woocommerce_stripe_p24_settings' ); |
40 |
| - delete_option( 'woocommerce_stripe_giropay_settings' ); |
41 |
| - delete_option( 'woocommerce_stripe_sepa_settings' ); |
42 |
| - delete_option( 'woocommerce_stripe_sofort_settings' ); |
43 |
| - delete_option( 'woocommerce_stripe_subscriptions_legacy_sepa_tokens_updated' ); |
| 98 | + |
| 99 | + // Webhook stats |
| 100 | + delete_option( 'wc_stripe_wh_monitor_began_at' ); |
| 101 | + delete_option( 'wc_stripe_wh_last_success_at' ); |
| 102 | + delete_option( 'wc_stripe_wh_last_failure_at' ); |
| 103 | + delete_option( 'wc_stripe_wh_last_error' ); |
| 104 | + delete_option( 'wc_stripe_wh_test_monitor_began_at' ); |
| 105 | + delete_option( 'wc_stripe_wh_test_last_success_at' ); |
| 106 | + delete_option( 'wc_stripe_wh_test_last_failure_at' ); |
| 107 | + delete_option( 'wc_stripe_wh_test_last_error' ); |
| 108 | + |
| 109 | + // OAuth connection stats |
| 110 | + delete_option( 'wc_stripe_oauth_updated_at' ); |
| 111 | + delete_option( 'wc_stripe_oauth_failed_attempts' ); |
| 112 | + delete_option( 'wc_stripe_oauth_last_failed_at' ); |
| 113 | + delete_option( 'wc_stripe_test_oauth_updated_at' ); |
| 114 | + delete_option( 'wc_stripe_test_oauth_failed_attempts' ); |
| 115 | + delete_option( 'wc_stripe_test_oauth_last_failed_at' ); |
| 116 | + |
| 117 | + // Feature flags |
| 118 | + delete_option( '_wcstripe_feature_upe' ); |
| 119 | + delete_option( 'upe_checkout_experience_accepted_payments' ); |
44 | 120 | }
|
0 commit comments