PluginProbe
ActivityPub / 1.0.8
ActivityPub v1.0.8
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
activitypub / integration / class-webfinger.php

class-webfinger.php in ActivityPub 1.0.8, at integration/class-webfinger.php

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