@@ -327,57 +327,67 @@ function is_post_disabled( $post ) {
327
327
}
328
328
329
329
/**
330
- * This function checks if a user is disabled for ActivityPub.
330
+ * This function checks if a user is enabled for ActivityPub.
331
331
*
332
332
* @param int $user_id The user ID.
333
- *
334
- * @return boolean True if the user is disabled, false otherwise.
333
+ * @return boolean True if the user is enabled, false otherwise.
335
334
*/
336
- function is_user_disabled ( $ user_id ) {
337
- $ disabled = false ;
338
-
335
+ function user_can_activitypub ( $ user_id ) {
339
336
switch ( $ user_id ) {
340
- // if the user is the application user, it's always enabled.
341
- case \Activitypub \Collection \Actors::APPLICATION_USER_ID :
342
- $ disabled = false ;
337
+ case Actors::APPLICATION_USER_ID :
338
+ $ enabled = true ; // Application user is always enabled.
343
339
break ;
344
- // if the user is the blog user, it's only enabled in single-user mode.
345
- case \Activitypub \Collection \Actors::BLOG_USER_ID :
346
- if ( is_user_type_disabled ( 'blog ' ) ) {
347
- $ disabled = true ;
348
- break ;
349
- }
350
340
351
- $ disabled = false ;
341
+ case Actors::BLOG_USER_ID :
342
+ $ enabled = ! is_user_type_disabled ( 'blog ' );
352
343
break ;
353
- // if the user is any other user, it's enabled if it can publish posts.
344
+
354
345
default :
355
346
if ( ! \get_user_by ( 'id ' , $ user_id ) ) {
356
- $ disabled = true ;
347
+ $ enabled = false ;
357
348
break ;
358
349
}
359
350
360
351
if ( is_user_type_disabled ( 'user ' ) ) {
361
- $ disabled = true ;
362
- break ;
363
- }
364
-
365
- if ( ! \user_can ( $ user_id , 'activitypub ' ) ) {
366
- $ disabled = true ;
352
+ $ enabled = false ;
367
353
break ;
368
354
}
369
355
370
- $ disabled = false ;
371
- break ;
356
+ $ enabled = \user_can ( $ user_id , 'activitypub ' );
372
357
}
373
358
374
359
/**
375
360
* Allow plugins to disable users for ActivityPub.
376
361
*
362
+ * @deprecated unreleased Use the `activitypub_user_can_activitypub` filter instead.
363
+ *
377
364
* @param boolean $disabled True if the user is disabled, false otherwise.
378
- * @param int $user_id The User- ID.
365
+ * @param int $user_id The user ID.
379
366
*/
380
- return apply_filters ( 'activitypub_is_user_disabled ' , $ disabled , $ user_id );
367
+ $ enabled = ! \apply_filters_deprecated ( 'activitypub_is_user_disabled ' , array ( ! $ enabled , $ user_id ), 'unreleased ' , 'activitypub_user_can_activitypub ' );
368
+
369
+ /**
370
+ * Allow plugins to enable/disable users for ActivityPub.
371
+ *
372
+ * @param boolean $enabled True if the user is enabled, false otherwise.
373
+ * @param int $user_id The user ID.
374
+ */
375
+ return apply_filters ( 'activitypub_user_can_activitypub ' , $ enabled , $ user_id );
376
+ }
377
+
378
+ /**
379
+ * This function checks if a user is disabled for ActivityPub.
380
+ *
381
+ * @deprecated unreleased Use the `user_can_activitypub` function instead.
382
+ *
383
+ * @param int $user_id The user ID.
384
+ *
385
+ * @return boolean True if the user is disabled, false otherwise.
386
+ */
387
+ function is_user_disabled ( $ user_id ) {
388
+ _deprecated_function ( __FUNCTION__ , 'unreleased ' , 'user_can_activitypub ' );
389
+
390
+ return ! user_can_activitypub ( $ user_id );
381
391
}
382
392
383
393
/**
@@ -615,7 +625,7 @@ function get_active_users( $duration = 1 ) {
615
625
}
616
626
617
627
// If blog user is disabled.
618
- if ( is_user_disabled ( Actors::BLOG_USER_ID ) ) {
628
+ if ( ! user_can_activitypub ( Actors::BLOG_USER_ID ) ) {
619
629
return (int ) $ count ;
620
630
}
621
631
@@ -647,7 +657,7 @@ function get_total_users() {
647
657
}
648
658
649
659
// If blog user is disabled.
650
- if ( is_user_disabled ( Actors::BLOG_USER_ID ) ) {
660
+ if ( ! user_can_activitypub ( Actors::BLOG_USER_ID ) ) {
651
661
return (int ) $ users ;
652
662
}
653
663
@@ -1485,11 +1495,11 @@ function add_to_outbox( $data, $activity_type = null, $user_id = 0, $content_vis
1485
1495
}
1486
1496
1487
1497
// If the user is disabled, fall back to the blog user when available.
1488
- if ( is_user_disabled ( $ user_id ) ) {
1489
- if ( is_user_disabled ( Actors::BLOG_USER_ID ) ) {
1490
- return false ;
1491
- } else {
1498
+ if ( ! user_can_activitypub ( $ user_id ) ) {
1499
+ if ( user_can_activitypub ( Actors::BLOG_USER_ID ) ) {
1492
1500
$ user_id = Actors::BLOG_USER_ID ;
1501
+ } else {
1502
+ return false ;
1493
1503
}
1494
1504
}
1495
1505
0 commit comments