Skip to content

Commit fd6cb84

Browse files
committed
Fix compatibility with WebFinger and NodeInfo plugin
1 parent 12b6750 commit fd6cb84

File tree

8 files changed

+131
-79
lines changed

8 files changed

+131
-79
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
**Tags:** OStatus, fediverse, activitypub, activitystream
44
**Requires at least:** 4.7
55
**Tested up to:** 6.3
6-
**Stable tag:** 1.0.4
6+
**Stable tag:** 1.0.5
77
**Requires PHP:** 5.6
88
**License:** MIT
99
**License URI:** http://opensource.org/licenses/MIT
@@ -105,6 +105,10 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
105105

106106
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
107107

108+
### 1.0.5 ###
109+
110+
* Fixed: compatibility with WebFinger and NodeInfo plugin
111+
108112
### 1.0.4 ###
109113

110114
* Fixed: Constants were not loaded early enough, resulting in a race condition

activitypub.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: ActivityPub
44
* Plugin URI: https://github.com/pfefferle/wordpress-activitypub/
55
* Description: The ActivityPub protocol is a decentralized social networking protocol based upon the ActivityStreams 2.0 data format.
6-
* Version: 1.0.4
6+
* Version: 1.0.5
77
* Author: Matthias Pfefferle & Automattic
88
* Author URI: https://automattic.com/
99
* License: MIT
@@ -82,6 +82,12 @@ function plugin_init() {
8282
require_once $debug_file;
8383
Debug::init();
8484
}
85+
86+
require_once __DIR__ . '/integration/class-webfinger.php';
87+
Integration\Webfinger::init();
88+
89+
require_once __DIR__ . '/integration/class-nodeinfo.php';
90+
Integration\Nodeinfo::init();
8591
}
8692
\add_action( 'plugins_loaded', __NAMESPACE__ . '\plugin_init' );
8793

includes/rest/class-nodeinfo.php

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class Nodeinfo {
1818
*/
1919
public static function init() {
2020
self::register_routes();
21-
22-
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
23-
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
2421
}
2522

2623
/**
@@ -194,36 +191,4 @@ public static function discovery( $request ) {
194191

195192
return new \WP_REST_Response( $discovery, 200 );
196193
}
197-
198-
/**
199-
* Extend NodeInfo data
200-
*
201-
* @param array $nodeinfo NodeInfo data
202-
* @param string The NodeInfo Version
203-
*
204-
* @return array The extended array
205-
*/
206-
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
207-
if ( '2.0' === $version ) {
208-
$nodeinfo['protocols'][] = 'activitypub';
209-
} else {
210-
$nodeinfo['protocols']['inbound'][] = 'activitypub';
211-
$nodeinfo['protocols']['outbound'][] = 'activitypub';
212-
}
213-
214-
return $nodeinfo;
215-
}
216-
217-
/**
218-
* Extend NodeInfo2 data
219-
*
220-
* @param array $nodeinfo NodeInfo2 data
221-
*
222-
* @return array The extended array
223-
*/
224-
public static function add_nodeinfo2_discovery( $nodeinfo ) {
225-
$nodeinfo['protocols'][] = 'activitypub';
226-
227-
return $nodeinfo;
228-
}
229194
}

includes/rest/class-webfinger.php

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ class Webfinger {
2020
*/
2121
public static function init() {
2222
self::register_routes();
23-
24-
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
25-
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
2623
}
2724

2825
/**
@@ -81,44 +78,6 @@ public static function request_parameters() {
8178
return $params;
8279
}
8380

84-
/**
85-
* Add WebFinger discovery links
86-
*
87-
* @param array $array the jrd array
88-
* @param string $resource the WebFinger resource
89-
* @param WP_User $user the WordPress user
90-
*
91-
* @return array the jrd array
92-
*/
93-
public static function add_user_discovery( $array, $resource, $user ) {
94-
$user = User_Collection::get_by_id( $user->ID );
95-
96-
$array['links'][] = array(
97-
'rel' => 'self',
98-
'type' => 'application/activity+json',
99-
'href' => $user->get_url(),
100-
);
101-
102-
return $array;
103-
}
104-
105-
/**
106-
* Add WebFinger discovery links
107-
*
108-
* @param array $array the jrd array
109-
* @param string $resource the WebFinger resource
110-
* @param WP_User $user the WordPress user
111-
*
112-
* @return array the jrd array
113-
*/
114-
public static function add_pseudo_user_discovery( $array, $resource ) {
115-
if ( $array ) {
116-
return $array;
117-
}
118-
119-
return self::get_profile( $resource );
120-
}
121-
12281
/**
12382
* Get the WebFinger profile.
12483
*

integration/class-buddypress.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
<?php
22
namespace Activitypub\Integration;
33

4+
/**
5+
* Compatibility with the BuddyPress plugin
6+
*
7+
* @see https://buddypress.org/
8+
*/
49
class Buddypress {
10+
/**
11+
* Initialize the class, registering WordPress hooks
12+
*/
513
public static function init() {
614
\add_filter( 'activitypub_json_author_array', array( self::class, 'add_user_metadata' ), 11, 2 );
715
}

integration/class-nodeinfo.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
namespace Activitypub\Integration;
3+
4+
/**
5+
* Compatibility with the NodeInfo plugin
6+
*
7+
* @see https://wordpress.org/plugins/nodeinfo/
8+
*/
9+
class Nodeinfo {
10+
/**
11+
* Initialize the class, registering WordPress hooks
12+
*/
13+
public static function init() {
14+
\add_filter( 'nodeinfo_data', array( self::class, 'add_nodeinfo_discovery' ), 10, 2 );
15+
\add_filter( 'nodeinfo2_data', array( self::class, 'add_nodeinfo2_discovery' ), 10 );
16+
}
17+
18+
/**
19+
* Extend NodeInfo data
20+
*
21+
* @param array $nodeinfo NodeInfo data
22+
* @param string The NodeInfo Version
23+
*
24+
* @return array The extended array
25+
*/
26+
public static function add_nodeinfo_discovery( $nodeinfo, $version ) {
27+
if ( $version >= '2.0' ) {
28+
$nodeinfo['protocols'][] = 'activitypub';
29+
} else {
30+
$nodeinfo['protocols']['inbound'][] = 'activitypub';
31+
$nodeinfo['protocols']['outbound'][] = 'activitypub';
32+
}
33+
34+
return $nodeinfo;
35+
}
36+
37+
/**
38+
* Extend NodeInfo2 data
39+
*
40+
* @param array $nodeinfo NodeInfo2 data
41+
*
42+
* @return array The extended array
43+
*/
44+
public static function add_nodeinfo2_discovery( $nodeinfo ) {
45+
$nodeinfo['protocols'][] = 'activitypub';
46+
47+
return $nodeinfo;
48+
}
49+
}

integration/class-webfinger.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
namespace Activitypub\Integration;
3+
4+
use Activitypub\Collection\Users as User_Collection;
5+
6+
/**
7+
* Compatibility with the WebFinger plugin
8+
*
9+
* @see https://wordpress.org/plugins/webfinger/
10+
*/
11+
class Webfinger {
12+
/**
13+
* Initialize the class, registering WordPress hooks
14+
*/
15+
public static function init() {
16+
\add_filter( 'webfinger_user_data', array( self::class, 'add_user_discovery' ), 10, 3 );
17+
\add_filter( 'webfinger_data', array( self::class, 'add_pseudo_user_discovery' ), 99, 2 );
18+
}
19+
20+
/**
21+
* Add WebFinger discovery links
22+
*
23+
* @param array $array the jrd array
24+
* @param string $resource the WebFinger resource
25+
* @param WP_User $user the WordPress user
26+
*
27+
* @return array the jrd array
28+
*/
29+
public static function add_user_discovery( $array, $resource, $user ) {
30+
$user = User_Collection::get_by_id( $user->ID );
31+
32+
$array['links'][] = array(
33+
'rel' => 'self',
34+
'type' => 'application/activity+json',
35+
'href' => $user->get_url(),
36+
);
37+
38+
return $array;
39+
}
40+
41+
/**
42+
* Add WebFinger discovery links
43+
*
44+
* @param array $array the jrd array
45+
* @param string $resource the WebFinger resource
46+
* @param WP_User $user the WordPress user
47+
*
48+
* @return array the jrd array
49+
*/
50+
public static function add_pseudo_user_discovery( $array, $resource ) {
51+
if ( $array ) {
52+
return $array;
53+
}
54+
55+
return self::get_profile( $resource );
56+
}
57+
}

readme.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: automattic, pfefferle, mediaformat, mattwiebe, akirk, jeherve, nur
33
Tags: OStatus, fediverse, activitypub, activitystream
44
Requires at least: 4.7
55
Tested up to: 6.3
6-
Stable tag: 1.0.4
6+
Stable tag: 1.0.5
77
Requires PHP: 5.6
88
License: MIT
99
License URI: http://opensource.org/licenses/MIT
@@ -105,6 +105,10 @@ Where 'blog' is the path to the subdirectory at which your blog resides.
105105

106106
Project maintained on GitHub at [automattic/wordpress-activitypub](https://github.com/automattic/wordpress-activitypub).
107107

108+
= 1.0.5 =
109+
110+
* Fixed: compatibility with WebFinger and NodeInfo plugin
111+
108112
= 1.0.4 =
109113

110114
* Fixed: Constants were not loaded early enough, resulting in a race condition

0 commit comments

Comments
 (0)