File tree Expand file tree Collapse file tree 5 files changed +46
-5
lines changed Expand file tree Collapse file tree 5 files changed +46
-5
lines changed Original file line number Diff line number Diff line change
1
+ Significance: patch
2
+ Type: fixed
3
+
4
+ Posts now only fall back to the blog user when blog mode is enabled and no valid author exists, ensuring content negotiation only runs if an Actor is available.
Original file line number Diff line number Diff line change @@ -1300,12 +1300,24 @@ function get_content_warning( $post_id ) {
1300
1300
/**
1301
1301
* Get the ActivityPub ID of a User by the WordPress User ID.
1302
1302
*
1303
+ * Fall back to blog user if in blog mode or if user is not found.
1304
+ *
1303
1305
* @param int $id The WordPress User ID.
1304
1306
*
1305
- * @return string The ActivityPub ID (a URL) of the User.
1307
+ * @return string|false The ActivityPub ID (a URL) of the User or false if not found .
1306
1308
*/
1307
1309
function get_user_id ( $ id ) {
1308
- $ user = Actors::get_by_id ( $ id );
1310
+ $ mode = \get_option ( 'activitypub_actor_mode ' , 'default ' );
1311
+
1312
+ if ( ACTIVITYPUB_BLOG_MODE === $ mode ) {
1313
+ $ user = Actors::get_by_id ( Actors::BLOG_USER_ID );
1314
+ } else {
1315
+ $ user = Actors::get_by_id ( $ id );
1316
+
1317
+ if ( \is_wp_error ( $ user ) ) {
1318
+ $ user = Actors::get_by_id ( Actors::BLOG_USER_ID );
1319
+ }
1320
+ }
1309
1321
1310
1322
if ( \is_wp_error ( $ user ) ) {
1311
1323
return false ;
Original file line number Diff line number Diff line change 11
11
use Activitypub \Comment as Comment_Helper ;
12
12
use Activitypub \Http ;
13
13
14
+ use function Activitypub \get_user_id ;
14
15
use function Activitypub \is_post_disabled ;
15
16
use function Activitypub \user_can_activitypub ;
16
17
@@ -90,7 +91,7 @@ public static function get_transformer( $data ) {
90
91
case 'WP_Post ' :
91
92
if ( 'attachment ' === $ data ->post_type && ! is_post_disabled ( $ data ) ) {
92
93
return new Attachment ( $ data );
93
- } elseif ( ! is_post_disabled ( $ data ) ) {
94
+ } elseif ( ! is_post_disabled ( $ data ) && get_user_id ( $ data -> post_author ) ) {
94
95
return new Post ( $ data );
95
96
}
96
97
break ;
Original file line number Diff line number Diff line change @@ -712,6 +712,17 @@ public function test_get_user_id() {
712
712
$ user ->add_cap ( 'activitypub ' );
713
713
714
714
$ this ->assertIsString ( \Activitypub \get_user_id ( $ user ->ID ) );
715
+
716
+ \add_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_MODE );
717
+
718
+ $ this ->assertIsString ( \Activitypub \get_user_id ( $ user ->ID ) );
719
+
720
+ $ user ->remove_cap ( 'activitypub ' );
721
+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_BLOG_MODE );
722
+ $ this ->assertIsString ( \Activitypub \get_user_id ( $ user ->ID ) );
723
+
724
+ \update_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_MODE );
725
+ $ this ->assertFalse ( \Activitypub \get_user_id ( $ user ->ID ) );
715
726
}
716
727
717
728
/**
Original file line number Diff line number Diff line change 13
13
use Activitypub \Transformer \Factory ;
14
14
use Activitypub \Transformer \Json ;
15
15
use Activitypub \Transformer \Post ;
16
- use WP_UnitTestCase ;
17
16
18
17
/**
19
18
* Test class for Transformer Factory.
20
19
*
21
20
* @coversDefaultClass \Activitypub\Transformer\Factory
22
21
*/
23
- class Test_Factory extends WP_UnitTestCase {
22
+ class Test_Factory extends \ WP_UnitTestCase {
24
23
/**
25
24
* Test post ID.
26
25
*
@@ -113,6 +112,20 @@ public function test_get_transformer_post() {
113
112
$ post = get_post ( self ::$ post_id );
114
113
$ transformer = Factory::get_transformer ( $ post );
115
114
115
+ $ this ->assertInstanceOf ( \WP_Error::class, $ transformer );
116
+
117
+ \add_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_AND_BLOG_MODE );
118
+
119
+ $ post = get_post ( self ::$ post_id );
120
+ $ transformer = Factory::get_transformer ( $ post );
121
+
122
+ $ this ->assertInstanceOf ( Post::class, $ transformer );
123
+
124
+ \add_option ( 'activitypub_actor_mode ' , ACTIVITYPUB_ACTOR_MODE );
125
+
126
+ $ post = get_post ( self ::$ post_id );
127
+ $ transformer = Factory::get_transformer ( $ post );
128
+
116
129
$ this ->assertInstanceOf ( Post::class, $ transformer );
117
130
}
118
131
You can’t perform that action at this time.
0 commit comments