Skip to content

Commit 559b1c0

Browse files
committed
feat: filter for ActionScheduler dispatch
1 parent 83a455c commit 559b1c0

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

includes/data-events/class-data-events.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public static function init() {
139139
* @return bool
140140
*/
141141
private static function use_action_scheduler() {
142-
return defined( 'NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER' ) && NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER;
142+
$use = defined( 'NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER' ) && NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER;
143+
return apply_filters( 'newspack_data_events_use_action_scheduler_dispatch', $use );
143144
}
144145

145146
/**

tests/unit-tests/data-events.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,8 @@ public function test_dispatch_via_action_scheduler() {
525525
$this->markTestSkipped( 'ActionScheduler not available.' );
526526
}
527527

528-
// Enable AS dispatch via constant (off by default).
529-
if ( ! defined( 'NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER' ) ) {
530-
define( 'NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER', true );
531-
} elseif ( ! NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER ) {
532-
$this->markTestSkipped( 'NEWSPACK_DATA_EVENTS_ACTIONSCHEDULER constant is false and cannot be redefined.' );
533-
}
528+
// Enable AS dispatch via filter.
529+
add_filter( 'newspack_data_events_use_action_scheduler_dispatch', '__return_true' );
534530

535531
$action_name = 'test_as_dispatch';
536532
Data_Events::register_action( $action_name );
@@ -559,6 +555,8 @@ public function test_dispatch_via_action_scheduler() {
559555
'ARRAY_A'
560556
);
561557
$this->assertNotEmpty( $pending, 'AS dispatch should schedule pending actions.' );
558+
559+
remove_filter( 'newspack_data_events_use_action_scheduler_dispatch', '__return_true' );
562560
}
563561

564562
/**

0 commit comments

Comments
 (0)