Skip to content

Commit 02678ee

Browse files
committed
fix some WebFinger issues
1 parent 3d1bf1b commit 02678ee

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

includes/rest/class-webfinger.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,28 @@ public static function webfinger( $request ) {
5555
*/
5656
\do_action( 'activitypub_rest_webfinger_pre' );
5757

58+
$code = 200;
59+
5860
$resource = $request->get_param( 'resource' );
5961
$response = self::get_profile( $resource );
6062

61-
$response = new WP_REST_Response( $response, 200 );
62-
$response->header( 'Access-Control-Allow-Origin', '*' );
63-
$response->header( 'Content-Type', 'application/jrd+json; charset=' . get_option( 'blog_charset' ) );
63+
if ( \is_wp_error( $response ) ) {
64+
$code = 400;
65+
$error_data = $response->get_error_data();
66+
67+
if ( isset( $error_data['status'] ) ) {
68+
$code = $error_data['status'];
69+
}
70+
}
6471

65-
return $response;
72+
return new WP_REST_Response(
73+
$response,
74+
$code,
75+
array(
76+
'Access-Control-Allow-Origin' => '*',
77+
'Content-Type' => 'application/jrd+json; charset=' . get_option( 'blog_charset' ),
78+
)
79+
);
6680
}
6781

6882
/**
@@ -92,7 +106,7 @@ public static function request_parameters() {
92106
public static function get_profile( $resource ) {
93107
$user = User_Collection::get_by_resource( $resource );
94108

95-
if ( is_wp_error( $user ) ) {
109+
if ( \is_wp_error( $user ) ) {
96110
return $user;
97111
}
98112

0 commit comments

Comments
 (0)