From 27107d0b025965a279e610dfc27db27283e2095e Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 18 Jun 2026 16:27:39 -0300 Subject: [PATCH 1/3] Remove paypal cron when all gateways are disconnected --- classes/controllers/FrmAppController.php | 8 +++-- paypal/helpers/FrmPayPalLiteConnectHelper.php | 1 + square/helpers/FrmSquareLiteConnectHelper.php | 1 + .../controllers/FrmTransLiteAppController.php | 29 +++++++++++++++++-- .../FrmTransLiteHooksController.php | 2 ++ stripe/helpers/FrmStrpLiteConnectHelper.php | 22 +------------- stripe/helpers/FrmTransLiteAppHelper.php | 18 ++++++++++++ 7 files changed, 55 insertions(+), 26 deletions(-) diff --git a/classes/controllers/FrmAppController.php b/classes/controllers/FrmAppController.php index aa4fbe7515..490e04ec0a 100644 --- a/classes/controllers/FrmAppController.php +++ b/classes/controllers/FrmAppController.php @@ -1330,14 +1330,18 @@ public static function handle_activation() { /** * The payment cron is unscheduled when Formidable is deactivated. - * We need to add it back again on activation if Stripe is configured. + * We need to add it back again on activation if any payment gateway is configured. * * @since 6.5 * * @return void */ private static function maybe_activate_payment_cron() { - if ( ! FrmStrpLiteConnectHelper::stripe_connect_is_setup() ) { + $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup(); + $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup(); + $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup(); + + if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) { return; } diff --git a/paypal/helpers/FrmPayPalLiteConnectHelper.php b/paypal/helpers/FrmPayPalLiteConnectHelper.php index 3951d30ba0..649c3d5972 100644 --- a/paypal/helpers/FrmPayPalLiteConnectHelper.php +++ b/paypal/helpers/FrmPayPalLiteConnectHelper.php @@ -938,6 +938,7 @@ public static function process_event( $event_id ) { public static function handle_disconnect() { self::disconnect(); self::reset_paypal_api_integration(); + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'paypal', self::get_mode_value_from_post() ); wp_send_json_success(); } diff --git a/square/helpers/FrmSquareLiteConnectHelper.php b/square/helpers/FrmSquareLiteConnectHelper.php index 6ed12ec2fe..3072263c3d 100644 --- a/square/helpers/FrmSquareLiteConnectHelper.php +++ b/square/helpers/FrmSquareLiteConnectHelper.php @@ -707,6 +707,7 @@ public static function cancel_subscription( $subscription_id ) { public static function handle_disconnect() { self::disconnect(); self::reset_square_api_integration(); + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'square', self::get_mode_value_from_post() ); wp_send_json_success(); } diff --git a/stripe/controllers/FrmTransLiteAppController.php b/stripe/controllers/FrmTransLiteAppController.php index b8f0e495b2..deadf0c34a 100755 --- a/stripe/controllers/FrmTransLiteAppController.php +++ b/stripe/controllers/FrmTransLiteAppController.php @@ -45,12 +45,23 @@ public static function maybe_schedule_cron() { } /** - * Remove the cron when the plugin is deactivated. + * Remove the payment cron when all gateways are disconnected. + * + * @since x.x + * + * @param string $gateway 'stripe', 'square', or 'paypal'. + * @param string $mode 'test' or 'live'. * * @return void */ - public static function remove_cron() { - wp_clear_scheduled_hook( 'frm_payment_cron' ); + public static function maybe_remove_payment_cron( $gateway, $mode ) { + $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup(); + $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup(); + $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup(); + + if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) { + wp_clear_scheduled_hook( 'frm_payment_cron' ); + } } /** @@ -231,4 +242,16 @@ public static function hide_gateway_fields_in_builder() { ' ); } + + /** + * Remove the cron when the plugin is deactivated. + * + * @deprecated x.x + * + * @return void + */ + public static function remove_cron() { + _deprecated_function( __METHOD__, 'x.x' ); + wp_clear_scheduled_hook( 'frm_payment_cron' ); + } } diff --git a/stripe/controllers/FrmTransLiteHooksController.php b/stripe/controllers/FrmTransLiteHooksController.php index d3f502387d..e37e769827 100755 --- a/stripe/controllers/FrmTransLiteHooksController.php +++ b/stripe/controllers/FrmTransLiteHooksController.php @@ -36,6 +36,8 @@ public static function load_hooks() { * @return void */ public static function load_admin_hooks() { + add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron' ); + if ( class_exists( 'FrmTransHooksController', false ) ) { add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' ); diff --git a/stripe/helpers/FrmStrpLiteConnectHelper.php b/stripe/helpers/FrmStrpLiteConnectHelper.php index ef6cdaf5fe..48239f442d 100644 --- a/stripe/helpers/FrmStrpLiteConnectHelper.php +++ b/stripe/helpers/FrmStrpLiteConnectHelper.php @@ -263,7 +263,7 @@ private static function get_url_to_connect_server() { private static function handle_disconnect() { self::disconnect(); self::reset_stripe_connect_integration(); - self::maybe_unschedule_crons(); + FrmTransLiteAppHelper::trigger_gateway_disconnected_hook( 'stripe', self::get_mode_value_from_post() ); wp_send_json_success(); } @@ -290,26 +290,6 @@ private static function disconnect() { return self::post_with_authenticated_body( 'disconnect', $additional_body ); } - /** - * Stop the payment cron once all Stripe connections have been disconnected. - * - * @since 6.5 - * - * @return void - */ - private static function maybe_unschedule_crons() { - if ( self::at_least_one_mode_is_setup() ) { - // Don't unschedule if a mode is still on. - return; - } - - $event = 'frm_payment_cron'; - $timestamp = wp_next_scheduled( $event ); - - if ( false !== $timestamp ) { - wp_unschedule_event( $timestamp, $event ); - } - } /** * @since 6.5 diff --git a/stripe/helpers/FrmTransLiteAppHelper.php b/stripe/helpers/FrmTransLiteAppHelper.php index b7c12c35a1..75716ad108 100755 --- a/stripe/helpers/FrmTransLiteAppHelper.php +++ b/stripe/helpers/FrmTransLiteAppHelper.php @@ -641,4 +641,22 @@ private static function sort_gateways( $gateways, $order ) { return $sorted + $gateways; } + + /** + * @since x.x + * + * @param string $gateway 'stripe', 'square', or 'paypal'. + * @param string $mode 'test' or 'live' + * + * @return void + */ + public static function trigger_gateway_disconnected_hook( $gateway, $mode ) { + /** + * @since x.x + * + * @param string $gateway 'stripe', 'square', or 'paypal'. + * @param string $mode 'test' or 'live'. + */ + do_action( 'frm_disconnected_gateway', $gateway, $mode ); + } } From 149524cf19d8c71483fb80af4ba1f452344df3c6 Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 18 Jun 2026 16:28:57 -0300 Subject: [PATCH 2/3] Run php cs fixer --- stripe/controllers/FrmTransLiteHooksController.php | 2 +- stripe/helpers/FrmStrpLiteConnectHelper.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/stripe/controllers/FrmTransLiteHooksController.php b/stripe/controllers/FrmTransLiteHooksController.php index e37e769827..dc23051543 100755 --- a/stripe/controllers/FrmTransLiteHooksController.php +++ b/stripe/controllers/FrmTransLiteHooksController.php @@ -36,7 +36,7 @@ public static function load_hooks() { * @return void */ public static function load_admin_hooks() { - add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron' ); + add_action( 'frm_disconnected_gateway', 'FrmTransLiteAppController::maybe_remove_payment_cron' ); if ( class_exists( 'FrmTransHooksController', false ) ) { add_action( 'frm_pay_show_square_options', 'FrmTransLiteAppController::add_repeat_cadence_value' ); diff --git a/stripe/helpers/FrmStrpLiteConnectHelper.php b/stripe/helpers/FrmStrpLiteConnectHelper.php index 48239f442d..6f7eef983c 100644 --- a/stripe/helpers/FrmStrpLiteConnectHelper.php +++ b/stripe/helpers/FrmStrpLiteConnectHelper.php @@ -290,7 +290,6 @@ private static function disconnect() { return self::post_with_authenticated_body( 'disconnect', $additional_body ); } - /** * @since 6.5 * From cbd82bd811e8468b12b1f9aa9dd65abe0f0bbb1b Mon Sep 17 00:00:00 2001 From: Mike Letellier Date: Thu, 18 Jun 2026 16:30:53 -0300 Subject: [PATCH 3/3] Use fullstop for comment --- stripe/helpers/FrmTransLiteAppHelper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stripe/helpers/FrmTransLiteAppHelper.php b/stripe/helpers/FrmTransLiteAppHelper.php index 75716ad108..8150e08a7a 100755 --- a/stripe/helpers/FrmTransLiteAppHelper.php +++ b/stripe/helpers/FrmTransLiteAppHelper.php @@ -646,7 +646,7 @@ private static function sort_gateways( $gateways, $order ) { * @since x.x * * @param string $gateway 'stripe', 'square', or 'paypal'. - * @param string $mode 'test' or 'live' + * @param string $mode 'test' or 'live'. * * @return void */