@@ -27,23 +27,17 @@ class Scheduler {
27
27
*
28
28
* @var array
29
29
*/
30
- private static $ batch_callbacks = array ();
30
+ private static $ batch_callbacks = array (
31
+ 'activitypub_send_activity ' => array ( Dispatcher::class, 'send_to_followers ' ),
32
+ 'activitypub_retry_activity ' => array ( Dispatcher::class, 'retry_send_to_followers ' ),
33
+ );
31
34
32
35
/**
33
36
* Initialize the class, registering WordPress hooks.
34
37
*/
35
38
public static function init () {
36
39
self ::register_schedulers ();
37
40
38
- self ::$ batch_callbacks = array (
39
- 'activitypub_send_activity ' => array ( Dispatcher::class, 'send_to_followers ' ),
40
- 'activitypub_retry_activity ' => array ( Dispatcher::class, 'retry_send_to_followers ' ),
41
- 'activitypub_migrate_from_0_17 ' => array ( Migration::class, 'migrate_from_0_17 ' ),
42
- 'activitypub_update_comment_counts ' => array ( Migration::class, 'update_comment_counts ' ),
43
- 'activitypub_create_post_outbox_items ' => array ( Migration::class, 'create_post_outbox_items ' ),
44
- 'activitypub_create_comment_outbox_items ' => array ( Migration::class, 'create_comment_outbox_items ' ),
45
- );
46
-
47
41
// Follower Cleanups.
48
42
\add_action ( 'activitypub_update_remote_actors ' , array ( self ::class, 'update_remote_actors ' ) );
49
43
\add_action ( 'activitypub_cleanup_remote_actors ' , array ( self ::class, 'cleanup_remote_actors ' ) );
@@ -52,10 +46,6 @@ public static function init() {
52
46
\add_action ( 'activitypub_async_batch ' , array ( self ::class, 'async_batch ' ), 10 , 99 );
53
47
\add_action ( 'activitypub_send_activity ' , array ( self ::class, 'async_batch ' ), 10 , 3 );
54
48
\add_action ( 'activitypub_retry_activity ' , array ( self ::class, 'async_batch ' ), 10 , 3 );
55
- \add_action ( 'activitypub_migrate_from_0_17 ' , array ( self ::class, 'async_batch ' ) );
56
- \add_action ( 'activitypub_update_comment_counts ' , array ( self ::class, 'async_batch ' ), 10 , 2 );
57
- \add_action ( 'activitypub_create_post_outbox_items ' , array ( self ::class, 'async_batch ' ), 10 , 2 );
58
- \add_action ( 'activitypub_create_comment_outbox_items ' , array ( self ::class, 'async_batch ' ), 10 , 2 );
59
49
\add_action ( 'activitypub_reprocess_outbox ' , array ( self ::class, 'reprocess_outbox ' ) );
60
50
\add_action ( 'activitypub_outbox_purge ' , array ( self ::class, 'purge_outbox ' ) );
61
51
@@ -81,6 +71,28 @@ public static function register_schedulers() {
81
71
do_action ( 'activitypub_register_schedulers ' );
82
72
}
83
73
74
+ /**
75
+ * Register a batch callback for async processing.
76
+ *
77
+ * @param string $hook The cron event hook name.
78
+ * @param callable $callback The callback to execute.
79
+ */
80
+ public static function register_async_batch_callback ( $ hook , $ callback ) {
81
+ if ( \did_action ( 'init ' ) && ! \doing_action ( 'init ' ) ) {
82
+ \_doing_it_wrong ( __METHOD__ , 'Async batch callbacks should be registered before or during the init action. ' , '5.2.0 ' );
83
+ return ;
84
+ }
85
+
86
+ if ( ! \is_callable ( $ callback ) ) {
87
+ return ;
88
+ }
89
+
90
+ self ::$ batch_callbacks [ $ hook ] = $ callback ;
91
+
92
+ // Register the WordPress action hook to trigger async_batch.
93
+ \add_action ( $ hook , array ( self ::class, 'async_batch ' ), 10 , 99 );
94
+ }
95
+
84
96
/**
85
97
* Schedule all ActivityPub schedules.
86
98
*/
0 commit comments