Commit 3fe480c7545 for woocommerce
commit 3fe480c75458d994e817ac693db125916544b274
Author: Vladimir Reznichenko <kalessil@gmail.com>
Date: Thu Jun 18 14:10:28 2026 +0200
[dev] Audit Action Scheduler APIs usage (#65831)
As the release includes several of my PRs, Claude have built good context on Action Scheduler internals.
I asked it to audit how WooCommerce uses it's APIs and flag anything what needs attention.
From the reported list, two items has been addressed:
- re-scheduling woocommerce_cleanup_sessions action was flagged as "can be skipped if rescheduled while running" (edge-case)
- scheduling woocommerce_tracker_send_event_wrapper action can potentially be running constantly (edge-case)
diff --git a/plugins/woocommerce/changelog/dev-actions-scheduler-api-usage-audit b/plugins/woocommerce/changelog/dev-actions-scheduler-api-usage-audit
new file mode 100644
index 00000000000..45084497796
--- /dev/null
+++ b/plugins/woocommerce/changelog/dev-actions-scheduler-api-usage-audit
@@ -0,0 +1,4 @@
+Significance: patch
+Type: dev
+
+Audit Action Scheduler APIs usage.
diff --git a/plugins/woocommerce/includes/class-woocommerce.php b/plugins/woocommerce/includes/class-woocommerce.php
index e22d316e314..1ffa2257f36 100644
--- a/plugins/woocommerce/includes/class-woocommerce.php
+++ b/plugins/woocommerce/includes/class-woocommerce.php
@@ -1720,11 +1720,7 @@ final class WooCommerce {
as_schedule_recurring_action( $tomorrow_3am, DAY_IN_SECONDS, 'woocommerce_cleanup_logs', array(), 'woocommerce', true );
- $next_run_timestamp = as_next_scheduled_action( 'woocommerce_cleanup_sessions', array(), 'woocommerce' );
- if ( $next_run_timestamp !== $tomorrow_6am ) {
- as_unschedule_all_actions( 'woocommerce_cleanup_sessions' );
- as_schedule_recurring_action( $tomorrow_6am, 12 * HOUR_IN_SECONDS, 'woocommerce_cleanup_sessions', array(), 'woocommerce', true );
- }
+ as_schedule_recurring_action( $tomorrow_6am, 12 * HOUR_IN_SECONDS, 'woocommerce_cleanup_sessions', array(), 'woocommerce', true );
as_schedule_recurring_action( $tomorrow_6am, 15 * DAY_IN_SECONDS, 'woocommerce_geoip_updater', array(), 'woocommerce', true );
@@ -1773,10 +1769,13 @@ final class WooCommerce {
* How frequent to schedule the tracker send event.
*
* @since 2.3.0
+ * @param string $recurrence Recurrence as per wp_get_schedules.
*/
$tracker_recurrence = apply_filters( 'woocommerce_tracker_event_recurrence', 'daily' );
+ $tracker_recurrence = is_string( $tracker_recurrence ) ? $tracker_recurrence : 'daily';
$core_internals = wp_get_schedules();
- as_schedule_recurring_action( time() + 10, $core_internals[ $tracker_recurrence ]['interval'], 'woocommerce_tracker_send_event_wrapper', array(), 'woocommerce', true );
+ $interval = $core_internals[ $tracker_recurrence ]['interval'] ?? DAY_IN_SECONDS;
+ as_schedule_recurring_action( time() + 10, $interval, 'woocommerce_tracker_send_event_wrapper', array(), 'woocommerce', true );
}
/**