PluginProbe
ActivityPub / 1.3.0
ActivityPub v1.3.0
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.3.0, at integration/class-webfinger.php

63 lines 1.5 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 if ( ! $user || is_wp_error( $user ) ) {
34 return $array;
35 }
36
37 $array['links'][] = array(
38 'rel' => 'self',
39 'type' => 'application/activity+json',
40 'href' => $user->get_url(),
41 );
42
43 return $array;
44 }
45
46 /**
47 * Add WebFinger discovery links
48 *
49 * @param array $array the jrd array
50 * @param string $resource the WebFinger resource
51 * @param WP_User $user the WordPress user
52 *
53 * @return array the jrd array
54 */
55 public static function add_pseudo_user_discovery( $array, $resource ) {
56 if ( $array ) {
57 return $array;
58 }
59
60 return Webfinger_Rest::get_profile( $resource );
61 }
62 }
63