[\w\-\.]+)', array( array( 'methods' => WP_REST_Server::READABLE, 'callback' => array( self::class, 'get' ), 'args' => self::request_parameters(), 'permission_callback' => '__return_true', ), ) ); } /** * Handle GET request * * @param WP_REST_Request $request * * @return WP_REST_Response */ public static function get( $request ) { $user_id = $request->get_param( 'user_id' ); $user = User_Collection::get_by_various( $user_id ); if ( is_wp_error( $user ) ) { return $user; } // redirect to canonical URL if it is not an ActivityPub request if ( ! is_activitypub_request() ) { header( 'Location: ' . $user->get_canonical_url(), true, 301 ); exit; } /* * Action triggerd prior to the ActivityPub profile being created and sent to the client */ \do_action( 'activitypub_outbox_pre' ); $user->set_context( Activity::CONTEXT ); $json = $user->to_array(); $response = new WP_REST_Response( $json, 200 ); $response->header( 'Content-Type', 'application/activity+json' ); return $response; } /** * The supported parameters * * @return array list of parameters */ public static function request_parameters() { $params = array(); $params['page'] = array( 'type' => 'string', ); $params['user_id'] = array( 'required' => true, 'type' => 'string', ); return $params; } }