| @@ -44,14 +44,25 @@ | ||
| 44 | 44 | } |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
| 48 | - * Remove the cron when the plugin is deactivated. | |
| 48 | + * Remove the payment cron when all gateways are disconnected. | |
| 49 | 49 | * |
| 50 | + * @since 6.32.1 | |
| 51 | + * | |
| 52 | + * @param string $gateway 'stripe', 'square', or 'paypal'. | |
| 53 | + * @param string $mode 'test' or 'live'. | |
| 54 | + * | |
| 50 | 55 | * @return void |
| 51 | 56 | */ |
| 52 | - public static function remove_cron() { | |
| 53 | - wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 57 | + public static function maybe_remove_payment_cron( $gateway, $mode ) { | |
| 58 | + $stripe_connected = FrmStrpLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 59 | + $square_connected = FrmSquareLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 60 | + $paypal_connected = FrmPayPalLiteConnectHelper::at_least_one_mode_is_setup(); | |
| 61 | + | |
| 62 | + if ( ! $stripe_connected && ! $square_connected && ! $paypal_connected ) { | |
| 63 | + wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 64 | + } | |
| 54 | 65 | } |
| 55 | 66 | |
| 56 | 67 | /** |
| 57 | 68 | * Process overdue subscriptions. |
| @@ -61,10 +72,15 @@ | ||
| 61 | 72 | public static function run_payment_cron() { |
| 62 | 73 | $frm_sub = new FrmTransLiteSubscription(); |
| 63 | 74 | $frm_payment = new FrmTransLitePayment(); |
| 64 | 75 | $overdue_subscriptions = $frm_sub->get_overdue_subscriptions(); |
| 65 | - FrmTransLiteLog::log_message( 'Stripe Cron Message', count( $overdue_subscriptions ) . ' subscriptions found to be processed.', false ); | |
| 66 | 76 | |
| 77 | + if ( ! $overdue_subscriptions && ! $frm_sub->get_active_subscriptions() ) { | |
| 78 | + return; | |
| 79 | + } | |
| 80 | + | |
| 81 | + FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', count( $overdue_subscriptions ) . ' subscriptions found to be processed.', false ); | |
| 82 | + | |
| 67 | 83 | foreach ( $overdue_subscriptions as $sub ) { |
| 68 | 84 | $last_payment = $frm_payment->get_one_by( $sub->id, 'sub_id' ); |
| 69 | 85 | |
| 70 | 86 | if ( ! $last_payment ) { |
| @@ -111,9 +127,9 @@ | ||
| 111 | 127 | $log_message .= 'on payment #' . $last_payment->id; |
| 112 | 128 | } |
| 113 | 129 | }//end if |
| 114 | 130 | |
| 115 | - FrmTransLiteLog::log_message( 'Stripe Cron Message', $log_message ); | |
| 131 | + FrmTransLiteLog::log_message( 'Overdue Subscription Cron Message', $log_message ); | |
| 116 | 132 | |
| 117 | 133 | self::maybe_trigger_changes( |
| 118 | 134 | array( |
| 119 | 135 | 'status' => $status, |
| @@ -224,6 +240,18 @@ | ||
| 224 | 240 | #frm_builder_page li[data-ftype="gateway"] { display: none; } |
| 225 | 241 | .frm_field_box:has(li[data-ftype="gateway"]:only-child) { display: none; } |
| 226 | 242 | ' |
| 227 | 243 | ); |
| 244 | + } | |
| 245 | + | |
| 246 | + /** | |
| 247 | + * Remove the cron when the plugin is deactivated. | |
| 248 | + * | |
| 249 | + * @deprecated 6.32.1 | |
| 250 | + * | |
| 251 | + * @return void | |
| 252 | + */ | |
| 253 | + public static function remove_cron() { | |
| 254 | + _deprecated_function( __METHOD__, '6.32.1' ); | |
| 255 | + wp_clear_scheduled_hook( 'frm_payment_cron' ); | |
| 228 | 256 | } |
| 229 | 257 | } |