Skip to content

Commit c1cbad1

Browse files
committed
Remove old payment methods transients on activation and update
1 parent ba2437a commit c1cbad1

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

includes/addons/class-wc-monei-addons-redirect-hooks.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@
2020
class WC_Monei_Addons_Redirect_Hooks {
2121

2222
private MoneiPaymentServices $moneiPaymentServices;
23+
private SubscriptionService $subscriptionService;
2324

24-
/**
25+
/**
2526
* Hooks on redirects.
2627
*/
2728
public function __construct() {

woocommerce-gateway-monei.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,45 @@
4242
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'cart_checkout_blocks', __FILE__, true );
4343
}
4444
} );
45+
/**
46+
* Remove transients for payment methods on activation
47+
*
48+
* @return void
49+
*/
50+
function delete_payment_methods_transients() {
51+
global $wpdb;
52+
53+
// Delete transients that match the pattern
54+
$wpdb->query(
55+
"DELETE FROM {$wpdb->options}
56+
WHERE option_name LIKE '_transient_payment_methods_%'
57+
OR option_name LIKE '_transient_timeout_payment_methods_%'"
58+
);
59+
}
60+
61+
/**
62+
* Remove transients for payment methods on update of the plugin
63+
*
64+
* @param $upgrader_object
65+
* @param $options
66+
* @return void
67+
*/
68+
function delete_payment_methods_transients_on_update($upgrader_object, $options) {
69+
if ($options['action'] == 'update' && $options['type'] == 'plugin') {
70+
if (isset($options['plugins'])) {
71+
foreach ($options['plugins'] as $plugin) {
72+
if ($plugin == plugin_basename(__FILE__)) {
73+
delete_payment_methods_transients();
74+
break;
75+
}
76+
}
77+
}
78+
}
79+
}
80+
81+
register_activation_hook(__FILE__, 'delete_payment_methods_transients');
82+
83+
add_action('upgrader_process_complete', 'delete_payment_methods_transients_on_update', 10, 2);
4584

4685
require_once 'class-woocommerce-gateway-monei.php';
4786
function WC_Monei() {

0 commit comments

Comments
 (0)