diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php index b6b0a64..75f7ff6 100644 --- a/includes/class-webfinger.php +++ b/includes/class-webfinger.php @@ -41,9 +41,14 @@ class Webfinger { * @return string|WP_Error The URL or WP_Error */ public static function resolve( $resource ) { + if ( ! $resource ) { + return null; + } + if ( ! preg_match( '/^@?' . ACTIVITYPUB_USERNAME_REGEXP . '$/i', $resource, $m ) ) { return null; } + $transient_key = 'activitypub_resolve_' . ltrim( $resource, '@' ); $link = \get_transient( $transient_key ); diff --git a/includes/rest/class-inbox.php b/includes/rest/class-inbox.php index 2cedf15..15fb4b2 100644 --- a/includes/rest/class-inbox.php +++ b/includes/rest/class-inbox.php @@ -236,8 +236,12 @@ class Inbox { $params['actor'] = array( 'required' => true, 'sanitize_callback' => function( $param, $request, $key ) { - if ( ! \is_string( $param ) ) { - $param = $param['id']; + if ( \is_array( $param ) ) { + if ( isset( $param['id'] ) ) { + $param = $param['id']; + } else { + $param = $param['url']; + } } return \esc_url_raw( $param ); }, diff --git a/integration/class-webfinger.php b/integration/class-webfinger.php index 177b417..c9dd565 100644 --- a/integration/class-webfinger.php +++ b/integration/class-webfinger.php @@ -30,6 +30,10 @@ class Webfinger { public static function add_user_discovery( $array, $resource, $user ) { $user = User_Collection::get_by_id( $user->ID ); + if ( ! $user || is_wp_error( $user ) ) { + return $array; + } + $array['links'][] = array( 'rel' => 'self', 'type' => 'application/activity+json',